You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

regexp-ast-analysis

Package Overview
Dependencies
2
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-ast-analysis

A library for analysing JS RegExp


Version published
Maintainers
1
Created

Package description

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

Changelog

Source

0.7.1 (2023-09-13)

Fixed

  • Some bug fixes for UnicodeSet.

Readme

Source

RegExp AST analysis

Actions Status npm

This is a library providing functionalities to analyse JavaScript RegExp.

All functions operate on AST nodes produced by regexpp. Characters are parsed by refa.

Usage

Install the library using npm:

npm i regexp-ast-analysis

Import the library:

import * as RAA from "regexp-ast-analysis";

Documentation

Links to the full API documentation:

Keywords

FAQs

Package last updated on 13 Sep 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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc