fuzzysort-collection
v1.0.0
Published
Fast SublimeText-like fuzzy search for collections
Downloads
9
Maintainers
Readme
fuzzysort-collection
Fast SublimeText-like fuzzy search for collections
Thanks to @farzher for fuzzysort
Installation
$ npm install --save fuzzysort-collection
Usage
const fuzz = require('fuzzysort-collection');
// You can config fuzzysort options:
// https://github.com/farzher/fuzzysort#options
fuzz.fuzzysort.highlightOpen = '<strong>';
fuzz.fuzzysort.highlightClose = '</strong>';
const crop = [{
a: {
b: 'Snap'
}
}, {
a: {
b: 'Paypal'
}
}, {
a: {
b: 'Google'
}
}, {
a: {
b: 'Apple'
}
}];
let cream = fuzz('ap', crop, 'a.b');
/*
[
{
"meta": {
"matches": [
0,
1
],
"target": "Apple",
"lower": "apple",
"score": 3,
"theMatches": [
0,
1
],
"highlighted": "<strong>Ap</strong>ple"
},
"data": {
"a": {
"b": "Apple"
}
}
},
{
"meta": {
"matches": [
2,
3
],
"target": "Snap",
"lower": "snap",
"score": 2002,
"theMatches": [
2,
3
],
"highlighted": "Sn<strong>ap</strong>"
},
"data": {
"a": {
"b": "Snap"
}
}
},
{
"meta": {
"matches": [
1,
3
],
"target": "Paypal",
"lower": "paypal",
"score": 4004,
"theMatches": [
1,
3
],
"highlighted": "P<strong>a</strong>y<strong>p</strong>al"
},
"data": {
"a": {
"b": "Paypal"
}
}
}
]
*/
License
ISC © Buster Collings