Regenerate is a specialized JavaScript library designed to create regular expressions from a given set of Unicode symbols or code points. It intelligently handles the complexities of Unicode in JavaScript, particularly with astral symbols (those outside the Basic Multilingual Plane), by generating ES5-compatible patterns that correctly match these characters, typically using surrogate pairs. The library provides a fluent, chainable API to add, remove, and manage code points and ranges, allowing developers to precisely define character sets for their regexes. Currently at version 1.4.2, the package appears to be in a maintenance or stable state, having seen its last significant update several years ago, indicating a mature and feature-complete solution for Unicode-aware regex generation. It remains a valuable tool for ensuring cross-browser and historical JavaScript engine compatibility when dealing with advanced Unicode characters in regular expressions.
npm install regenerateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `regenerate` set, add and remove individual code points and ranges, and finally generate both the regex string and the `RegExp` object. It also shows adding multiple values directly during initialization, including astral symbols.
Thoroughly test existing regex generation logic when upgrading from versions older than 0.6.0. Review the generated regex patterns and their behavior, especially with complex Unicode sets.
In Node.js ESM, use `import * as regenerate from 'regenerate';`. For TypeScript, ensure `esModuleInterop` is enabled in `tsconfig.json`. When using bundlers, verify their CJS-to-ESM interop settings. Alternatively, stick to `const regenerate = require('regenerate');` in CJS files.Evaluate if the lack of ongoing maintenance poses a risk for your project's specific requirements. For most Unicode regex generation needs, the existing functionality should remain robust.
Do not add the `u` flag to regular expressions generated by `regenerate` unless you fully understand its implications and have thoroughly tested the resulting patterns. `regenerate`'s output is designed to work correctly without the `u` flag in older environments, and with it, in modern ones, the surrogate pair handling might conflict with native Unicode matching.
Ensure you are importing the package correctly. For CommonJS, use `const regenerate = require('regenerate');`. For ESM (especially in TypeScript), use `import * as regenerate from 'regenerate';` to capture the CJS default export as a namespace object, then call `regenerate.default()` or `regenerate()` if your transpiler unwraps it.Always call the `regenerate()` function first to create a new set instance, then chain its methods: `regenerate().add(0x60).addRange(0x6A, 0x6B);`
Verify your project's `package.json` for `"type": "module"` and adjust import/export strategies. Ensure your bundler or Node.js environment is correctly configured for CJS-ESM interop. If possible, consider changing the consuming file to use ESM `import` syntax or ensure `esModuleInterop` is enabled in TypeScript.
No dependency data recorded yet.