npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@monyone/aho-corasick

v1.4.0

Published

Aho Corasick implementation written in TypeScript

Readme

aho-corasick

Simple Aho-Corasick algorhythm implementaiton for TypeScript.

Getting Started

npm i @monyone/aho-corasick

Keyword Detection

import { AhoCorasick } from '@monyone/aho-corasick';

const ahocorasick = new AhoCorasick(keywords);
const hasAnyKeyword: boolean = ahocorasick.hasKeywordInText(text);

Keyword Matching

import { AhoCorasick } from '@monyone/aho-corasick';

const ahocorasick = new AhoCorasick(keywords);
const match: { begin: number, end: number, keyword: string}[] = ahocorasick.matchInText(text);

Dynamic Addition/Deletion

import { DynamicAhoCorasick } from '@monyone/aho-corasick';

const ahocorasick = new DynamicAhoCorasick(keywords);
ahocorasick.add('test')
ahocorasick.delete('test')
const match: { begin: number, end: number, keyword: string}[] = ahocorasick.matchInText(text);

Greedy (Leftmost-Longest) Match Variant

import { AhoCorasick } from '@monyone/aho-corasick/greedy';

const ahocorasick = new AhoCorasick(keywords);
const match: { begin: number, end: number, keyword: string}[] = ahocorasick.matchInText(text);

Streaming (Leftmost-Longest)

Streaming Replace

import { AhoCorasick, Boundary } from '@monyone/aho-corasick/stream';

const ahocorasick = new AhoCorasick(['cat']);

Array.from(
  ahocorasick.replaceSync(['a cat and category'], () => 'DOG')
)
// ['a DOG and DOGegory']

Word Boundaries

import { AhoCorasick, Boundary } from '@monyone/aho-corasick/stream';

const ahocorasick = new AhoCorasick(['cat']);

Array.from(
  ahocorasick.replaceSync(['a cat and category'], () => 'DOG', Boundary.AsciiEdge())
)
// ['a DOG and category']

With Node.js Stream API

import { AhoCorasick } from '@monyone/aho-corasick/stream/node';
import { createReadStream, createWriteStream } from 'node:fs';

const ahocorasick = new AhoCorasick(['example', 'Example']);
const input = createReadStream('input.txt', { encoding: 'utf-8' });
const output = createWriteStream('output.txt', { encoding: 'utf-8' });

input.pipe(ahocorasick.replaceStream((key) => '#'.repeat(key.length))).pipe(output);

With Web Streams / fetch

import { AhoCorasick } from '@monyone/aho-corasick/stream/web';

const ahocorasick = new AhoCorasick(['example', 'Example']);
const input = (await fetch('http://example.com')).body!.pipeThrough(new TextDecoderStream());

const replaced = input.pipeThrough(ahocorasick.replaceStream((key) => '#'.repeat(key.length)));

Streaming Tokenize

import { AhoCorasick } from '@monyone/aho-corasick/stream';

const ahocorasick = new AhoCorasick(['cat', 'dog']);

const tokens = Array.from(ahocorasick.tokenizeSync(
  ['a cat and a dog'],
  (text) => ({ type: 'text', value: text }),
  (keyword) => ({ type: 'match', keyword }),
));
// [{type:'text',value:'a '}, {type:'match',keyword:'cat'}, {type:'text',value:' and a '}, {type:'match',keyword:'dog'}]

Imperative (Push)

import { AhoCorasick } from '@monyone/aho-corasick/stream/imperative';

const handle = new AhoCorasick(['cat']).replaceSync(() => 'DOG');

const parts = [];
parts.push(...handle.write('a ca'));   // may buffer a partial match at the boundary
parts.push(...handle.write('t and category'));
parts.push(...handle.end());           // flush the tail
parts.join('');
// 'a DOG and DOGegory'
import { AhoCorasick } from '@monyone/aho-corasick/stream/imperative';

const handle = new AhoCorasick(['cat', 'dog']).tokenizeSync(
  (text) => ({ type: 'text', value: text }),
  (keyword) => ({ type: 'match', keyword }),
);

const tokens = [...handle.write('a cat and a dog'), ...handle.end()];
// [{type:'text',value:'a '}, {type:'match',keyword:'cat'}, {type:'text',value:' and a '}, {type:'match',keyword:'dog'}]

More Faster Search (Double Array)

DAT (Double Array Trie) Based Aho-Corasick implementation

Fast Search, but Build (Construction) heavy.

Normal Aho-Corasick

import { AhoCorasick } from '@monyone/aho-corasick/fast';

const ahocorasick = new AhoCorasick(keywords);
const match: { begin: number, end: number, keyword: string}[] = ahocorasick.matchInText(text);

Greedy (Leftmost-Longest) Variant

import { AhoCorasick } from '@monyone/aho-corasick/greedy/fast';

const ahocorasick = new AhoCorasick(keywords);
const match: { begin: number, end: number, keyword: string}[] = ahocorasick.matchInText(text);