Simple, expected, and deterministic best-match sorting of an array in JavaScript
by kentcdoddsTypeScript
Last 12 weeks · 0 commits
6 of 6 standards met
I want to be able to optionally capture the information about how each item was matched/ranked in the return result of Use case I have a combobox with items that are filtered/sorted using . We want to add the ability for a user to create a custom item in the combobox for items that do not exist. The option to create the custom item should only appear if there are no matches that are above a certain rank. Proposed API If is true, the result is a rather than Type safety can be achieved elegantly using function overloading Alternatives I could run matchSorter twice, once with set to and once with it set to . This would allow me to continue to filter the combobox, while checking to see if the result with set to returned any results. This obviously comes at the cost of filtering twice.
What: Allow callers to opt into match metadata so they can use ranking details without reimplementing the sorter. Why: For cases when you want to use matchSort but need to save/extract information about how each item was ranked after matchSort runs. How: Added a new option called and an overload for matchSorter. When is true, the return type is but when false it is still just Checklist: [x] Documentation [x] Tests [x] Ready to be merged Summary by CodeRabbit New Features Added a new function that returns matched items with ranking metadata (item, rankedValue, rank, keyIndex, keyThreshold, index). Documentation README updated with usage examples showing the new ranked-item output and improved code formatting in examples. Tests Added tests verifying the ranked-item output structure, ordering, and behavior both with and without options. Refactor Core matching now centralizes ranking so existing match results continue to work while enabling the new ranked-output function.
Review and modernize this repository’s GitHub Actions workflows to comply with the [2025 npm authentication and token management changes](https://github.blog/changelog/2025-09-29-strengthening-npm-security-important-changes-to-authentication-and-token-management/). Focus only on updating workflow steps and permissions, not environment configuration or unrelated logic. Specifically: 1. Upgrade all steps to the latest major version (currently ). 2. Upgrade all steps to the latest major version (currently ). 3. Update values to the current LTS (currently ). 4. Upgrade to the latest major version (currently ). 5. Update the input to the current major (currently ). 6. Remove all references to , as npm releases now use GitHub’s OIDC authentication for provenance. 7. Add explicit permissions to the semantic-release job: Do not modify other permissions, secrets, job logic, or environment blocks unrelated to these security and release changes.
Repository: kentcdodds/match-sorter. Description: Simple, expected, and deterministic best-match sorting of an array in JavaScript Stars: 4103, Forks: 143. Primary language: TypeScript. Languages: TypeScript (99.7%), JavaScript (0.3%). License: MIT. Homepage: https://npm.im/match-sorter Latest release: v8.3.0 (4mo ago). Open PRs: 0, open issues: 5. Last activity: 3mo ago. Community health: 85%. Top contributors: allcontributors[bot], kentcdodds, MichaelDeBoey, ChrisRu, bernharduw, conorhastings, nfdjps, Raghuboi, RebeccaStevens, sdbrannum and others.