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

Base sort should still be applied if the search string is empty #100

Closed RebeccaStevens closed 4 years ago

RebeccaStevens commented 4 years ago

Relevant code or config

import matchSorter from 'match-sorter'

const list = ['hi', 'hey', 'hello', 'sup', 'yo']

const sorted = matchSorter(list, '')

What you did:

console.log(sorted);

What happened:

The list was returned unsorted.

Problem description:

As no search string was supplied, all items should have the same ranking, therefore the base sort should be applied as the tie-breaker. i.e. The list should be sorted but it's not.

Suggested solution:

If the search string is empty, apply the base sort instead of just returning the list unsorted.

Additional Note:

I stole the "Relevant code" from the Usage section of the Read Me. When I did, I noticed that it's slightly out of date now as the base sort is not be applied to the output. matchSorter(list, 'h') // ['hi', 'hey', 'hello'] should be matchSorter(list, 'h') // [ 'hello', 'hey', 'hi' ]

kentcdodds commented 4 years ago

Thanks for the issue Rebecca. I agree with you. Would you be willing to make a pull request to add this functionality (and fix the README too)?

RebeccaStevens commented 4 years ago

Made the PR :)

kentcdodds commented 4 years ago

:tada: This issue has been resolved in version 4.2.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: