https://github.com/monyone/aho-corasick
aho-corasick implementation for TypeScript
https://github.com/monyone/aho-corasick
Last synced: about 1 year ago
JSON representation
aho-corasick implementation for TypeScript
- Host: GitHub
- URL: https://github.com/monyone/aho-corasick
- Owner: monyone
- License: mit
- Created: 2024-05-31T00:07:33.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-02T06:55:01.000Z (about 2 years ago)
- Last Synced: 2025-04-12T23:08:01.652Z (about 1 year ago)
- Language: TypeScript
- Size: 58.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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);
```