fuzzy-array-filter
A simple fuzzy filter function for array.prototype.filter
using fuse.js.
How to use it
Simple
ìmport fuzzyFilter from 'fuzzy-array-filter';
const array = ['There is a house in New Orleans',
'They call the Rising Sun',
'And \'s been the ruin of many a poor boy',
'And God, I know I\'m one',
'My mother was a tailor',
'She sewed my new blue jeans',
'My father was a gamblin man',
'Down in New Orleans',
'Now the only thing a gambler needs',
'Is a suitcase and trunk',
'And the only time he\'s satisfied',
'Is when he\'s on a drunk',
'Oh mother, tell your children',
'Not to do what I have done',
'Spend your lives in sin and misery',
'In the House of the Rising Sun' ];
console.log(array.filter(fuzzySearch('new orleans')));
Default fuzzy options are
{
"threshold": 0.4,
"location": 0,
"distance": 100,
"maxPatternLength": 32,
"keys": []
}
With custom options
ìmport fuzzyFilter from 'fuzzy-array-filter';
const array = theRisingSunArray;
const options = {
caseSensitive: true,
};
console.log(array.filter(fuzzySearch('new orleans', options)));
console.log(array.filter(fuzzySearch('man', options)));
For more details, please see the fuse.js options documentation
Dependencies
ToDo
- It must filter more complex arrays