oniguruma-parser-cjs

May 4, 2025 ยท View on GitHub

CommonJS wrapper for oniguruma-parser.

Installation

npm install oniguruma-parser-cjs

Usage

// CommonJS
const { toOnigurumaAst } = require('oniguruma-parser-cjs');
const ast = toOnigurumaAst('A.*');
console.log(ast);

// Optimizer
const { optimize } = require('oniguruma-parser-cjs/optimizer');
const optimized = optimize('[aa]', {
	rules: {
		// `vscode-oniguruma` enables this Oniguruma option by default
		captureGroup: true,
		allowOrphanBackrefs: true,
	},
}).pattern;
console.log(optimized); // a

Development

Setup

# Install dependencies
pnpm install

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 oniguruma-parser 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