fuzzbunny é uma biblioteca de pesquisa/correspondência/destaque/destaque para pequenas (1k), rápida e eficiente e eficiente em memória. Funciona igualmente bem em um ambiente de navegador ou node.js.
Outras bibliotecas semelhantes são difusas, confusas, pesquisas difusas, fuzzyJs.
fuzzbunny pretende ser ágil e rápido. Possui uma API simples que pode ser facilmente integrada a qualquer biblioteca de front -end para criar uma ótima interface do usuário de pesquisa. Nós o usamos em mixpanel.com para alimentar nossos suspensos e tabelas de interface do usuário.
npm install --save fuzzbunny ou yarn add fuzzbunny
Fuzzbunny Gutenberg Catalog Demo →

const { fuzzyFilter , fuzzyMatch } = require ( `fuzzbunny` ) ;
// or import {fuzzyFilter, fuzzyMatch} from 'fuzzbunny';
const heroes = [
{
name : `Claire Bennet` ,
ability : `Rapid cellular regeneration` ,
} ,
{
name : `Micah Sanders` ,
ability : `Technopathy` ,
} ,
{
name : `Hiro Nakamura` ,
ability : `Space-time manipulation` ,
} ,
{
name : `Peter Petrelli` ,
ability : `Tactile power mimicry` ,
} ,
] ;
// Use fuzzyFilter to filter an array of items on specific fields and get filtered + score-sorted results with highlights.
const results = fuzzyFilter ( heroes , `stm` , { fields : [ `name` , `ability` ] } ) ;
/*
results = [
{
item: {
name: 'Peter Petrelli',
ability: 'Tactile power mimicry',
},
score: 1786,
highlights: {
ability: ['', 'T', 'actile power ', 'm', 'imicry'],
},
},
{
item: {
name: 'Hiro Nakamura',
ability: 'Space-time manipulation',
},
score: 983,
highlights: {
ability: ['Space-', 't', 'ime ', 'm', 'anipulation'],
},
},
];
*/
// Use fuzzyMatch to match a single string to get score + highlights. Returns null if no match found.
const match = fuzzyMatch ( heroes [ 0 ] . name , `ben` ) ;
/*
match = {
score: 2893,
highlights: ['Claire ', 'Ben', 'net'],
};
*/ fuzzbunny usa um algoritmo de pontuação que prioriza os seguintes sinais. Consulte _getMatchScore Função.
Exemplo 1:
{Mayfl}ower classifica acima The {Mayfl}owerThe {Mayfl}ower classifica acima da Story of the {Mayfl}owerThe {Mayfl}ower classifica acima {May} {fl}owerThe {May} {fl}ower classifica acima This {May} {fl}ower 
Exemplo 2:
const f = require ( `fuzzbunny` ) ;
f . fuzzyMatch ( `Gobbling pupusas` , `usa` ) ;
// {score: 2700, highlights: ['Gobbling pup', 'usa', 's']}
f . fuzzyMatch ( `United Sheets of Antarctica` , `usa` ) ;
// {score: 2276, highlights: ['', 'U', 'nited ', 'S', 'heets of ', 'A', 'ntarctica']} Gobbling pup{usa}s vence porque a sequência contígua de 3 letras produz uma pontuação mais alta.
Nota : fuzzbunny optmiza para obter resultados significativos. Ele só faz correspondência de substring/prefixo/sigla, não correspondente gananciosa.
Isso ocorre porque os cérebros humanos são ótimos no recall prefixo. Por exemplo, as palavras que começam com "CA" são muito mais fáceis de lembrar do que as palavras que contêm as letras "C" e "A" em algum lugar. É fácil lembrar que {usa} significa {U}nited {S}tates of {A}merica , não F{u}ll Java{s}cript Fr{a}mework
fuzzbunny corresponde a ~ milhões de linhas/segundo em hardware moderno. Testado no MacBook Pro 2018 com CPU de 2,4 GHz. Consulte testes/performance.js
fuzzbunny vem com tipos de texto de texto autogenerados. Veja Index.D.Ts