Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
regjsgen
Advanced tools
Package description
The regjsgen package is used to generate regular expressions from parsed structures. It is often used in conjunction with packages like regjsparser, which parses regular expression strings into a structured format that regjsgen can then turn back into regular expression strings. This can be useful for manipulating and generating regular expressions programmatically.
Generate regular expressions from parsed objects
This feature allows you to generate a regular expression string from a parsed regular expression object. The example shows how to generate a simple literal regular expression.
const regjsgen = require('regjsgen');
const parsedRegex = {
type: 'literal',
body: 'hello',
raw: 'hello'
};
const regexString = regjsgen.generate(parsedRegex);
console.log(regexString); // Output: 'hello'
regexp-tree is a toolkit for working with regular expressions. It allows you to parse, transform, optimize, and generate regular expressions. It is more feature-rich than regjsgen, providing a full AST for regular expressions and the ability to perform complex transformations and optimizations.
regexgen is a package for generating regular expressions that match a given set of strings. Unlike regjsgen, which generates regular expressions from parsed objects, regexgen takes a list of strings and outputs a regular expression that matches all of them. It is useful for creating compact regular expressions from a list of possible values.
Readme
Generate regular expressions from regjsparser’s AST.
npm i regjsgen
regjsgen.generate(ast)
This function accepts an abstract syntax tree representing a regular expression (see regjsparser), and returns the generated regular expression string.
const regjsparser = require('regjsparser');
const regjsgen = require('regjsgen');
// Generate an AST with `regjsparser`.
let ast = regjsparser.parse(regex);
// Modify AST
// …
// Generate `RegExp` string with `regjsgen`.
let regex = regjsgen.generate(ast);
Tested in Node.js 10, 12, 14, and 16.
Compatible with regjsparser v0.7.0’s AST.
FAQs
Generate regular expressions from regjsparser’s AST.
The npm package regjsgen receives a total of 6,500,366 weekly downloads. As such, regjsgen popularity was classified as popular.
We found that regjsgen demonstrated a healthy version release cadence and project activity because the last version was released less than 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
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.