胃肠炎吃什么药| 12583是什么电话| rh血型阴性是什么意思| 50岁掉牙齿是什么原因| 下眼袋发青是什么原因| 蛇是什么动物| 孕激素低吃什么补得快| 这什么意思| 猫发烧吃什么药| 秋天是什么样子的| 宫颈多发纳氏囊肿是什么意思| aep是什么意思| 胸膜牵拉是什么意思| 小腿冰凉是什么原因| 咳嗽不能吃什么食物| aug什么意思| 功能性子宫出血是什么原因造成的| 胎毒是什么意思| 儿童支气管炎吃什么药| 什么是真爱| 捞面条配什么菜好吃| 突然发胖要警惕什么病| 潜伏是什么意思| 肛门松弛是什么原因| 痛经吃什么| 肿瘤患者吃什么药可以抑制肿瘤| 什么的游泳| 专柜是什么意思| 洗手指征是什么| 电子烟有什么危害| 尿淀粉酶高是什么原因| 双侧卵巢显示不清是什么意思| 老鼠喜欢吃什么| 热痱子长什么样| 70年产权是什么意思| 胃气上逆吃什么中成药| 智能手环是干什么用的| 生长因子是什么| 被臭虫咬了擦什么药| 秸秆是什么| 心脏不舒服吃什么药最好| 狗刨坑是什么征兆| 炒面用什么面条最好| 梦见海龟是什么意思| 心电图窦性心律是什么意思| 高抬腿运动有什么好处| 小便出血是什么原因| 盗墓笔记它到底是什么| 什么是薪级工资| 1984年属什么| c60是什么| ins是什么社交软件| 胸痛是什么病的前兆| 00属什么生肖| 老公的妈妈叫什么| 咨询是什么意思| 鸭肫是什么| 新生儿血糖低是什么原因| 包块是什么| 打招呼是什么意思| 做月子要注意什么| 理工科是什么意思| 什么是梨形身材| 彩云之南是什么意思| 乙肝15阳性是什么意思| 中暑吃什么好得快| 肿瘤指标偏高什么意思| 左胸下方是什么部位| 7月5号什么星座| 人为什么会有头皮屑| 代谢慢的人吃什么有助于新陈代谢| 甲状腺炎吃什么药好得快| 叶凡为什么找石昊求救| 微量泵是干什么用的| 坐骨神经有什么症状| 肺痨是什么病| 林黛玉和贾宝玉是什么关系| 支气管扩张是什么意思| 多发息肉是什么意思| 开背是什么意思| 浮肿是什么原因| 皮笑肉不笑是什么生肖| 更年期什么年龄开始| 衣原体阴性是什么意思| 反目成仇是什么意思| 容易受惊吓是什么原因| 喝酒对身体有什么好处和坏处| 取次是什么意思| 腼腆是什么意思| 足癣用什么药最快好| 黑长直是什么意思| 幽门螺旋杆菌的症状是什么| 体力不支是什么意思| 70年产权是从什么时候开始算| 基佬是什么意思| 毛字出头念什么| moose是什么意思| 拔牙需要注意什么| 鸟加一笔是什么字| 人加一笔变成什么字| 乌龟喜欢吃什么食物| 豚鼠吃什么食物| 梦见屎是什么意思| 感冒喝什么药| 冠状动脉粥样硬化性心脏病吃什么药| 薄谷开来为什么杀人| 梦见别人盖房子是什么预兆| 长期失眠应该吃什么药| 60大寿送什么礼物| 肠道细菌感染吃什么药| 阴桃花是什么意思| 复方甘草酸苷片治什么病| 戊五行属什么| 主动脉硬化什么意思| 小孩子手脱皮是什么原因引起的| 人的运气跟什么有关| 吃什么改善睡眠| 梦见鼻子出血是什么意思| 联合创始人是什么意思| 破气是什么意思| 眼压高滴什么眼药水| 世袭罔替什么意思| 韩语思密达是什么意思| 人间炼狱是什么意思| 枪代表什么生肖| 脑梗死吃什么药| 什么是肺部磨玻璃结节| 全运会是什么| 肝属于五行中的什么| 囗苦是什么原因| c919是什么意思| 宽慰是什么意思| 螨虫用什么药膏| 狐臭挂什么科室的号| 菠萝蜜什么季节成熟| 什么可以去湿气| 张飞的武器是什么| 二重唱是什么意思| 4月23日是什么星座| 三里屯有什么好玩的地方| 为什么会高血压| 迂回战术什么意思| 五月十日是什么星座| 支气管炎能吃什么水果| 傧相是什么意思| 肺部钙化灶是什么意思| 两颗星是什么军衔| 小舌头学名叫什么| 孕妇吃花生对胎儿有什么好处| 嘴唇神经跳动是什么原因| 奇花异草的异是什么意思| 银屑病为什么会自愈| 很man是什么意思| 子母门是什么意思| 肌酐高吃什么好| 铜钱草能治什么病| 锲而不舍是什么生肖| 开天眼是什么意思| 环状肉芽肿是什么皮肤病| 吃东西就打嗝是什么原因| 1958年是什么年| 什么菜好消化| 近亲为什么不能结婚| 脚后跟长痣有什么寓意| 健身后应该吃什么| 好事将近是什么意思| 烟草是什么植物| 梗米是什么| ckd5期是什么意思| 马躺下睡觉为什么会死| 父母是o型血孩子是什么血型| 脂蛋白是什么| 金字是什么部首| 涨价是什么意思| juicy什么意思| 及时是什么意思| 莲子吃了有什么好处| 男人眉毛短是什么面相| 4月份是什么季节| 脊髓是什么| 扭转乾坤什么意思| 胡萝卜什么时候种| 五月是什么星座的啊| 黎明破晓是什么意思| 秋葵有什么好处| 大蒜泡酒有什么功效| 巴宝莉是什么品牌| 妈妈的奶奶应该叫什么| 王菲什么星座| 黄鳝喜欢吃什么| 费力不讨好是什么生肖| 独角仙生活在什么地方| 7月9日是什么星座| 肋膈角锐利是什么意思| 脾虚湿气重吃什么好| 肝风内动是什么原因造成的| 梦见很多苍蝇是什么意思| 胃发炎吃什么药好得快| 风寒感冒吃什么药好| 肩周炎吃什么药最好| 哺乳期抽烟对宝宝有什么影响| 减肥最快的方法是什么| 什么叫高危行为| 根充是什么意思| 护士要什么学历| 身份证穿什么衣服| 原发性高血压什么意思| 双手合十什么意思| 报考军校需要什么条件| 陈皮是什么做的| 左眼屈光不正是什么意思| 杜甫被称为什么| 支气管炎吃什么药最有效| 指甲的月牙代表什么| 肝实质回声细密是什么意思| 地区和市有什么区别| 血糖用什么字母表示| 准生证什么时候办| 歧视什么意思| CNN什么意思| 风疹病毒igg阳性是什么意思| 家里进鸟了是什么预兆| 脚烧是什么原因| 为什么指甲有竖纹| 借鉴是什么意思| 消石灰是什么| 羊内腰和外腰分别是什么| 男生被口是什么感觉| 西梅什么时候上市| 察言观色是什么意思| 红粉是什么意思| lady是什么意思啊| 微信中抱拳是什么意思| 夏朝前面是什么朝代| 干性湿疹用什么药膏| 亥时右眼跳是什么预兆| 狗狗咳嗽吃什么药好得快| 玄色是什么颜色| 神经性头痛吃什么药效果好| 月经周期是什么意思| ca医学代表什么意思| 缘是什么意思| 贲门松弛吃什么药| 手上长红点是什么原因| 血红蛋白高是什么原因| 什么的遐想| 城市的夜晚霓虹灯璀璨是什么歌| 丁桂鱼吃什么食物| 为什么会经常流鼻血| 包皮炎看什么科| 务实什么意思| 什么是前列腺增生| 属鸡女和什么属相最配| 为什么一紧张就拉肚子| 每天吃维生素c有什么好处| 亭亭净植的亭亭是什么意思| 藤原拓海开的什么车| 结婚十年是什么婚| dolphin是什么意思| 小兔子吃什么食物| 介怀是什么意思| 为什么疤痕会增生| 省军区司令员是什么级别| 鸡拉绿色粪便吃什么药| 百度
Skip to content

