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

regexp-tree

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-tree

Regular Expressions parser in JavaScript

  • 0.1.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5M
increased by2.94%
Maintainers
1
Weekly downloads
 
Created

What is regexp-tree?

The regexp-tree npm package is a toolkit for working with regular expressions in JavaScript. It provides functionalities for parsing, transforming, and optimizing regular expressions, making it easier to manipulate and understand complex regex patterns.

What are regexp-tree's main functionalities?

Parsing

This feature allows you to parse a regular expression into an Abstract Syntax Tree (AST). The AST can then be used for further analysis or transformation.

const { parse } = require('regexp-tree');
const ast = parse('/a(b|c)*d/');
console.log(JSON.stringify(ast, null, 2));

Transforming

This feature allows you to transform a regular expression by applying custom transformations to its AST. In this example, the character 'a' is transformed to 'z'.

const { transform } = require('regexp-tree');
const transformed = transform('/a(b|c)*d/', {
  onChar(path) {
    if (path.node.value === 'a') {
      path.node.value = 'z';
    }
  }
});
console.log(transformed.getSource());

Optimizing

This feature allows you to optimize a regular expression by simplifying it. In this example, the non-capturing group '(?:b|c)' is optimized.

const { optimize } = require('regexp-tree');
const optimized = optimize('/a(?:b|c)d/');
console.log(optimized.getSource());

Other packages similar to regexp-tree

Keywords

FAQs

Package last updated on 30 Aug 2019

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