string-case-match
String matching class. Given a set of strings to match, it will search it by different input.
It is able to search strings as abbreviations (e.g. HelloWorld
matches hw
, hewo
, h w
, ...). Works in node.js and all modern browsers without any dependencies. This script is intended to use as ranking function for autocompletes, searches for short strings, etc.
See the live demo page to play with it.
Installation
With node.js
npm install string-
var StringCaseMatch = ;console;
In browser with require.js
Without require.js:
Usage
You can find actual examples in the spec file but here's a quick example:
// init a matcher instance with strings to searchvar matcher = "HelloWorld" "Hello" "Bye";// get matches against "hell" word (matches will be sorted by rank in descending order)var matches = matcher; // ["Hello", "HelloWorld"] var matches = matcher; // top 1 match // to highlight found characters, use this:var matcher = "HelloWorld" start: "<i>" end: "</i>" ;var matches = matcher; // matches will look like "<i>Hell</i>oWorld" // just get a string rank, don't search anything// rank is [0..1], 0 - no match, 1 - complete matchvar rank = ;
License
string-case-match
is redistributed under MIT license. So, you can use it in any projects without attribution.