main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
774 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
4 | var toString = require('../internals/to-string');
|
---|
5 | var WHITESPACES = require('../internals/whitespaces');
|
---|
6 |
|
---|
7 | var charCodeAt = uncurryThis(''.charCodeAt);
|
---|
8 | var replace = uncurryThis(''.replace);
|
---|
9 | var NEED_ESCAPING = RegExp('[!"#$%&\'()*+,\\-./:;<=>?@[\\\\\\]^`{|}~' + WHITESPACES + ']', 'g');
|
---|
10 |
|
---|
11 | // `RegExp.escape` method
|
---|
12 | // https://github.com/tc39/proposal-regex-escaping
|
---|
13 | $({ target: 'RegExp', stat: true, forced: true }, {
|
---|
14 | escape: function escape(S) {
|
---|
15 | var str = toString(S);
|
---|
16 | var firstCode = charCodeAt(str, 0);
|
---|
17 | // escape first DecimalDigit
|
---|
18 | return (firstCode > 47 && firstCode < 58 ? '\\x3' : '') + replace(str, NEED_ESCAPING, '\\$&');
|
---|
19 | }
|
---|
20 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.