
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
router-trie
Advanced tools
npm i router-trie
import { createTrie, matchTrie } from "router-trie";
const routesTrie = createTrie([
{
id: "root",
children: [
{
id: "home",
index: true,
},
],
},
]);
const matches = matchTrie(routesTrie, "/");
console.log(matches);
// [{ id: "root" }, { id: "home", index: true }]
To install dependencies:
npm i
To run the playground:
npm start
To run the tests:
npm test
Visual of the trie structure:
Given the following routing config: routes.json
We get the following trie:
graph TD;
0__{_ROOT_} --> 0_0__{_ROUTE_};
0_0__{_ROUTE_} --> 0_0_0__{_INDEX_};
0_0_0__{_INDEX_} --> 0_0_0_0__{_ROUTE_};
0_0__{_ROUTE_} --> 0_0_1__{path-index};
0_0_1__{path-index} --> 0_0_1_0__{_INDEX_};
0_0_1_0__{_INDEX_} --> 0_0_1_0_0__{_ROUTE_};
0_0__{_ROUTE_} --> 0_0_2__{not-nested};
0_0_2__{not-nested} --> 0_0_2_0__{_ROUTE_};
0_0_2__{not-nested} --> 0_0_2_1__{sub};
0_0_2_1__{sub} --> 0_0_2_1_0__{_ROUTE_};
0_0_2__{not-nested} --> 0_0_2_2__{_DYNAMIC_};
0_0_2_2__{_DYNAMIC_} --> 0_0_2_2_0__{_ROUTE_};
0_0_2_2__{_DYNAMIC_} --> 0_0_2_2_1__{_DYNAMIC_};
0_0_2_2_1__{_DYNAMIC_} --> 0_0_2_2_1_0__{_ROUTE_};
0_0__{_ROUTE_} --> 0_0_3__{optional};
0_0_3__{optional} --> 0_0_3_0__{_OPTIONAL_};
0_0_3_0__{_OPTIONAL_} --> 0_0_3_0_0__{_OPTIONAL_};
0_0_3_0_0__{_OPTIONAL_} --> 0_0_3_0_0_0__{_ROUTE_};
0_0_3_0__{_OPTIONAL_} --> 0_0_3_0_1__{sub};
0_0_3_0_1__{sub} --> 0_0_3_0_1_0__{_ROUTE_};
0_0_3__{optional} --> 0_0_3_1__{sub};
0_0_3_1__{sub} --> 0_0_3_1_0__{_OPTIONAL_};
0_0_3_1_0__{_OPTIONAL_} --> 0_0_3_1_0_0__{_ROUTE_};
0_0__{_ROUTE_} --> 0_0_4__{nested};
0_0_4__{nested} --> 0_0_4_0__{_ROUTE_};
0_0_4_0__{_ROUTE_} --> 0_0_4_0_0__{_INDEX_};
0_0_4_0_0__{_INDEX_} --> 0_0_4_0_0_0__{_ROUTE_};
0_0_4_0__{_ROUTE_} --> 0_0_4_0_1__{sub};
0_0_4_0_1__{sub} --> 0_0_4_0_1_0__{_ROUTE_};
0_0_4_0__{_ROUTE_} --> 0_0_4_0_2__{_DYNAMIC_};
0_0_4_0_2__{_DYNAMIC_} --> 0_0_4_0_2_0__{_ROUTE_};
0_0_4_0_2__{_DYNAMIC_} --> 0_0_4_0_2_1__{_DYNAMIC_};
0_0_4_0_2_1__{_DYNAMIC_} --> 0_0_4_0_2_1_0__{_ROUTE_};
0_0__{_ROUTE_} --> 0_0_5__{nested-nested};
0_0_5__{nested-nested} --> 0_0_5_0__{_ROUTE_};
0_0_5_0__{_ROUTE_} --> 0_0_5_0_0__{_INDEX_};
0_0_5_0_0__{_INDEX_} --> 0_0_5_0_0_0__{_ROUTE_};
0_0_5_0__{_ROUTE_} --> 0_0_5_0_1__{sub};
0_0_5_0_1__{sub} --> 0_0_5_0_1_0__{_ROUTE_};
0_0_5_0__{_ROUTE_} --> 0_0_5_0_2__{_DYNAMIC_};
0_0_5_0_2__{_DYNAMIC_} --> 0_0_5_0_2_0__{_ROUTE_};
0_0_5_0_2_0__{_ROUTE_} --> 0_0_5_0_2_0_0__{_DYNAMIC_};
0_0_5_0_2_0_0__{_DYNAMIC_} --> 0_0_5_0_2_0_0_0__{_ROUTE_};
0_0__{_ROUTE_} --> 0_0_6__{_CATCH_ALL_};
0_0_6__{_CATCH_ALL_} --> 0_0_6_0__{_ROUTE_};
FAQs
## Usage
The npm package router-trie receives a total of 1 weekly downloads. As such, router-trie popularity was classified as not popular.
We found that router-trie demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.