Registry / serialization / regexpu-core

regexpu-core

JSON →
library6.4.0jsnpmunverified

regexpu-core is the core module of regexpu, a transpiler that converts ES2015 Unicode regular expressions (with the `u` and `v` flags) into ES5-compatible patterns. Current stable version is 6.4.0. It supports features like Unicode property escapes, dotAll flag, named capture groups, and the `v` flag (unicodeSetsFlag), with options to either pass through or transform them. Released on npm with TypeScript types, it has a steady release cadence, updated for Unicode 15.1. Key differentiator: focused on core regexp rewriting without the full regexpu CLI, used by Babel and other tools.

npm install regexpu-core
INSTALL
IMPORT
SIG · REGEXPU-CORE
R
regexpu-core
serializationjavascriptv6.4.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-core'
const rewritePattern = require('regexpu-core')
Default export; ESM and CJS both supported. In CJS, require returns the function directly.
rewritePattern (named)
import { rewritePattern } from 'regexpu-core'
import rewritePattern from 'regexpu-core'
Named export also available since v5.1.0; both named and default exports are the same function.
types
import type { RewritePatternOptions } from 'regexpu-core'
import { RewritePatternOptions } from 'regexpu-core'
Use `import type` for TypeScript interfaces to avoid runtime import.

Shows basic usage of rewritePattern to transpile a Unicode property escape regex into ES5-compatible pattern.

import rewritePattern from 'regexpu-core'; // Transform a Unicode regex with 'u' flag to ES5 const pattern = '\\p{ASCII_Hex_Digit}+'; const flags = 'u'; const result = rewritePattern(pattern, flags, { unicodePropertyEscapes: 'transform', unicodeFlag: 'transform', }); console.log(result); // E.g.: '(?:[0-9A-Fa-f])+'
Debug
Known issues
breakingv6.0.0: Always enable unicodeSetsFlag parsing. Removed option to disable 'v' flag support.
fix
Remove any setting that disables 'v' flag; pattern is always parsed with 'v' flag support.
affects: >=6.0.0 <6.0.0
deprecatedThe 'useUnicodeFlag' option is deprecated since v5.0.0.
fix
Replace 'useUnicodeFlag' with 'unicodeFlag' option.
affects: >=5.0.0 <5.0.0
gotchaWhen using CommonJS require, the default export is the function, not an object.
fix
Use `const rewritePattern = require('regexpu-core');` not `require('...').rewritePattern`.
affects: >=4.0.0
gotchaThe 'unicodeFlag' option must be 'transform' to actually transform; false leaves it as-is.
fix
Set `unicodeFlag: 'transform'` explicitly to get ES5-compatible output.
affects: >=5.0.0
gotchaNamed capture groups are not transformed by default; must set 'namedGroups' option.
fix
Pass `namedGroups: 'transform'` option to compile named groups.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: rewritePattern is not a function
Using named import when default export expected in CJS.
fix
Use `const rewritePattern = require('regexpu-core');`
Can't find module 'regexpu-core/data/character-class-escape-sets'
Importing internal modules directly, not part of public API.
fix
Do not import from internal paths; use only 'regexpu-core'.
TypeScript error: 'RewritePatternOptions' is a type and must be imported using a type-only import
Using regular import for a type-only export.
fix
Use `import type { RewritePatternOptions } from 'regexpu-core';`
Upgrade
Version history
6.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
regexpu-core — npm install regexpu-core · libregistry