Oniguruma-To-ES is a JavaScript library designed to accurately translate Oniguruma regular expression patterns into equivalent native JavaScript RegExp objects. Currently at v4.3.5, the library maintains an active release cadence, frequently delivering bug fixes and feature enhancements. A key differentiator is its ability to support approximately 99.99% of Oniguruma regex features, making it a robust alternative to WASM-based Oniguruma implementations like `vscode-oniguruma`, offering a significantly smaller bundle size and often faster execution by leveraging native JavaScript regex engines. It deeply understands and compensates for the numerous syntactic and behavioral disparities between Oniguruma and JavaScript, including differences in flag support, group naming rules, and Unicode handling. The library is built upon `oniguruma-parser` and `Regex+`, ensuring battle-tested reliability from extensive use in TextMate grammars. Developers can also precompile regexes to further optimize bundle size and runtime performance, though the `EmulatedRegExp` class may still be required for advanced feature emulation.
npm install oniguruma-to-esVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting an Oniguruma pattern with 'x' flag, duplicate named capture groups, Unicode properties, and character class intersection into a native JavaScript RegExp, then tests it.
If direct AST access is needed, import and use functions from 'oniguruma-parser' directly. Otherwise, use `toRegExp` from `oniguruma-to-es` for pattern translation.
Always use `oniguruma-to-es` to translate Oniguruma patterns before using them in a JavaScript environment to ensure correct behavior and semantics.
Ensure `oniguruma-to-es` is updated to at least v4.3.3 to benefit from bug workarounds. Thoroughly test complex regexes in all target browser environments.
Update `oniguruma-to-es` to at least v4.3.1 when working with Bun, or ensure Bun itself is updated to a version greater than 1.1.34.
Precompile regexes during your build process. If `EmulatedRegExp` is required for some patterns, ensure it's properly imported and bundled. Consider whether less complex patterns can avoid `EmulatedRegExp` entirely.
This functionality has moved to the `oniguruma-parser` library. If you need AST access, use `oniguruma-parser`. Otherwise, use `toRegExp` from `oniguruma-to-es` to get a JavaScript RegExp object.
Pass your Oniguruma pattern string through `oniguruma-to-es.toRegExp(pattern)` to translate it into a valid JavaScript RegExp object before use.
Ensure you `import { EmulatedRegExp } from 'oniguruma-to-es';` in your module where the precompiled regexes are being used.