import { matchSorter } from 'match-sorter';
// BUG, match-sorter returns [] even though `code` contains `1`
// If you change `id` to something else like e.g. `a1` it works correctly
// If you remove the 2nd key or remove `threshold` property from it it also works correctly
// If you change `code` to `1t` making `1` the first char it also works correctly
const arr = [{ id: '11', code: 't1t' }];
console.log(
matchSorter(arr, '1', {
keys: [
(obj) => obj.code,
{ key: (obj) => obj.id, threshold: matchSorter.rankings.EQUAL }
]
})
);
What you did:
Ran match-sorter with a single character(doesn't matter which one) in query-string and 2 keys: 1 with default threshold and another with rankings.EQUAL threshold.
What happened:
match-sorter returned an empty array, even though it should've matched an item from provided array
match-sorter
version: 6.3.0node
version: 14.15.5Relevant code or config
What you did:
Ran match-sorter with a single character(doesn't matter which one) in query-string and 2 keys: 1 with default threshold and another with
rankings.EQUAL
threshold.What happened:
match-sorter returned an empty array, even though it should've matched an item from provided array
Reproduction repository: https://codesandbox.io/s/sweet-bush-e496s?file=/src/index.ts
Problem description: This is a werid combination of conditions that causes this bug. I've described what changes make it work correctly
Suggested solution: Don't have one