source: imaps-frontend/node_modules/core-js/modules/esnext.regexp.escape.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.4 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var uncurryThis = require('../internals/function-uncurry-this');
4var aString = require('../internals/a-string');
5var hasOwn = require('../internals/has-own-property');
6var padStart = require('../internals/string-pad').start;
7var WHITESPACES = require('../internals/whitespaces');
8
9var $Array = Array;
10// eslint-disable-next-line es/no-nonstandard-regexp-properties -- safe
11var $escape = RegExp.escape;
12var charAt = uncurryThis(''.charAt);
13var charCodeAt = uncurryThis(''.charCodeAt);
14var numberToString = uncurryThis(1.1.toString);
15var join = uncurryThis([].join);
16var FIRST_DIGIT_OR_ASCII = /^[0-9a-z]/i;
17var SYNTAX_SOLIDUS = /^[$()*+./?[\\\]^{|}]/;
18var OTHER_PUNCTUATORS_AND_WHITESPACES = RegExp('^[!"#%&\',\\-:;<=>@`~' + WHITESPACES + ']');
19var exec = uncurryThis(FIRST_DIGIT_OR_ASCII.exec);
20
21var ControlEscape = {
22 '\u0009': 't',
23 '\u000A': 'n',
24 '\u000B': 'v',
25 '\u000C': 'f',
26 '\u000D': 'r'
27};
28
29var escapeChar = function (chr) {
30 var hex = numberToString(charCodeAt(chr, 0), 16);
31 return hex.length < 3 ? '\\x' + padStart(hex, 2, '0') : '\\u' + padStart(hex, 4, '0');
32};
33
34// Avoiding the use of polyfills of the previous iteration of this proposal
35var FORCED = !$escape || $escape('ab') !== '\\x61b';
36
37// `RegExp.escape` method
38// https://github.com/tc39/proposal-regex-escaping
39$({ target: 'RegExp', stat: true, forced: FORCED }, {
40 escape: function escape(S) {
41 aString(S);
42 var length = S.length;
43 var result = $Array(length);
44
45 for (var i = 0; i < length; i++) {
46 var chr = charAt(S, i);
47 if (i === 0 && exec(FIRST_DIGIT_OR_ASCII, chr)) {
48 result[i] = escapeChar(chr);
49 } else if (hasOwn(ControlEscape, chr)) {
50 result[i] = '\\' + ControlEscape[chr];
51 } else if (exec(SYNTAX_SOLIDUS, chr)) {
52 result[i] = '\\' + chr;
53 } else if (exec(OTHER_PUNCTUATORS_AND_WHITESPACES, chr)) {
54 result[i] = escapeChar(chr);
55 } else {
56 var charCode = charCodeAt(chr, 0);
57 // single UTF-16 code unit
58 if ((charCode & 0xF800) !== 0xD800) result[i] = chr;
59 // unpaired surrogate
60 else if (charCode >= 0xDC00 || i + 1 >= length || (charCodeAt(S, i + 1) & 0xFC00) !== 0xDC00) result[i] = escapeChar(chr);
61 // surrogate pair
62 else {
63 result[i] = chr;
64 result[++i] = charAt(S, i);
65 }
66 }
67 }
68
69 return join(result, '');
70 }
71});
Note: See TracBrowser for help on using the repository browser.