{"_id":"fast-string-compare","_rev":"3290769","name":"fast-string-compare","description":"A (much) faster String.prototype.localeCompare","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"grantila","email":""}],"time":{"modified":"2024-05-23T06:50:44.000Z","created":"2021-04-09T23:21:51.284Z","3.0.0":"2023-02-02T20:44:46.061Z","2.0.0":"2021-09-13T06:41:10.869Z","1.0.0":"2021-04-09T23:21:51.284Z"},"users":{},"author":{"name":"Gustaf Räntilä"},"repository":{"type":"git","url":"git+https://github.com/grantila/fast-string-compare.git"},"versions":{"3.0.0":{"name":"fast-string-compare","version":"3.0.0","description":"A (much) faster String.prototype.localeCompare","author":{"name":"Gustaf Räntilä"},"license":"MIT","bugs":{"url":"https://github.com/grantila/fast-string-compare/issues"},"homepage":"https://github.com/grantila/fast-string-compare#readme","main":"./dist/index.js","exports":"./dist/index.js","types":"./dist/index.d.ts","type":"module","sideEffects":false,"engines":{"node":"^14.13.1 || >=16.0.0"},"scripts":{"build":"rimraf dist && tsc -p tsconfig.prod.json","test":"NODE_OPTIONS=--experimental-vm-modules jest --coverage","benchmark":"ts-node benchmark","cz":"git-cz"},"repository":{"type":"git","url":"git+https://github.com/grantila/fast-string-compare.git"},"keywords":["fast","string","compare"],"devDependencies":{"@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.18.6","@types/benchmark":"^2.1.2","@types/bintrees":"^1.0.3","@types/jest":"^29.4.0","@types/node":"^18.11.18","benchmark":"^2.1.4","bintrees":"^1.0.2","cz-conventional-changelog":"^3.3.0","jest":"^29.4.1","rimraf":"^4.1.2","ts-node":"^10.9.1","typescript":"^4.9.5"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"jest":{"testEnvironment":"node","collectCoverageFrom":["<rootDir>/lib/**"],"coverageReporters":["lcov","text","html"],"extensionsToTreatAsEsm":[".ts"]},"packageManager":"yarn@3.2.4","gitHead":"9e8cc266284db2240df3d8186a7224aa514e9ab7","_id":"fast-string-compare@3.0.0","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"shasum":"524dc0c02b485ec5b97092f09230d42926325639","size":3974,"noattachment":false,"key":"/fast-string-compare/-/fast-string-compare-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/fast-string-compare/download/fast-string-compare-3.0.0.tgz"},"_npmUser":{"name":"grantila","email":"g.rantila@gmail.com"},"directories":{},"maintainers":[{"name":"grantila","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fast-string-compare_3.0.0_1675370685937_0.7948573950205122"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-02-02T20:44:46.061Z","publish_time":1675370686061,"_cnpm_publish_time":1675370686061},"2.0.0":{"name":"fast-string-compare","version":"2.0.0","description":"A (much) faster String.prototype.localeCompare","author":{"name":"Gustaf Räntilä"},"license":"MIT","bugs":{"url":"https://github.com/grantila/fast-string-compare/issues"},"homepage":"https://github.com/grantila/fast-string-compare#readme","main":"./dist/index.js","exports":"./dist/index.js","types":"./dist/index.d.ts","type":"module","sideEffects":false,"engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"build":"rimraf dist && tsc -p tsconfig.prod.json","test":"NODE_OPTIONS=--experimental-vm-modules jest --coverage","benchmark":"ts-node benchmark","cz":"git-cz"},"repository":{"type":"git","url":"git+https://github.com/grantila/fast-string-compare.git"},"keywords":["fast","string","compare"],"devDependencies":{"@babel/preset-env":"^7.15.6","@babel/preset-typescript":"^7.15.0","@types/benchmark":"^2.1.1","@types/bintrees":"^1.0.3","@types/jest":"^27.0.1","@types/node":"^16.9.1","benchmark":"^2.1.4","bintrees":"^1.0.2","cz-conventional-changelog":"^3.1.0","jest":"^27.1.1","rimraf":"^3.0.1","ts-node":"^10.2.1","typescript":"^4.4.3"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"jest":{"testEnvironment":"node","collectCoverageFrom":["<rootDir>/lib/**"],"coverageReporters":["lcov","text","html"],"extensionsToTreatAsEsm":[".ts"]},"gitHead":"b664ef7adb010f9ed97485801f5d39bb5ad778ba","_id":"fast-string-compare@2.0.0","_nodeVersion":"14.17.6","_npmVersion":"6.14.15","dist":{"shasum":"c69460852479feb170dd955add8ec0ca9c715cc6","size":4061,"noattachment":false,"key":"/fast-string-compare/-/fast-string-compare-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/fast-string-compare/download/fast-string-compare-2.0.0.tgz"},"_npmUser":{"name":"grantila","email":"g.rantila@gmail.com"},"directories":{},"maintainers":[{"name":"grantila","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fast-string-compare_2.0.0_1631515270685_0.7567707469646938"},"_hasShrinkwrap":false,"publish_time":1631515270869,"_cnpm_publish_time":1631515270869,"_cnpmcore_publish_time":"2021-12-17T00:21:40.628Z"},"1.0.0":{"name":"fast-string-compare","version":"1.0.0","description":"A (much) faster String.prototype.localeCompare","author":{"name":"Gustaf Räntilä"},"license":"MIT","bugs":{"url":"https://github.com/grantila/fast-string-compare/issues"},"homepage":"https://github.com/grantila/fast-string-compare#readme","main":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=10"},"scripts":{"build":"rimraf dist && tsc -p tsconfig.prod.json","test":"jest --coverage","benchmark":"ts-node benchmark","cz":"git-cz"},"repository":{"type":"git","url":"git+https://github.com/grantila/fast-string-compare.git"},"keywords":["fast","string","compare"],"devDependencies":{"@types/benchmark":"^2.1.0","@types/bintrees":"^1.0.3","@types/jest":"^26.0.22","@types/node":"^14.14.37","cz-conventional-changelog":"^3.1.0","benchmark":"^2.1.4","bintrees":"^1.0.2","jest":"^26.6.3","rimraf":"^3.0.1","ts-jest":"^26.5.4","ts-node":"^9.1.1","typescript":"^4.2.4"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"jest":{"preset":"ts-jest","testEnvironment":"node","collectCoverageFrom":["<rootDir>/lib/**"],"coverageReporters":["lcov","text","html"]},"gitHead":"5c1aa39f955d27a1cf2e5f9e4c337e552aa862e8","_id":"fast-string-compare@1.0.0","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"shasum":"2bbb7efb6e9bf728aff7c46f92abc75acb4b237d","size":3908,"noattachment":false,"key":"/fast-string-compare/-/fast-string-compare-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/fast-string-compare/download/fast-string-compare-1.0.0.tgz"},"_npmUser":{"name":"grantila","email":"g.rantila@gmail.com"},"directories":{},"maintainers":[{"name":"grantila","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fast-string-compare_1.0.0_1618010511143_0.8713383879783683"},"_hasShrinkwrap":false,"publish_time":1618010511284,"_cnpm_publish_time":1618010511284,"_cnpmcore_publish_time":"2021-12-17T00:21:40.947Z"}},"readme":"[![npm version][npm-image]][npm-url]\n[![downloads][downloads-image]][npm-url]\n[![build status][build-image]][build-url]\n[![coverage status][coverage-image]][coverage-url]\n[![Node.JS version][node-version]][node-url]\n\n\n# fast-string-compare\n\nThis is a (much) faster version of [String.prototype.localeCompare()][mdn-localecompare] to compare two strings, useful for [Array.prototype.sort()][mdn-sort] or for ordering strings in trees.\n\nThis is **not equivalent** to `localeCompare`, and does **not** return the same result. `localeCompare` respects the current *locale* (language), and orders e.g. both 'a' and 'A' before 'b'. See [Intl.Collator][mdn-collator].\n\nThe function exported by this package - `compare` - returns a pure **binary comparison**, and is therefore just as stable and useful if *some* deterministic order is needed, but not necessarily a *human friendly* order.\n\n# Versions\n\n * Since v2 this is a [pure ESM][pure-esm] package, and requires Node.js >=12.20. It cannot be used from CommonJS.\n * Since v3 requires Node.js >= 14.13.1.\n\n# API\n\n```ts\nimport { compare } from 'fast-string-compare'\n\n[ 'c', 'a', 'B' ].sort( compare ); // 'B', 'a', 'c'\n```\n\n\n# Benchmark\n\nRunning this under a system heavily slowing down user code (e.g. Jest, with or without coverage), it will run much slower than `localeCompare()`. This is misleading, and not the case when not running in a test environment.\n\nLook at the benchmark code and run it using `yarn benchmark`.\n\nIn these benchmarks, the fast compare is ~2-3x faster than `localeCompare`, but a large part of the benchmark is logic *around* the actual comparison, so the difference is likely larger for the pure comparison.\n\n<details style=\"padding-left: 32px; border-left: 4px solid gray;\">\n<summary>Benchmark results (the exported compare function is the 'fast' method):</summary>\n<p>\n\n```\n❯ yarn -s benchmark\nBenchmarking raw comparison algorithms...\n\nRunning test of: raw compare\nfast           x 12,190,097 ops/sec ±0.50% (91 runs sampled)\nfast double    x 11,263,299 ops/sec ±0.44% (91 runs sampled)\nfast and slice x 7,343,412 ops/sec ±0.62% (91 runs sampled)\nfast codepoint x 11,552,827 ops/sec ±0.67% (87 runs sampled)\nIntl.Collator  x 6,341,841 ops/sec ±1.12% (86 runs sampled)\nlocaleCompare  x 5,599,850 ops/sec ±1.01% (90 runs sampled)\n\nBenchmarking comparison algorithms for sort...\n\nRunning test of: english words\nfast           x 2.15 ops/sec ±3.61% (10 runs sampled)\nfast double    x 2.04 ops/sec ±5.87% (10 runs sampled)\nfast and slice x 1.36 ops/sec ±2.53% (8 runs sampled)\nfast codepoint x 1.74 ops/sec ±2.18% (9 runs sampled)\nIntl.Collator  x 0.87 ops/sec ±0.82% (7 runs sampled)\nlocaleCompare  x 0.78 ops/sec ±4.24% (6 runs sampled)\n\nRunning test of: english words reversed\nfast           x 2.12 ops/sec ±5.38% (10 runs sampled)\nfast double    x 2.11 ops/sec ±1.76% (10 runs sampled)\nfast and slice x 1.39 ops/sec ±3.90% (8 runs sampled)\nfast codepoint x 1.79 ops/sec ±1.79% (9 runs sampled)\nIntl.Collator  x 0.89 ops/sec ±0.28% (7 runs sampled)\nlocaleCompare  x 0.79 ops/sec ±3.82% (7 runs sampled)\n\nRunning test of: english words randomized\nfast           x 2.12 ops/sec ±7.95% (10 runs sampled)\nfast double    x 2.13 ops/sec ±1.59% (10 runs sampled)\nfast and slice x 1.42 ops/sec ±0.55% (8 runs sampled)\nfast codepoint x 1.81 ops/sec ±0.53% (9 runs sampled)\nIntl.Collator  x 0.88 ops/sec ±3.13% (7 runs sampled)\nlocaleCompare  x 0.80 ops/sec ±2.20% (7 runs sampled)\n\nRunning test of: data type words\nfast           x 10,857 ops/sec ±0.74% (92 runs sampled)\nfast double    x 9,770 ops/sec ±0.76% (93 runs sampled)\nfast and slice x 6,135 ops/sec ±0.44% (94 runs sampled)\nfast codepoint x 8,212 ops/sec ±0.89% (93 runs sampled)\nIntl.Collator  x 3,778 ops/sec ±0.47% (94 runs sampled)\nlocaleCompare  x 3,434 ops/sec ±0.87% (92 runs sampled)\n\nRunning test of: data type words reversed\nfast           x 10,731 ops/sec ±1.09% (94 runs sampled)\nfast double    x 9,643 ops/sec ±0.72% (92 runs sampled)\nfast and slice x 6,109 ops/sec ±0.46% (92 runs sampled)\nfast codepoint x 8,158 ops/sec ±1.34% (93 runs sampled)\nIntl.Collator  x 3,800 ops/sec ±0.47% (93 runs sampled)\nlocaleCompare  x 3,438 ops/sec ±0.41% (92 runs sampled)\n\nRunning test of: data type words randomized\nfast           x 10,776 ops/sec ±1.26% (92 runs sampled)\nfast double    x 9,789 ops/sec ±0.38% (93 runs sampled)\nfast and slice x 6,177 ops/sec ±0.32% (96 runs sampled)\nfast codepoint x 8,202 ops/sec ±1.04% (93 runs sampled)\nIntl.Collator  x 3,786 ops/sec ±0.39% (93 runs sampled)\nlocaleCompare  x 3,431 ops/sec ±0.50% (94 runs sampled)\n\nBenchmarking comparison algorithms for trees...\n\nRunning test of: english words\nfast           x 0.40 ops/sec ±2.35% (5 runs sampled)\nfast double    x 0.36 ops/sec ±1.33% (5 runs sampled)\nfast and slice x 0.28 ops/sec ±1.56% (5 runs sampled)\nfast codepoint x 0.32 ops/sec ±2.45% (5 runs sampled)\nIntl.Collator  x 0.24 ops/sec ±4.09% (5 runs sampled)\nlocaleCompare  x 0.22 ops/sec ±0.87% (5 runs sampled)\n\nRunning test of: english words reversed\nfast           x 0.38 ops/sec ±1.87% (5 runs sampled)\nfast double    x 0.36 ops/sec ±2.17% (5 runs sampled)\nfast and slice x 0.28 ops/sec ±5.81% (5 runs sampled)\nfast codepoint x 0.32 ops/sec ±1.70% (5 runs sampled)\nIntl.Collator  x 0.24 ops/sec ±0.98% (5 runs sampled)\nlocaleCompare  x 0.22 ops/sec ±0.86% (5 runs sampled)\n\nRunning test of: english words randomized\nfast           x 0.38 ops/sec ±1.03% (5 runs sampled)\nfast double    x 0.36 ops/sec ±1.42% (5 runs sampled)\nfast and slice x 0.28 ops/sec ±1.35% (5 runs sampled)\nfast codepoint x 0.33 ops/sec ±4.34% (5 runs sampled)\nIntl.Collator  x 0.24 ops/sec ±0.79% (5 runs sampled)\nlocaleCompare  x 0.22 ops/sec ±1.07% (5 runs sampled)\n\nRunning test of: data type words\nfast           x 2,688 ops/sec ±0.69% (91 runs sampled)\nfast double    x 2,386 ops/sec ±0.77% (95 runs sampled)\nfast and slice x 1,653 ops/sec ±0.44% (95 runs sampled)\nfast codepoint x 1,898 ops/sec ±0.52% (93 runs sampled)\nIntl.Collator  x 1,259 ops/sec ±0.38% (93 runs sampled)\nlocaleCompare  x 1,143 ops/sec ±0.48% (94 runs sampled)\n\nRunning test of: data type words reversed\nfast           x 2,728 ops/sec ±0.84% (92 runs sampled)\nfast double    x 2,389 ops/sec ±0.45% (94 runs sampled)\nfast and slice x 1,654 ops/sec ±0.38% (94 runs sampled)\nfast codepoint x 1,913 ops/sec ±0.34% (95 runs sampled)\nIntl.Collator  x 1,272 ops/sec ±0.39% (94 runs sampled)\nlocaleCompare  x 1,143 ops/sec ±0.54% (93 runs sampled)\n\nRunning test of: data type words randomized\nfast           x 2,723 ops/sec ±0.73% (94 runs sampled)\nfast double    x 2,399 ops/sec ±0.39% (95 runs sampled)\nfast and slice x 1,639 ops/sec ±0.56% (93 runs sampled)\nfast codepoint x 1,919 ops/sec ±0.44% (93 runs sampled)\nIntl.Collator  x 1,272 ops/sec ±0.38% (93 runs sampled)\nlocaleCompare  x 1,140 ops/sec ±0.89% (91 runs sampled)\n```\n\n</p>\n</details>\n\n\n[npm-image]: https://img.shields.io/npm/v/fast-string-compare.svg\n[npm-url]: https://npmjs.org/package/fast-string-compare\n[downloads-image]: https://img.shields.io/npm/dm/fast-string-compare.svg\n[build-image]: https://img.shields.io/github/actions/workflow/status/grantila/fast-string-compare/master.yml?branch=master\n[build-url]: https://github.com/grantila/fast-string-compare/actions?query=workflow%3AMaster\n[coverage-image]: https://coveralls.io/repos/github/grantila/fast-string-compare/badge.svg?branch=master\n[coverage-url]: https://coveralls.io/github/grantila/fast-string-compare?branch=master\n[node-version]: https://img.shields.io/node/v/fast-string-compare\n[node-url]: https://nodejs.org/en/\n\n[mdn-localecompare]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare\n[mdn-sort]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n[mdn-collator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator\n[pure-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n","_attachments":{},"homepage":"https://github.com/grantila/fast-string-compare#readme","bugs":{"url":"https://github.com/grantila/fast-string-compare/issues"},"license":"MIT"}