@e22m4u/js-path-trie
English | Русский
A router based on a prefix tree (trie).
Installation
npm install @e22m4u/js-path-trie
To load the ES-module, you need to set "type": "module"
in the package.json
file, or use the .mjs
extension.
Example
add(pathTemplate: string, value: unknown)
adds a value to a new routematch(path: string)
returns a value by a given path
const trie = new PathTrie();
trie.add('/foo/bar', yourValue1);
trie.add('/foo/:p1/bar/:p2', yourValue2);
trie.match('/foo/bar');
trie.match('/foo/10/bar/20');
trie.match('/foo/bar/baz');
Debugging
Set the DEBUG
variable before the run command to enable log output.
DEBUG=jsPathTrie* npm run test
Testing
npm run test
License
MIT