Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RebeccaStevens opened this issue Sep 13, 2020 · 3 comments · Fixed by #101
Closed

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

RebeccaStevens opened this issue Sep 13, 2020 · 3 comments · Fixed by #101
Labels

Comments

@RebeccaStevens
Copy link
Contributor

  • match-sorter version: 4.2.0
  • node version: 14.8.0
  • npm (or yarn) version: 6.14.7 (or 1.21.1 😛)

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
Copy link
Owner

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 pushed a commit to RebeccaStevens/match-sorter that referenced this issue Sep 14, 2020
@RebeccaStevens
Copy link
Contributor Author

Made the PR :)

kentcdodds pushed a commit that referenced this issue Sep 14, 2020
* fix: still sort when search value is absent

fix #100

* docs: add RebeccaStevens as a contributor
kentcdodds added a commit that referenced this issue Sep 14, 2020
* fix: still sort when search value is absent

fix #100

* docs: add RebeccaStevens as a contributor

* docs: adjust example in the readme to apply the base sort

* docs: add doc contribution to RebeccaStevens

Co-authored-by: Kent C. Dodds <[email protected]>
@kentcdodds
Copy link
Owner

🎉 This issue has been resolved in version 4.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants