kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript

Home Page:https://npm.im/match-sorter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return NO_MATCH Items in Alphabetical Order based on Keys

Triggs125 opened this issue · comments

  • match-sorter version: 6.3.1
  • node version: v10.24.1

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.

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!