JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q30856F
  • License MIT

An easy to easy TypeScript implementation of the Trie data structure for

Package Exports

  • easy-trie
  • easy-trie/bundle.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (easy-trie) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

easy-trie

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.

Installation

npm install --save easy-trie

Usage

Add words to dictionary

Words can be added to the dictionary one at a time, or an array of words can be added at the same time.

Adding a single word

const Trie = require("easy-trie");
const trie = new Trie();
trie.addWord("word");

Adding an array of words

const Trie = require("easy-trie");
const trie = new Trie();
trie.addWords(["hello", "world", "today", "home"]);

Searching for words

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 = []

Longest common prefix

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"