Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/monyone/aho-corasick

aho-corasick implementation for TypeScript
https://github.com/monyone/aho-corasick

Last synced: 3 months ago
JSON representation

aho-corasick implementation for TypeScript

Awesome Lists containing this project

README

        

# aho-corasick

Simple Aho-Corasick algorhythm implementaiton for TypeScript.

## Getting Started

```sh
npm i @monyone/aho-corasick
```

### Keyword Detection

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

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

### Keyword Matching

```ts
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

```ts
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);
```