javascript string score
just a tiny method for scoring matches of javascript string objects. here are some examples to demonstrate its simplicity =>
"hello world".score("e") //=>0.1090909090909091 (single letter match)
"hello world".score("h") //=>0.5363636363636364 (single letter match plus bonuses for beginning of word and beginning of phrase)
"hello world".score("hello") //=>0.6818181818181818
"hello world".score("hello world") //=> 1
// And then there is fuzziness
"hello world".score("hello wor1") //=>0 (the "1" in place of the "l" makes a mismatch)
"hello world".score("hello wor1",0.5) //=>0.5581818181818182 (fuzzy)
// considers string length
'He'.score('h') //=>0.6249999999999999 (better match becaus string length is closer)
// Acronym are given a little more weight
"Hillsdale Michigan".score("HiMi") > "Hillsdale Michigan".score("Hills")
"Hillsdale Michigan".score("HiMi") < "Hillsdale Michigan".score("Hillsd")
its super tiny (443 bytes!) and framework-agnostic and might feel just at home in a custom-built autocomplete widget.