mathiasbynens/regexpu

Repository files navigation

regexpu Build status Code coverage status regexpu on npm

regexpu is a source code transpiler that enables the use of ES2015 Unicode regular expressions in JavaScript-of-today (ES5). It rewrites regular expressions that make use of the ES2015 u flag into equivalent ES5-compatible regular expressions.

Here’s an online demo.

Traceur v0.0.61+, Babel v1.5.0+, esnext v0.12.0+, and Bublé v0.12.0+ use regexpu for their u regexp transpilation. The REPL demos for Traceur, Babel, esnext, and Bublé let you try u regexps as well as other ES.next features.

Example

Consider a file named example-es2015.js with the following contents:

var string = 'foo??bar';
var match = string.match(/foo(.)bar/u);
console.log(match[1]);
// → '??'

// This regex matches any symbol from U+1F4A9 to U+1F4AB, and nothing else.
var regex = /[\u{1F4A9}-\u{1F4AB}]/u;
// The following regex is equivalent.
var alternative = /[??-??]/u;
console.log([
  regex.test('a'),  // false
  regex.test('??'), // true
  regex.test('??'), // true
  regex.test('??'), // true
  regex.test('??')  // false
]);

Let’s transpile it:

$ regexpu < example-es2015.js > example-es5.js

example-es5.js can now be used in ES5 environments. Its contents are as follows:

