Command-score is a JavaScript utility designed for fuzzy string matching, providing a numerical 'matchiness' score between 0 and 1 for a given query and target string. It was developed for use in autocompletion contexts within the Superhuman email client, where the set of potential results is relatively bounded. The library's scoring algorithm prioritizes various factors, including exact matches, case sensitivity, prefix matches, and penalties for word or character jumps and transpositions within the query. Scores are primarily comparable when the query remains constant across different target strings, allowing for a secondary sort on top of matchiness. The latest version, 0.1.2, was published in June 2016, and the project has seen no significant code updates since, indicating it is no longer actively maintained. As such, it does not support modern JavaScript module systems (ESM) natively.
npm install command-scoreVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to import `command-score`, use it to calculate fuzzy match scores for a list of items against a query, filter out non-matching results, and then sort them by score (and alphabetically for ties).
Ensure your project is configured to handle CommonJS modules (e.g., using `require()` in Node.js or a bundler like Webpack/Rollup that can transpile CJS to ESM). Avoid direct `import` statements in pure ESM contexts.
While still functional for its intended purpose, consider evaluating actively maintained alternatives like `Fuse.js`, `fzy`, or `fuzzaldrin` for new projects or if long-term support is critical.
Always use the same query when sorting a list of items based on their `command-score`. Use secondary sorting criteria (like `localeCompare` for item names) to handle ties effectively, as many items can have the same match score.
Use the CommonJS `require` syntax: `const commandScore = require('command-score');`.Ensure you are using `const commandScore = require('command-score');` in CommonJS files. If in an ESM file, a bundler or Node.js's CJS-ESM interop might eventually resolve `import commandScore from 'command-score';` by wrapping the CJS export, but the officially supported method remains `require` for this package.No dependency data recorded yet.