Registry / serialization / regexpu

regexpu

JSON →
library4.8.0jsnpmunverified

regexpu is a source code transpiler that enables the use of ES2015 Unicode regular expressions (the `u` flag) in ES5 environments. It rewrites regex literals with the `u` flag into equivalent ES5-compatible patterns, handling Unicode properties, escapes, and case folding. Current version 4.8.0 (stable) releases infrequently; major version bumps (e.g., 2.0.0) introduced breaking changes in module export paths. Key differentiators: it is the core engine behind Babel, Traceur, and other transpilers for Unicode regex; also ships `regexpu-core` for programmatic use. Supports Node >=6 and browsers via bundlers.

npm install regexpu
INSTALL
IMPORT
SIG · REGEXPU
R
regexpu
serializationjavascriptv4.8.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rewritePattern
import { rewritePattern } from 'regexpu'
const rewritePattern = require('regexpu').rewritePattern
Before v2.0.0, the correct import was require('regexpu').rewritePattern; after v2.0.0, ESM-style named import is preferred. CommonJS users should use the new path.
default
import regexpu from 'regexpu'
const regexpu = require('regexpu')
Default export exists in ESM; CommonJS requires destructuring. ESM-only since v2.0.0?
rewritePattern (from regexpu-core)
import { rewritePattern } from 'regexpu-core'
const rewritePattern = require('regexpu').rewritePattern
The core module regexpu-core is the recommended way since v2.0.0; the main package now re-exports it.

Transpiles a Unicode regex pattern with the u flag to an ES5-compatible equivalent, demonstrating usage of rewritePattern with options.

import { rewritePattern } from 'regexpu-core'; // Transpile a regex with the u flag to ES5 const pattern = '\\p{ASCII_Hex_Digit}'; const flags = 'u'; const result = rewritePattern(pattern, flags); console.log(result); // '[A-Fa-f0-9]' // With support for Unicode properties const pattern2 = '\\p{Emoji}'; const flags2 = 'u'; const result2 = rewritePattern(pattern2, flags2, { unicodePropertyEscape: true }); console.log(result2); // '[...]'
Debug
Known issues
breakingBreaking change in v2.0.0: require('regexpu-core') is the new require('regexpu/rewrite-pattern')
fix
Update imports: use require('regexpu-core') or import { rewritePattern } from 'regexpu-core' instead of old require('regexpu').rewritePattern.
affects: >= 2.0.0
deprecatedUsing require('regexpu') directly may be deprecated; prefer regexpu-core submodule.
fix
Switch to require('regexpu-core') for the rewritePattern function.
affects: >= 2.0.0
gotchaThe package only transpiles the regex pattern string; it does not handle the regular expression literal syntax. Pass the pattern without delimiters.
fix
Ensure input is a string pattern (e.g., '\\p{ASCII_Hex_Digit}') not '/\\p{ASCII_Hex_Digit}/u'.
affects: >= 1.0.0
gotchaOptions object must be passed correctly: { unicodePropertyEscape: true } to enable Unicode property escapes (default false).
fix
Pass options as second or third argument to rewritePattern.
affects: >= 3.0.0
Errors
Common errors & fixes
require is not defined
Trying to use CommonJS require in an ESM module (e.g., .mjs file or type:module).
fix
Use import statements: import { rewritePattern } from 'regexpu-core';
Cannot find module 'regexpu' or 'regexpu-core'
Module not installed or incorrect import path.
fix
Install the correct package: npm install regexpu --save (or regexpu-core if using core).
rewritePattern is not a function
Import destructuring error; default export vs named export confusion.
fix
Use named import: import { rewritePattern } from 'regexpu-core';
Upgrade
Version history
4.8.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
regexpu — npm install regexpu · libregistry