low-level, primitive autocomplete using trie data structure
MIT License
A low-level, primitive autocomplete using trie data structure
This autocomplete library has the ability to insert words manually, get word suggestions based on a query, populate the data structure with a dictionary array of words, and delete undesired words.
NOTE: The library is not populated with any words by default.
const completion = createTrie();
completion.insert("hello");
completion.count(); // => 1
completion.insert("world");
completion.count(); // => 2
completion.suggest("he"); // => ['hello']
completion.insert("hellen");
completion.suggest("he"); // => ["hello", "hellen"]
completion.suggest("w"); // => ["world"]
const fs = require("fs");
const text = "/usr/share/dict/words";
const dictionary = fs.readFileSync(text).toString().trim().split("\n");
const completion = createTrie();
completion.populate(dictionary);
completion.suggest("world"); // => [ 'world', 'worlded', 'worldful', ]
completion.suggest("world"); // => ['world', 'worlded', 'worldful', ]
completion.delete("worlded");
completion.suggest("world"); // => ['world', 'worldful', ]
case-insensitive suggestions
startNode
in Trie#suggest
substring suggestions
Inspired by the "Compelete-Me" project from the Turing School of Software & Design