var string = 'foo??bar';
var match = string.match(/foo((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))bar/);
console.log(match[1]);
// → '??'

// This regex matches any symbol from U+1F4A9 to U+1F4AB, and nothing else.
var regex = /(?:\uD83D[\uDCA9-\uDCAB])/;
// The following regex is equivalent.
var alternative = /(?:\uD83D[\uDCA9-\uDCAB])/;
console.log([
  regex.test('a'),  // false
  regex.test('??'), // true
  regex.test('??'), // true
  regex.test('??'), // true
  regex.test('??')  // false
]);

Known limitations

  1. regexpu only transpiles regular expression literals, so things like RegExp('…', 'u') are not affected.
  2. regexpu doesn’t polyfill the RegExp.prototype.unicode getter because it’s not possible to do so without side effects.
  3. regexpu doesn’t support canonicalizing the contents of back-references in regular expressions with both the i and u flag set, since that would require transpiling/wrapping strings.
  4. regexpu doesn’t match lone low surrogates accurately. Unfortunately that is impossible to implement due to the lack of lookbehind support in JavaScript regular expressions.

Installation

To use regexpu programmatically, install it as a dependency via npm:

npm install regexpu --save-dev

To use the command-line interface, install regexpu globally:

npm install regexpu -g

API

regexpu.version

A string representing the semantic version number.

regexpu.rewritePattern(pattern, flags, options)

This is an alias for the rewritePattern function exported by regexpu-core. Please refer to that project’s documentation for more information.

regexpu.rewritePattern uses regjsgen, regjsparser, and regenerate as internal dependencies. If you only need this function in your program, it’s better to include it directly:

// Instead of…
const rewritePattern = require('regexpu').rewritePattern;

// Use this:
const rewritePattern = require('regexpu-core');

This prevents the Recast and Esprima dependencies from being loaded into memory.

regexpu.transformTree(ast, options) or its alias regexpu.transform(ast, options)

This function accepts an abstract syntax tree representing some JavaScript code, and returns a transformed version of the tree in which any regular expression literals that use the ES2015 u flag are rewritten in ES5.

