An easy-to-use implementation of the Trie data structure. This can be used for searching for words to autocomplete and also for spell-checking.
npm install --save easy-trie
Words can be added to the dictionary one at a time, or an array of words can be added at the same time.
const Trie = require("easy-trie");
const trie = new Trie();
trie.addWord("word");
const Trie = require("easy-trie");
const trie = new Trie();
trie.addWords(["hello", "world", "today", "home"]);
trie.search(""); // results = ["hello", "world", "today", "home"]
trie.search("h"); // results = ["hello", "home"]
trie.search("ho"); // results = ["home"]
trie.search("world"); // results = ["world"]
trie.search("invalid"); // results = []
Find the longest common prefix between all the words. If no common prefix exists, return an empty string.
const trie = new Trie();
trie.addWords(["hello", "he", "her"]);
trie.longestCommonPrefix(); // results = "he"