English
Aho–Corasick / exact text matching
Match a dictionary against text with grapheme precision and slice-ready ranges. Follow every transition, fallback, and suffix match.
Documentation for v3.2.0, available on npm. MIT · SonOfMagic · BrunoRB/ahocorasick
Start with a task
Pick the result you need, then keep the same matcher as your application grows.
Get independent matches with original text ranges, duplicate pattern indexes, and overlap control.
matcher.search(text)MeasureStop on the first hit, count all occurrences, or count each dictionary entry without creating match objects.
matcher.countByPattern(text)RenderTokenize non-overlapping matches and render user input as text nodes, including strings that look like HTML.
matcher.tokenize(text)StreamCarry graphemes across chunk boundaries with sessions, async iterables, previews, and backpressure.
createTokenStream(matcher)The contract to remember
Every result uses a half-open UTF-16 range, so the matched text is always text.slice(start, end). Emoji, combining marks, and CRLF stay together as graphemes.
const text = '😀 café'
const hit = new AhoCorasick(['café']).search(text)[0]
text.slice(hit.start, hit.end)
// 'café'Keep exploring