Skip to content

jolancornevin/StringLooker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

A small helper to do a quick (memoized) fuzzy search in a list of strings.

You can choose amongh multiples algorithms, like:

  • strict matching, will only returns strings that strictly match your query
  • start with, will return strings that start with your query, order by size
  • an updated jaro-winkler score: that prioritize strings that start with your query, and then use the jaro-winkler algorithm
  • fuzzysort.

100% tested and coverage with jasmine

Description

Options

  • list: the list of strings to look into
  • options:
    • threshold: the threshold to filter not good enough strings. Default: Infinity
    • algorithm: the algorithm to use for the lookup. Default: SIMI Choices: FUZZY, SIMI, STRICT_MATCH, START_WITH
      • use import {ALGORITHM} from 'fuzmoisearch' to access them.

Methods:

  • search(query = ''): Does the actuall search in the list ✅
  • add(target): element to list of items ✅
  • remove(target): element to list of items ✅
  • reset: reset the cache ✅

Example

let list = ['anakin', 'luc', 'leila', 'vader', 'yoda'],
    looker = new StringLooker(list, {algorithm: ALGORITHM.FUZZY});
    
looker.search();                      // => []
looker.search('l');                   // => ['luc', 'leila']

looker.add('kylo')

looker.search('l');                   // => ['luc', 'leila', 'kylo'] and no search actually done !

// Using a custom algoritm
looker = new StringLooker(
  ['123', '12', '123456'], {
    comparator: (target, query) => {
      return target.length;
    }
  })

looker.search('12')                   // => ['123456', '123', '12']

About

A minimal memoized fuzzy search javascript library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors