babel-plugin-transform-regexp-constructors
Example
In
JavaScript
const foo = "ab+";
var a = new RegExp(foo + "c", "i");
Out
JavaScript
const foo = "ab+";
var a = /ab+c/i;
Installation
- npm
- Yarn
- pnpm
npm install babel-plugin-transform-regexp-constructors --save-dev
yarn add babel-plugin-transform-regexp-constructors --dev
pnpm add babel-plugin-transform-regexp-constructors --save-dev
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["transform-regexp-constructors"]
}
Via CLI
Shell
babel --plugins transform-regexp-constructors script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["transform-regexp-constructors"],
});