From 605e9e49151e014c878f86f64667857c286467f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 3 Feb 2022 00:01:35 +0100 Subject: [PATCH] Add docs for the new `unicode-sets-regex` plugin (#2615) Co-authored-by: Brian Ng --- docs/plugin-proposal-unicode-sets-regex.md | 49 ++++++++++++++++++++++ docs/plugin-syntax-unicode-sets-regex.md | 47 +++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 docs/plugin-proposal-unicode-sets-regex.md create mode 100644 docs/plugin-syntax-unicode-sets-regex.md diff --git a/docs/plugin-proposal-unicode-sets-regex.md b/docs/plugin-proposal-unicode-sets-regex.md new file mode 100644 index 0000000000..880587e878 --- /dev/null +++ b/docs/plugin-proposal-unicode-sets-regex.md @@ -0,0 +1,49 @@ +--- +id: babel-plugin-proposal-unicode-sets-regex +title: @babel/plugin-proposal-unicode-sets-regex +sidebar_label: unicode-sets-regex +--- + +This plugin transforms regular expressions using the `v` flag, introduced by the [RegExp set notation + properties of strings](https://github.com/tc39/proposal-regexp-set-notation) proposal, to regular expressions that use the `u` flag. + +## Example + +```js +/[\p{ASCII}&&\p{Decimal_Number}]/v +``` + +will be transformed to + +```js +/[0-9]/u +``` + +## Installation + +```sh +npm install --save-dev @babel/plugin-proposal-unicode-sets-regex +``` + +## Usage + +### With a configuration file (Recommended) + +```json +{ + "plugins": ["@babel/plugin-proposal-unicode-sets-regex"] +} +``` + +### Via CLI + +```sh +babel --plugins @babel/plugin-proposal-unicode-sets-regex script.js +``` + +### Via Node API + +```javascript +require("@babel/core").transformSync("code", { + plugins: ["@babel/plugin-proposal-unicode-sets-regex"], +}); +``` diff --git a/docs/plugin-syntax-unicode-sets-regex.md b/docs/plugin-syntax-unicode-sets-regex.md new file mode 100644 index 0000000000..51aa8e9187 --- /dev/null +++ b/docs/plugin-syntax-unicode-sets-regex.md @@ -0,0 +1,47 @@ +--- +id: babel-plugin-syntax-unicode-sets-regex +title: @babel/plugin-syntax-unicode-sets-regex +sidebar_label: syntax-unicode-sets-regex +--- + +> #### Syntax only +> +> It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use [plugin-proposal-unicode-sets-regex](plugin-proposal-unicode-sets-regex.md) to _both_ parse and transform this syntax. + +This plugin enables parsing regular expressions using the `v` flag, introduced by the [RegExp set notation + properties of strings](https://github.com/tc39/proposal-regexp-set-notation) proposal, to regular expressions that use the `u` flag. + +## Example + +```js +/[\p{ASCII}&&\p{Decimal_Number}]/v +``` + +## Installation + +```sh +npm install --save-dev @babel/plugin-syntax-unicode-sets-regex +``` + +## Usage + +### With a configuration file (Recommended) + +```json +{ + "plugins": ["@babel/plugin-syntax-unicode-sets-regex"] +} +``` + +### Via CLI + +```sh +babel --plugins @babel/plugin-syntax-unicode-sets-regex script.js +``` + +### Via Node API + +```javascript +require("@babel/core").transformSync("code", { + plugins: ["@babel/plugin-syntax-unicode-sets-regex"], +}); +```