{"_id":"babel-plugin-transform-modern-regexp","_rev":"3115389","name":"babel-plugin-transform-modern-regexp","description":"Enables modern RegExp features in JavaScript","dist-tags":{"latest":"0.0.6"},"maintainers":[{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"}],"time":{"modified":"2023-11-27T05:51:32.000Z","created":"2017-04-17T07:49:33.959Z","0.0.6":"2018-08-24T11:50:52.411Z","0.0.5":"2018-05-14T18:21:20.882Z","0.0.4":"2017-04-24T22:44:20.164Z","0.0.3":"2017-04-17T21:49:56.072Z","0.0.2":"2017-04-17T21:29:04.972Z","0.0.1":"2017-04-17T07:49:33.959Z"},"users":{},"author":{"name":"Dmitry Soshnikov"},"repository":{"type":"git","url":"git+https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp.git"},"versions":{"0.0.6":{"name":"babel-plugin-transform-modern-regexp","version":"0.0.6","license":"MIT","description":"Enables modern RegExp features in JavaScript","repository":{"type":"git","url":"git+https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp.git"},"homepage":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp","bugs":{"url":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues"},"scripts":{"test":"jest"},"keywords":["regexp","es2018","modern","xflag","lookbehind","babel"],"author":{"name":"Dmitry Soshnikov"},"engines":{"node":">=6"},"dependencies":{"regexp-tree":"^0.0.85"},"devDependencies":{"babel-core":"^6.26.3","jest-cli":"^19.0.2"},"jest":{"testPathIgnorePatterns":["/node_modules/","fixtures"]},"gitHead":"dd189c9ad95c5623eb419ddbf8469c695aacf994","_id":"babel-plugin-transform-modern-regexp@0.0.6","_npmVersion":"6.1.0","_nodeVersion":"9.11.1","_npmUser":{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"},"dist":{"shasum":"010be0b62e4695a2006bd8ddb3ae0f5e5b0fc067","size":6302,"noattachment":false,"key":"/babel-plugin-transform-modern-regexp/-/babel-plugin-transform-modern-regexp-0.0.6.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-modern-regexp/download/babel-plugin-transform-modern-regexp-0.0.6.tgz"},"maintainers":[{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-modern-regexp_0.0.6_1535111452262_0.7719188677897955"},"_hasShrinkwrap":false,"publish_time":1535111452411,"_cnpm_publish_time":1535111452411,"_cnpmcore_publish_time":"2021-12-16T18:25:47.605Z"},"0.0.5":{"name":"babel-plugin-transform-modern-regexp","version":"0.0.5","license":"MIT","description":"Enables modern RegExp features in JavaScript","repository":{"type":"git","url":"git+https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp.git"},"homepage":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp","bugs":{"url":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues"},"scripts":{"test":"jest"},"keywords":["regexp","es2018","modern","xflag","lookbehind","babel"],"author":{"name":"Dmitry Soshnikov"},"engines":{"node":">=6"},"dependencies":{"regexp-tree":"^0.0.43"},"devDependencies":{"babel-core":"6.24.1","jest-cli":"^19.0.2"},"jest":{"testPathIgnorePatterns":["/node_modules/","fixtures"]},"gitHead":"6ddc6b9a0b6f7556a0b4152ebcff4582db0fb5f1","_id":"babel-plugin-transform-modern-regexp@0.0.5","_npmVersion":"5.6.0","_nodeVersion":"9.11.1","_npmUser":{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"},"dist":{"shasum":"53cfa38db0c5a81c4ffe3bacf24bd9c13e9d8995","size":6398,"noattachment":false,"key":"/babel-plugin-transform-modern-regexp/-/babel-plugin-transform-modern-regexp-0.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-modern-regexp/download/babel-plugin-transform-modern-regexp-0.0.5.tgz"},"maintainers":[{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-modern-regexp_0.0.5_1526322080801_0.8611859161486304"},"_hasShrinkwrap":false,"publish_time":1526322080882,"_cnpm_publish_time":1526322080882,"_cnpmcore_publish_time":"2021-12-16T18:25:47.843Z"},"0.0.4":{"name":"babel-plugin-transform-modern-regexp","version":"0.0.4","license":"MIT","description":"Enables modern RegExp features in JavaScript","repository":{"type":"git","url":"git+https://github.com/dmitrysoshnikov/babel-plugin-transform-modern-regexp.git"},"homepage":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp","bugs":{"url":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues"},"scripts":{"test":"jest"},"keywords":["regexp","es2018","modern","xflag","lookbehind","babel"],"author":{"name":"Dmitry Soshnikov"},"engines":{"node":">=6"},"dependencies":{"regexp-tree":"^0.0.43"},"devDependencies":{"babel-core":"6.24.1","jest-cli":"^19.0.2"},"jest":{"testPathIgnorePatterns":["/node_modules/","fixtures"]},"gitHead":"78274325c7d0da329f7057e8f094a1ccae06a968","_id":"babel-plugin-transform-modern-regexp@0.0.4","_shasum":"457b2f087d4a8fb8b73c7128ee5aba3b654b449c","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.5.0","_npmUser":{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"},"dist":{"shasum":"457b2f087d4a8fb8b73c7128ee5aba3b654b449c","size":8388,"noattachment":false,"key":"/babel-plugin-transform-modern-regexp/-/babel-plugin-transform-modern-regexp-0.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-modern-regexp/download/babel-plugin-transform-modern-regexp-0.0.4.tgz"},"maintainers":[{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/babel-plugin-transform-modern-regexp-0.0.4.tgz_1493073858304_0.8577616182155907"},"directories":{},"publish_time":1493073860164,"_hasShrinkwrap":false,"_cnpm_publish_time":1493073860164,"_cnpmcore_publish_time":"2021-12-16T18:25:48.056Z"},"0.0.3":{"name":"babel-plugin-transform-modern-regexp","version":"0.0.3","license":"MIT","description":"Enables modern RegExp features in JavaScript","repository":{"type":"git","url":"git+https://github.com/dmitrysoshnikov/babel-plugin-transform-modern-regexp.git"},"homepage":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp","bugs":{"url":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues"},"scripts":{"test":"jest"},"keywords":["regexp","es2018","modern","xflag","lookbehind","babel"],"author":{"name":"Dmitry Soshnikov"},"engines":{"node":">=6"},"dependencies":{"regexp-tree":"^0.0.43"},"devDependencies":{"babel-core":"6.24.1","jest-cli":"^19.0.2"},"jest":{"testPathIgnorePatterns":["/node_modules/","fixtures"]},"gitHead":"2c4ef197f7adf538ac7cea3bfa1b7d83648092d3","_id":"babel-plugin-transform-modern-regexp@0.0.3","_shasum":"abbef542efaa937749f085c8638dd3433847166c","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.5.0","_npmUser":{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"},"dist":{"shasum":"abbef542efaa937749f085c8638dd3433847166c","size":7056,"noattachment":false,"key":"/babel-plugin-transform-modern-regexp/-/babel-plugin-transform-modern-regexp-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-modern-regexp/download/babel-plugin-transform-modern-regexp-0.0.3.tgz"},"maintainers":[{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/babel-plugin-transform-modern-regexp-0.0.3.tgz_1492465795774_0.9513080017641187"},"directories":{},"publish_time":1492465796072,"_hasShrinkwrap":false,"_cnpm_publish_time":1492465796072,"_cnpmcore_publish_time":"2021-12-16T18:25:48.265Z"},"0.0.2":{"name":"babel-plugin-transform-modern-regexp","version":"0.0.2","license":"MIT","description":"Enables modern RegExp features in JavaScript","repository":{"type":"git","url":"git+https://github.com/dmitrysoshnikov/babel-plugin-transform-modern-regexp.git"},"homepage":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp","bugs":{"url":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues"},"scripts":{"test":"jest"},"keywords":["regexp","es2018","modern","xflag","lookbehind","babel"],"author":{"name":"Dmitry Soshnikov"},"engines":{"node":">=6"},"dependencies":{"regexp-tree":"^0.0.43"},"devDependencies":{"babel-core":"6.24.1","jest-cli":"^19.0.2"},"jest":{"testPathIgnorePatterns":["/node_modules/","fixtures"]},"gitHead":"7ce35ae36b7d94013886f89c55a7044e48727b09","_id":"babel-plugin-transform-modern-regexp@0.0.2","_shasum":"c39dc8f4c9fa5173e1ad0e4e569568a422fc6787","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.5.0","_npmUser":{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"},"dist":{"shasum":"c39dc8f4c9fa5173e1ad0e4e569568a422fc6787","size":7002,"noattachment":false,"key":"/babel-plugin-transform-modern-regexp/-/babel-plugin-transform-modern-regexp-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-modern-regexp/download/babel-plugin-transform-modern-regexp-0.0.2.tgz"},"maintainers":[{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/babel-plugin-transform-modern-regexp-0.0.2.tgz_1492464543017_0.8787528681568801"},"directories":{},"publish_time":1492464544972,"_hasShrinkwrap":false,"_cnpm_publish_time":1492464544972,"_cnpmcore_publish_time":"2021-12-16T18:25:48.563Z"},"0.0.1":{"name":"babel-plugin-transform-modern-regexp","version":"0.0.1","license":"MIT","description":"Enables modern RegExp features in JavaScript","repository":{"type":"git","url":"git+https://github.com/dmitrysoshnikov/babel-plugin-transform-modern-regexp.git"},"homepage":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp","bugs":{"url":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues"},"scripts":{"test":"jest"},"keywords":["regexp","es2018","modern","xflag","lookbehind","babel"],"author":{"name":"Dmitry Soshnikov"},"engines":{"node":">=6"},"dependencies":{"regexp-tree":"^0.0.43"},"devDependencies":{"babel-core":"6.24.1","jest-cli":"^19.0.2"},"jest":{"testPathIgnorePatterns":["/node_modules/","fixtures"]},"gitHead":"c0e49dd7a2c3f93572b6449b7d18eb2c814951e1","_id":"babel-plugin-transform-modern-regexp@0.0.1","_shasum":"c3d42db77d8089c850f10adf177cf4ebb2c58a2f","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.5.0","_npmUser":{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"},"dist":{"shasum":"c3d42db77d8089c850f10adf177cf4ebb2c58a2f","size":5963,"noattachment":false,"key":"/babel-plugin-transform-modern-regexp/-/babel-plugin-transform-modern-regexp-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-modern-regexp/download/babel-plugin-transform-modern-regexp-0.0.1.tgz"},"maintainers":[{"name":"dmitrysoshnikov","email":"dmitry.soshnikov@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/babel-plugin-transform-modern-regexp-0.0.1.tgz_1492415373738_0.9274103147909045"},"directories":{},"publish_time":1492415373959,"_hasShrinkwrap":false,"_cnpm_publish_time":1492415373959,"_cnpmcore_publish_time":"2021-12-16T18:25:48.779Z"}},"readme":"# babel-plugin-transform-modern-regexp\n\n[![Build Status](https://travis-ci.org/DmitrySoshnikov/babel-plugin-transform-modern-regexp.svg?branch=master)](https://travis-ci.org/DmitrySoshnikov/babel-plugin-transform-modern-regexp) [![npm version](https://badge.fury.io/js/babel-plugin-transform-modern-regexp.svg)](https://badge.fury.io/js/babel-plugin-transform-modern-regexp)\n\nEnables modern RegExp features in JavaScript.\n\nYou can get an overview of the plugin in [this article](https://medium.com/@DmitrySoshnikov/using-modern-regexes-in-javascript-30322af557c5).\n\n### Table of Contents\n\n- [Features](#features)\n  - [dotAll s-flag](#dotall-s-flag)\n  - [Named capturing groups](#named-capturing-groups)\n  - [Extended x-flag](#extended-x-flag)\n- [Plugin options](#plugin-options)\n  - [`features` option](#features-option)\n  - [`useRe` option](#usere-option)\n  - [`useRuntime` option](#useruntime-option)\n- [Usage](#usage)\n  - [Via `.babelrc`](#via-babelrc)\n  - [Via CLI](#via-cli)\n  - [Via Node.js API](#via-nodejs-api)\n\n## Features\n\nThe plugin enables the following features for JS regular expressions:\n\n* \"dotAll\" `s`-flag (stage 3 proposal)\n* Named capturing groups (stage 3 proposal)\n* Extended `x`-flag (non-standard)\n\nSee also examples in [compat-transpile](https://www.npmjs.com/package/regexp-tree#using-compat-transpiler-api), and [regexp extensions](https://www.npmjs.com/package/regexp-tree#regexp-extensions) sections of [regexp-tree](https://www.npmjs.com/package/regexp-tree).\n\n### dotAll s-flag\n\nSee details in the [proposal](https://github.com/mathiasbynens/es-regexp-dotall-flag).\n\nBy default the `.` symbol matches all symbols _but_ new lines. The \"dotAll\" `s` flag enables matching `\\n` and other new line symbols with the `.` symbol:\n\n```js\n// Simple.\n/./s;\n\n// With unicode `u` flag.\n/./su;\n```\n\nIt is translated into:\n\n```js\n// Simple.\n/[\\0-\\uFFFF]/;\n\n// With unicode `u` flag.\n/[\\0-\\u{10FFFF}]/u;\n```\n\n### Named capturing groups\n\nSee details in the [proposal](https://github.com/tc39/proposal-regexp-named-groups).\n\nCapturing groups in JS regexes until recent supported only numbered-matching.\n\nFor example, given `/(\\d{4})-(\\d{2})-(\\d{2})/` that matches a date, one cannot be sure which group corresponds to the month and which one is the day without examining the surrounding code. Also, if one wants to swap the order of the month and the day, the group references should also be updated.\n\nNamed capture groups provide a nice solution for these issues.\n\n```js\n/(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})/\n```\n\nTo backreference a named group, we can use `\\k<name>` notation:\n\n```js\n/(?<value>a)\\k<value>\\1/\n```\n\nThe above regexp is translated into:\n\n```js\n/(a)\\1\\1/\n```\n\n### Extended x-flag\n\n> Note: `x`-flag is not yet standardized by ES spec. It's a standard flag in PCRE, Python, and other regexes.\n\nSome features, like `x`-flag currently can only be used via `new RegExp(...)` pattern, since are not supported yet by JavaScript parsers for regexp literals:\n\n```js\nnew RegExp(`\n\n  # A regular expression for date.\n\n  (?<year>\\\\d{4})-    # year part of a date\n  (?<month>\\\\d{2})-   # month part of a date\n  (?<day>\\\\d{2})      # day part of a date\n\n`, 'x');\n```\n\nTranslated into:\n\n```js\n/(\\d{4})-(\\d{2})-(\\d{2})/;\n```\n\n## Plugin options\n\nThe plugin supports the following options.\n\n### `features` option\n\nThis options allows choosing which specific transformations to apply. Available features are:\n\n- `dotAll`\n- `namedCapturingGroups`\n- `xFlag`\n\nwhich can be specified as an extra object for the plugin:\n\n```json\n{\n  \"plugins\": [\"transform-modern-regexp\", {\n    \"features\": [\n      \"namedCapturingGroups\",\n      \"xFlag\"\n    ]\n  }]\n}\n```\n\n> NOTE: if omitted, all features are used by default.\n\n### `useRe` option\n\nThis option enables a convenient `re` shorthand, which allows using multiline regexes with _single escape for meta-characters_ (just like in regular expression literals).\n\nTaking example of the date regexep using standard `RegExp` constructor:\n\n```js\nnew RegExp(`\n\n  # A regular expression for date.\n\n  (?<year>\\\\d{4})-    # year part of a date\n  (?<month>\\\\d{2})-   # month part of a date\n  (?<day>\\\\d{2})      # day part of a date\n\n`, 'x');\n```\n\nwe see inconvenient double-escaping of `\\\\d` (and similarly for other meta-characters). The `re` shorthand allows using single escaping:\n\n```js\nre`/\n\n  # A regular expression for date.\n\n  (?<year>\\d{4})-    # year part of a date\n  (?<month>\\d{2})-   # month part of a date\n  (?<day>\\d{2})      # day part of a date\n\n/x`;\n```\n\nAs we can see, `re` accepts a regexp in the _literal notation_, which unifies the usage format.\n\nIn both cases it's translated to simple regexp literal, so no any runtime overhead:\n\n```js\n/(\\d{4})-(\\d{2})-(\\d{2})/\n```\n\n> NOTE: it supports only template string literals, you can't use expressions there. Be careful also with `/${4}/` -- this is treated as a template literal expression, and should be written as `/\\${4}/` instead.\n\n> NOTE: `\\\\1` backreferences should still be escaped with _double slashes_. This is due template literal strings do not allow `\\1` treating them as Octal numbers.\n\n### `useRuntime` option\n\n> NOTE: the `useRuntime` option is not implemented yet. Track [issue #3](https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues/3) for details.\n\n> NOTE: `useRuntime` is not required: if e.g. named groups are used mostly for readability, the `useRuntime` can be omitted. If you need to access actual group names on the matched results, the runtime support should be used.\n\nThis option enables usage of a supporting runtime for the transformed regexes. The `RegExpTree` class is a thin wrapper on top of a native regexp, and has identical API.\n\n> NOTE: `regexp-tree-runtime` should be in your dependencies list.\n\nE.g. the [date expression](#extended-x-flag) from above is translated into:\n\n```js\nconst RegExpTree = require('regexp-tree-runtime');\n\n...\n\nconst re = new RegExpTree(/(\\d{4})-(\\d{2})-(\\d{2})/, {\n  flags: 'x',\n  source: <original-source>,\n  groups: {\n    year: 1,\n    month: 2,\n    day: 3,\n  },\n});\n\nconst result = re.exec('2017-04-17');\n\n// Can access `result.groups`:\n\nconsole.log(result.groups.year); // 2017\n```\n\n## Usage\n\n### Via `.babelrc`\n\n`.babelrc`\n\n```json\n{\n  \"plugins\": [\"transform-modern-regexp\"]\n}\n```\n\n### Via CLI\n\n```sh\n$ babel --plugins transform-modern-regexp script.js\n```\n\n### Via Node.js API\n\n```js\nrequire('babel-core').transform(code, {\n  plugins: ['transform-modern-regexp']\n});\n```\n","_attachments":{},"homepage":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp","bugs":{"url":"https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp/issues"},"license":"MIT"}