
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
A tiny TypeScript trie implementation with limited wildcards support.
yarn add basic-trie
import Trie from 'basic-trie';
// Create a new trie.
const trie = new Trie<number, string>();
trie.get([1, 2, 3]);
// undefined
// Set a value.
trie.set([1, 2, 3], '123');
trie.get([1, 2, 3]);
// '123'
trie.get([1, 2]);
// null
// NOTE:
// Returns null instead of undefined as trie starts with
// [1, 2], but there's no value associated with [1, 2].
trie.get([1, 2, 3, 4]);
// undefined
trie.get([1]);
// null
trie.get([2, 1]);
// undefined
Wildcards are supported by overriding a few methods of Trie
class, example:
import Trie, { PayloadType } from 'basic-trie';
class MyTrie extends Trie<string, string> {
isKeyWildcard(key: string): boolean {
return key.startsWith(':');
}
getWildcardPayload(
key: string,
wildcardName: string,
_wildcardValue: string | null,
): PayloadType | undefined {
return {
[wildcardName.substr(1)]: key,
};
}
}
// Helper funcs to demonstrate uses of wildcards.
function splitPathString(s: string): string[] {
return s.split('/');
}
function addMyPath(trie: MyTrie, s: string) {
trie.set(splitPathString(s), s);
}
const trie = new MyTrie();
addMyPath(trie, ':a');
addMyPath(trie, ':b');
addMyPath(trie, ':c/:sub1');
addMyPath(trie, 'imp/:sub2');
trie.getWithPayload(['a']);
// ['a'] matches wildcard ':a'
// Prints [':a', { a: 'a' }]
trie.getWithPayload(['a', 'b', 'c']);
// No match
// Prints [undefined, undefined]
trie.getWithPayload(['a', 'b']);
// ['a', 'b'] matches two consecutive wildcards ':c/:sub1'.
// Prints [':c/:sub1', { c: 'a', sub1: 'b' }]
trie.getWithPayload(['imp', 'b']);
// ['imp', 'b'] actually matches both ':c/:sub1' and 'imp/:sub2',
// but 'imp/:sub2' takes precedence as 'imp' is not a wildcard.
// Prints ['imp/:sub2', { sub2: 'b' }]
FAQs
A tiny TypeScript trie implementation
The npm package basic-trie receives a total of 1 weekly downloads. As such, basic-trie popularity was classified as not popular.
We found that basic-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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.