Skip to content

Upgrading from v1 ​

v2 is a rewrite: fewer functions, flat options, stable return types and a smarter default score.

Functions ​

v1v2
rate(a, b), getSimilarityScore(a, b)similarity(a, b)
rate(a, b, { explain: true })compare(a, b)
isMatch(a, b, 85)unchanged
findBestMatch(q, list)closest(q, list), returns undefined below the threshold
rankCandidates(q, list)search(q, list, { threshold: 0 })
filterMatches(q, list)search(q, list).map((m) => m.item)
extract(q, list, { limit })search(q, list, { limit }).map((m) => m.item)
createMatcher(options)unchanged, with more methods
normalize, normalizeStringnormalize
getLevenshteinDistancelevenshtein
getJaroWinklerScore(a, b)jaroWinkler(a, b) * 100

List results are now { item, score, index, text } (value became item).

Options ​

Options are flat: the normalize: { ... } block is gone.

v1v2
algorithm: 'hybrid'default smart
spaceInsensitive: truedefault (ignoreSpaces: true)
normalize.sortTokens: truedefault (ignoreWordOrder: true)
normalize.caseSensitivecaseSensitive
normalize.removeAccents: falseaccentSensitive: true
normalize.removePunctuation: falsepunctuation: 'keep'
normalize.punctuationStrategypunctuation: 'space' | 'remove'
normalize.replacementsreplace (whole words only)
normalize.removeWordsignoreWords
return: 'entries', explain on listsalways entries; use compare() to explain

Scores ​

smart tolerates swapped letters, word order and missing spaces, so similar texts generally score higher than with v1's levenshtein. Re-check thresholds on a few real examples with compare().

Behavior fixes ​

  • replace used to replace inside words (st → saint turned stairs into saintairs). It now replaces whole words only.
  • Two texts made only of punctuation used to score 100. An empty guess is now always wrong in check().
  • Non-string inputs (null, undefined, numbers) no longer throw: they are read as text.