prefix-search
Prefix search finds the item in a list that has the longest matching prefix.
Using simple prefix searches will return the shortest matching string, or object based on the criterion.
const psearch = require('prefix-search')var searchTerm = 'awe'var docs = [{name: 'awesome'}, {name: 'awe! Kittens'}]var res = psearch.objects(searchTerm, 'name', 'name', docs)// res = {name, 'awesome'}; this string matched the most
ps.search
returns the index of the best matching word. ps.words
returns the string best matching the prefix, though -1
is still returned when there is no match.
var words = 'aabb' 'abba'var index = psearchconsole // returns index 0index = psearch console // returns -1, "no match"
(WIP) Using the complex prefix search finds the item with the best matching critia within complex strings.
var res = psearch// res = {name: 'awe! Kittens'}; the string 'awe' is an exact match