Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regexp-ast-analysis

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-ast-analysis

A library for analysing JS RegExp

  • 0.6.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is regexp-ast-analysis?

The 'regexp-ast-analysis' npm package provides tools for analyzing and manipulating the abstract syntax tree (AST) of regular expressions. It allows developers to parse regular expressions into an AST, traverse and modify the AST, and perform various analyses on the structure of the regular expression.

What are regexp-ast-analysis's main functionalities?

Parsing Regular Expressions

This feature allows you to parse a regular expression into its corresponding AST. The code sample demonstrates how to parse the regular expression '/abc/' and output its AST structure.

const { parseRegExpLiteral } = require('regexp-ast-analysis');
const ast = parseRegExpLiteral('/abc/');
console.log(JSON.stringify(ast, null, 2));

Traversing the AST

This feature allows you to traverse the AST of a regular expression. The code sample demonstrates how to visit each character node in the AST and log its raw value.

const { parseRegExpLiteral, visitRegExpAST } = require('regexp-ast-analysis');
const ast = parseRegExpLiteral('/abc/');
visitRegExpAST(ast, {
  onCharacterEnter(node) {
    console.log('Character:', node.raw);
  }
});

Modifying the AST

This feature allows you to modify the AST of a regular expression. The code sample demonstrates how to change the character 'a' to 'x' in the AST.

const { parseRegExpLiteral, visitRegExpAST } = require('regexp-ast-analysis');
const ast = parseRegExpLiteral('/abc/');
visitRegExpAST(ast, {
  onCharacterEnter(node) {
    if (node.raw === 'a') {
      node.raw = 'x';
    }
  }
});
console.log(JSON.stringify(ast, null, 2));

Analyzing the AST

This feature allows you to perform various analyses on the AST of a regular expression. The code sample demonstrates how to analyze the AST of the regular expression '/a|b/' and output the analysis results.

const { parseRegExpLiteral, analyzeRegExpAST } = require('regexp-ast-analysis');
const ast = parseRegExpLiteral('/a|b/');
const analysis = analyzeRegExpAST(ast);
console.log(analysis);

Other packages similar to regexp-ast-analysis

Keywords

FAQs

Package last updated on 30 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc