A Javascript implementation of the Aho-Corasick algorithm. It has one difference in that it will return the longest possible match.
$ npm install aho-corasick.js
var AhoCorasick = require('aho-corasick.js'),
trie = new AhoCorasick.TrieNode();
['ab', 'bcr', 'caa'].forEach(function(word) { trie.add(word, { word: word }); });
AhoCorasick.add_suffix_links(trie);
AhoCorasick.search('foab', trie, function(found_word, data) {
console.log(found_word, data);
});
Coffeescript port by @hsujian https://github.com/hsujian/aho-corasick