fuzzy.js

Fuzzy.js is a fuzzy search algorithm in javascript

Website:https://github.com/Extaze/fuzzy.js

fuzzyjs

Build Status Coverage Status

fuzzyjs is a fuzzy search algorithm in javascript.

License

fuzzyjs is licensed under MIT License.

Usage

// Basic true/false test
fuzzy.test('li', 'lorem ipsum'); // true
fuzzy.test('li', 'Lorem ipsum', true); // false

// Advanced match with surrounding and score
fuzzy.match('li', 'lorem ipsum');
// { score: 0.2857, result: 'lorem ipsum' }

fuzzy.match('Li', 'Lorem ipsum', {
    caseSensitive: true,
    before: '<span>',
    after: '</span>'
});
// { score: 0.2857, result: '<span>L</span>orem <span>i</span>psum' }

// Filter an array using match (array is sorted based on score)
const arr = ['lorem ipsum', 'foo', 'the li element'];
fuzzy.filter('li', arr, { caseSensitive: true, before: '<span>', after: '</span>' });
/*
[
    'the <span>l</span><span>i</span> element',
    '<span>l</span>orem <span>i</span>psum'
]
*/