const regexpu = require('regexpu');
const recast = require('recast');
const tree = recast.parse(code); // ES2015 code
const transformedTree = regexpu.transform(tree);
const result = recast.print(transformedTree);
console.log(result.code); // transpiled ES5 code
console.log(result.map); // source map

The optional options object is passed to regexpu-core’s rewritePattern. For a description of the available options, see its documentation.

regexpu.transformTree uses Recast, regjsgen, regjsparser, and regenerate as internal dependencies. If you only need this function in your program, it’s better to include it directly:

const transformTree = require('regexpu/transform-tree');

This prevents the Esprima dependency from being loaded into memory.

regexpu.transpileCode(code, options)

This function accepts a string representing some JavaScript code, and returns a transpiled version of this code tree in which any regular expression literals that use the ES2015 u flag are rewritten in ES5.

const es2015 = 'console.log(/foo.bar/u.test("foo??bar"));';
const es5 = regexpu.transpileCode(es2015);
// → 'console.log(/foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF])bar/.test("foo??bar"));'

The optional options object recognizes the following properties:

The sourceFileName and sourceMapName properties must be provided if you want to generate source maps.

const result = regexpu.transpileCode(code, {
  'sourceFileName': 'es2015.js',
  'sourceMapName': 'es2015.js.map',
});
console.log(result.code); // transpiled source code
console.log(result.map); // source map

regexpu.transpileCode uses Esprima, Recast, regjsgen, regjsparser, and regenerate as internal dependencies. If you only need this function in your program, feel free to include it directly:

const transpileCode = require('regexpu/transpile-code');

Transpilers that use regexpu internally

If you’re looking for a general-purpose ES.next-to-ES5 transpiler with support for Unicode regular expressions, consider using one of these:

For maintainers

How to publish a new release

  1. On the main branch, bump the version number in package.json:

    npm version patch -m 'Release v%s'

    Instead of patch, use minor or major as needed.

    Note that this produces a Git commit + tag.

  2. Push the release commit and tag:

    git push && git push --tags

    Our CI then automatically publishes the new release to npm.

Author

twitter/mathias
Mathias Bynens

License

regexpu is available under the MIT license.

About

A source code transpiler that enables the use of ES2015 Unicode regular expressions in ES5.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

胃癌是什么原因引起的 令是什么生肖 6月12日是什么星座 胃顶的难受是什么原因 什么是再生纤维面料
12345是什么投诉电话 猪肝吃多了有什么坏处 海藻面膜有什么作用 咽喉肿痛吃什么消炎药 什么是棱长
过年送什么礼物好 暮春是什么时候 什么菜降血压效果最好 土字旁的字有什么 左腹部是什么器官
打开心扉是什么意思 cdfi是什么意思 脂肪肝是什么意思 大败是什么意思 立冬北方吃什么
腊肉炒什么菜好吃hcv9jop4ns1r.cn 2月28号是什么星座hcv8jop2ns2r.cn 梦见动物是什么意思hcv7jop5ns3r.cn 为什么生理期过后最容易掉秤0735v.com mA是什么hcv9jop2ns9r.cn
阳起石是什么东西hcv9jop0ns8r.cn 肉字五行属什么hcv8jop0ns0r.cn 印堂发红是什么的征兆hcv7jop6ns4r.cn 学护理需要什么条件wmyky.com 国债什么意思hcv8jop0ns5r.cn
肝右叶钙化灶是什么意思fenrenren.com 营养心脏最好的药是什么药hcv9jop8ns1r.cn 能屈能伸是什么生肖weuuu.com 脾胃湿热吃什么药好cj623037.com 什么叫类风湿hcv8jop0ns4r.cn
风流是什么意思hcv9jop1ns8r.cn 孩子急性肠胃炎吃什么药hcv7jop6ns8r.cn 胸疼挂什么科室hcv8jop2ns0r.cn 34周为什么不建议保胎hcv9jop8ns0r.cn m型发际线适合什么发型xinjiangjialails.com
百度