Skip to content

Options ​

Every function accepts the same flat options object. All fields are optional.

ts
similarity(a, b, { preset: 'music', threshold: 85, ignoreWords: ['live'] })

Presets ​

A preset is a ready-made set of options. Anything you pass yourself wins over it.

PresetForWhat it sets
musicsong titles, artistsstrip: ['featuring', 'version', 'brackets', 'articles'], replace: { '&': 'and', '+': 'and', n: 'and' }
searchsearch boxespartial: true, acronyms: true, threshold: 70, numbers: false
strictcodes, referencesignoreWordOrder: false, ignoreSpaces: false, threshold: 90

A built-in preset does not change within a major version: what it sets in 2.x stays the same until 3.0, and a test enforces it. New behavior arrives as an option you turn on yourself.

search and acronyms

2.2.0 broke that rule: it added acronyms: true to the search preset, so nyc started to find New York City, and short queries can return more results than in 2.0 and 2.1. To get the 2.0 behavior back, pass { preset: 'search', acronyms: false }.

Matching ​

OptionDefaultEffect
threshold80Minimum score to match.
ignoreWordOrdertruejohn smith matches smith john.
ignoreSpacestruestairwaytoheaven matches stairway to heaven.
partialfalseThe shorter text may match a part of the longer one, starting at a word. A full match always scores higher.
acronymsfalse (true with the search preset)A single word may be the initials of the other text: nyc = New York City, one typo allowed from 3 letters on. Scores 90, or 80 with a typo. In lists, only the query can be the acronym.
substringfalseLike partial, and a match may also start inside a word: phone finds iPhone 15 and Smartphone, ville finds Belleville. Turns partial on. A match from the start of a word still ranks first (inside a word counts 95 %). For search-as-you-type over product names, file names, codes.
phoneticfalseTexts that sound the same match too, in English and French: beyonsay = Beyoncé, nite = night, fone = phone, kwin = Queen. A match on sound alone scores 95 at most, and words of fewer than 3 sounds are left alone.
algorithm'smart'See How it works.

Normalization ​

Before comparing, both texts are cleaned up. normalize() shows the result.

OptionDefaultEffect
caseSensitivefalseKeep A and a apart.
accentSensitivefalseKeep é and e apart. Otherwise ligatures are expanded too: œ → oe, ß → ss.
punctuation'space''space': saint-malo → saint malo. 'remove': → saintmalo. 'keep': untouched. Apostrophes are removed outright: don't → dont.
strip[]Noise to drop, see below.
replace{}Whole-word replacements: { st: 'saint', nyc: 'new york city' }. st never touches stairs.
ignoreWords[]Whole words to drop: ['inc', 'ltd', 'sarl'].
numberstrueNumbers in words (English, French) and roman numerals become digits: two → 2, vingt et un → 21, XIV → 14, first → 1st. Single letters (I, X) stay. false with the search preset, so sev still finds Seven.

strip rules ​

RuleExample
featuringGet Lucky (feat. Pharrell) → get lucky
versionHey Jude - Remastered 2015 → hey jude, Song (Live) → song
bracketsSong [Bonus] (2012) → song
articlesThe Beatles → beatles, L'Aventurier → aventurier

A rule never empties a text: (Intro) stays intro.

Thresholds ​

ThresholdFeels like
95+Same text, maybe one typo in a long one
85A typo or two, good for strict answers
80Default: forgiving but rarely wrong
70Loose, good for search

Short texts move fast: one typo in a 4-letter word already costs 25 points. Use check()'s close verdict to be kind without accepting wrong answers.