regex-recursion-cjs
TypeScript icon, indicating that this package has built-in type declarations

6.0.2 • Public • Published

regex-recursion-cjs

CommonJS wrapper for regex-recursion.

Installation

pnpm add regex-recursion-cjs

Usage

// CommonJS
const { recursion } = require('regex-recursion-cjs');

// Use recursion to process a regex with recursive patterns
const pattern = '\\((?:(?R=2)|[^()])\\)';
const result = recursion(pattern);
console.log(result.pattern); // Processed pattern with recursion transformed

More Examples

Nested Parentheses Matching

const { recursion } = require('regex-recursion-cjs');

// Create a pattern that matches balanced parentheses
const pattern = '\\((?:(?R=10)|[^()])*\\)';
const processed = recursion(pattern);

// The processed pattern can be used with a standard RegExp
const regex = new RegExp(processed.pattern);
const text = 'foo (bar (baz) blah) end';
console.log(text.match(regex)[0]); // '(bar (baz) blah)'

Using Named Groups with Recursion

const { recursion } = require('regex-recursion-cjs');

// Use named groups with recursion
const pattern = '\\((?<content>(?:\\g<content&R=2>|[^()]*)*)\\)';
const processed = recursion(pattern);

console.log(processed.pattern); // Shows the expanded pattern

Development

Setup

# Install dependencies
pnpm install

Linting

This project uses ts-standard for linting and code formatting, which is an extension of StandardJS for TypeScript.

# Run linting
pnpm lint

# Fix linting issues automatically
pnpm lint:fix

Pre-commit hooks (using Husky and lint-staged) ensure that code is properly linted before being committed.

Building and Testing

# Clean build artifacts
pnpm clean

# Build the package
pnpm build

# Run tests
pnpm test

# Development workflow (clean, build, test)
pnpm dev

Why

The original regex-recursion package is ESM-only, which can cause compatibility issues in CommonJS projects. This package provides a pre-built CommonJS version that can be used in any Node.js environment without the need for special configuration.

License

MIT

Package Sidebar

Install

npm i regex-recursion-cjs

Weekly Downloads

9

Version

6.0.2

License

MIT

Unpacked Size

17.7 kB

Total Files

5

Last publish

Collaborators

  • ivankarpan