
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
npm install kbnf
const { Parser, Generator } = require('kbnf');
const parser = new Parser();
const grammar = parser.parse(`
# this is a comment
# the lhs of each rule denotes the rule's name
# the right hand side is a "|" separated list of values to be randomly returned
# numbers and letters are currently supported for generating random values
<num> = 1 | 2 | 3 | 4 | 5
<letter> = "a" | "b" | "c"
# rules can be referenced to create more complex generators
<numOrLetter> = <num> | <letter>
# values can consist of multiple terms that optionally are separated with whitespace
<nums> = <num> | <num> <nums>
<addition> = <nums>"+"<nums>
`);
const generator = new Generator(grammar);
// generator.generate will return an array for each term specified in the rule.
generator.generate('num'); // returns an array where the only element is one of 1, 2, 3, 4 or 5.
generator.generate('letter'); // array with only element being one of a, b, or c
generator.generate('numOrLetter'); // array with only element being one of 1-5 or a-c
// passing in true as the 2nd argument will stringify all the output rather than returning a nested set of arrays.
generator.generate('nums', true); // any digit length
FAQs
A context-free-grammar to define rules for generating random data
We found that kbnf 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 new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.