An open API service indexing awesome lists of open source software.

https://github.com/redcmd/oniguruma-parser-cjs

CommonJS wrapper for oniguruma-parser
https://github.com/redcmd/oniguruma-parser-cjs

commonjs oniguruma

Last synced: 4 months ago
JSON representation

CommonJS wrapper for oniguruma-parser

Awesome Lists containing this project

README

          

# oniguruma-parser-cjs

CommonJS wrapper for [oniguruma-parser](https://github.com/slevithan/oniguruma-parser).

## Installation

```sh
npm install oniguruma-parser-cjs
```

## Usage

```js
// 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

```sh
# Install dependencies
pnpm install
```

### Building and Testing

```sh
# 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](https://github.com/slevithan/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](/LICENSE)