
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
generate-radix-tree
Advanced tools
Generates a function that uses a radix tree to match which pattern fits the input
Generates a function that uses a radix tree to match which pattern fits the input
npm install generate-radix-tree
const gentree = require('generate-radix-tree')
const match = gentree([
{match: 'hello'},
{match: 'world'},
{match: 'hello world'}
])
console.log(match('hello')) // returns {match: 'hello'} as it matches
console.log(match('hello world')) // returns {match: 'hello world'}
console.log(match('hey')) // returns null
The returned match function is code generated based in the input to make as few comparisons as possible to find the pattern that matches.
You can view the generated source code by calling toString() on the function
console.log(match.toString())
If you want to match against a dynamic pattern use a function.
This function must set fn.pointer to the end index in the string it matches.
For example
const match = gentree([
{match: ['hello', any, 'world']},
{match: 'hello world'}
])
console.log(match('hello world')) // return {match: 'hello world'}
console.log(match('hello_world')) // return {match: ['hello', any, 'world]}
// match any char in str at ptr
function any (str, ptr) {
if (str.length > ptr) {
// more chars, we match
// set any.pointer to where we matched to
any.pointer = ptr + 1
return true
}
return false
}
The static patterns always have preference to the dynamic ones
MIT
FAQs
Generates a function that uses a radix tree to match which pattern fits the input
We found that generate-radix-tree 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 and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.