kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript
https://npm.im/match-sorter
MIT License
3.73k stars 129 forks source link

Return NO_MATCH Items in Alphabetical Order based on Keys #132

Closed Triggs125 closed 9 months ago

Triggs125 commented 3 years ago

Relevant code or config

const items = [
  { key: 'bb', desc: 'bb' },
  { key: 'aa', desc: 'aa' }
]

const results = matchSorter(items, 'no matches', { keys: ['key'], threshold: matchSorter.rankings.NO_MATCH});

console.log("Results: ", results);

What was logged in the console:

Results:  [ { key: 'bb', desc: 'bb' }, { key: 'aa', desc: 'aa' } ]

What you did: I'm sorting a bunch of objects based on multiple keys with a threshold of NO_MATCH. (Basic implementation above)

What happened: The non-matching items were not sorted alphabetically based on the provided key(s).

Solution: Add functionality where the non-matching objects are sorted alphabetically based on the first key that's passed in. For the case when no keys are passed in then maybe sort on the first key in the object or if that can't be done then don't do any sorting like it currently does.

kentcdodds commented 3 years ago

Thanks for your interest in the project @Triggs125! I'm afraid I'm don't have time to maintain this project right now. If you'd like to dig a little deeper into things and make a pull request that'd be great. Good luck!