Маршрутизатор для Node.js на основе префиксного дерева
|
|
1 year ago | |
|---|---|---|
| .husky | 1 year ago | |
| src | 1 year ago | |
| .c8rc | 1 year ago | |
| .commitlintrc | 1 year ago | |
| .editorconfig | 1 year ago | |
| .gitignore | 1 year ago | |
| .mocharc.cjs | 1 year ago | |
| .prettierrc | 1 year ago | |
| LICENSE | 1 year ago | |
| README.md | 1 year ago | |
| eslint.config.js | 1 year ago | |
| package.json | 1 year ago | |
| tsconfig.json | 1 year ago |
ES-module of the path trie routing.
npm install @e22m4u/js-path-trie
add(pathTemplate: string, value: unknown)match(path: string)const trie = new PathTrie();
// add values to the trie
trie.add('/foo/bar', yourValue1);
trie.add('/foo/:p1/bar/:p2', yourValue2);
// path matching
trie.match('/foo/bar');
// {
// value: yourValue1,
// params: {}
// }
// path matching (with parameters)
trie.match('/foo/10/bar/20');
// {
// value: yourValue2,
// params: {p1: 10, p2: 20}
// }
// if not matched
trie.match('/foo/bar/baz');
// undefined
Do set environment variable DEBUG=jsPathTrie* before
start.
DEBUG=jsPathTrie* npm run test
npm run test
MIT