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

Add ability to set a threshold per key #50

Merged
merged 4 commits into from
Aug 29, 2018

Conversation

tikotzky
Copy link
Contributor

What:
Add the ability to set a threshold per key

Why:
To be able to set specific keys to only match when they meet a specified threshold

How:
By adding returning the keys threshold with each match and verifying that the the match is >= the threshold specified on its key.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

@tikotzky tikotzky mentioned this pull request Aug 29, 2018
Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Just one comment.

src/index.js Outdated
@@ -60,17 +65,21 @@ function matchSorter(items, value, options = {}) {
* @param {Array} keys - the keys to get values from the item for the ranking
* @param {String} value - the value to rank against
* @param {Object} options - options to control the ranking
* @return {{rank: Number, keyIndex: Number}} - the highest ranking
* @return {{rank: Number, keyIndex: Number, itemThreshold: Number}} - the highest ranking
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this keyThreshold instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Agree. I’ll make the change soon.

rename itemThreshold to keyThreshold
this way it’ll match a key when the keyThreshold is lower than the default threshold
@tikotzky
Copy link
Contributor Author

I update the variable name to keyThreshold

I also added another test to assert that it will match a key when the keys threshold is set lower that the default threshold

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super! Thanks!

@kentcdodds kentcdodds merged commit 22f1d73 into kentcdodds:master Aug 29, 2018
@kentcdodds
Copy link
Owner

🎉 This PR is included in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tikotzky
Copy link
Contributor Author

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants