link-trie
v1.1.0
Published
Trie data structure built to process link paths
Readme
link-trie
Trie data structure built to process link paths (npm)
Installation
npm install link-trieUsage
The trie can be initialized with a list of paths or as an empty trie.
const trie = new LinkTrie();
const trie = new LinkTrie(['/path1', '/path2']);This package provides insert, search, and isPrefix methods.
insert(path): inserts a new path into the triesearch(path): returnstrueif the given path is in the trieisPrefix(path): returnstrueif the given path is a prefix in the trie
Links are expected to be in the form /path/to/page or path/to/page and may include wildcards in the form /path/to/multiple/*.
Wildcards may only occur at the end of a path, extra segments after the wildcard are ignored.
const trie = new LinkTrie();
trie.insert('/example/*')
trie.search('/example/1') // returns true
trie.search('/example/1/2') // also returns true