Skip to content

A Node implementation of the Aho-Corasick string matching algorithm based on DoubleArray Trie.

Notifications You must be signed in to change notification settings

petetnt/aho-corasick-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aho-corasick-node

A Node implementation of the Aho-Corasick string matching algorithm based on DoubleArray Trie.

Install

npm install aho-corasick-node --save

Usage

Build

const AhoCorasick = require('aho-corasick-node');

const keywords = ['b', 'ba', 'nan', 'ab'];
const builder = AhoCorasick.builder();
keywords.forEach(k => builder.add(k));
const ac = builder.build();

Match

const text = 'banana';
const hits = ac.match(text); // ['b', 'ba', 'nan']

Export

const buf = ac.export();
console.log(buf);
// {
//   base: 'string...',
//   check: 'string...',
//   failurelink: 'string...',
//   output: 'string...',
//   codemap: 'string...',
// };

Load

const loadedAC = AhoCorasick.from(buf);
const hits = loadedAC.match(text); // ['b', 'ba', 'nan']

Licence

MIT

About

A Node implementation of the Aho-Corasick string matching algorithm based on DoubleArray Trie.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%