@babel/plugin-transform-unicode-property-regex

unicode-property-regex - 图1info

This plugin is included in @babel/preset-env, in ES2018

This plugin transforms regular expression literals to support the \p{...} escapes. It does not patch the new RegExp constructor, since its arguments cannot be pre-transformed statically: to handle runtime behavior of functions/classes, you will need to use a polyfill instead.

Here’s an online demo.

Installation

  • npm
  • Yarn
  • pnpm
  1. npm install --save-dev @babel/plugin-transform-unicode-property-regex
  1. yarn add --dev @babel/plugin-transform-unicode-property-regex
  1. pnpm add --save-dev @babel/plugin-transform-unicode-property-regex

Usage

babel.config.json

  1. {
  2. "plugins": ["@babel/plugin-transform-unicode-property-regex"]
  3. }

Via CLI

Shell

  1. babel --plugins @babel/@babel/plugin-transform-unicode-property-regex script.js

Via Node.js API

JavaScript

  1. require("@babel/core").transformSync(code, {
  2. plugins: ["@babel/plugin-transform-unicode-property-regex"],
  3. });

To transpile to ES6/ES2015:

JavaScript

  1. require("@babel/core").transformSync(code, {
  2. plugins: [
  3. [
  4. "@babel/plugin-transform-unicode-property-regex",
  5. { useUnicodeFlag: false },
  6. ],
  7. ],
  8. });

Options

  • useUnicodeFlag (defaults to true)

When disabled with false, the transform converts Unicode regexes to non-Unicode regexes for wider support, removing the u flag. See https://github.com/mathiasbynens/regexpu-core#useunicodeflag-default-false for more information.

unicode-property-regex - 图2tip

You can read more about configuring plugin options here

Author

twitter/mathias
Mathias Bynens