source: trip-planner-front/node_modules/core-js/internals/get-substitution.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1var toObject = require('../internals/to-object');
2
3var floor = Math.floor;
4var replace = ''.replace;
5var SUBSTITUTION_SYMBOLS = /\$([$&'`]|\d{1,2}|<[^>]*>)/g;
6var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&'`]|\d{1,2})/g;
7
8// `GetSubstitution` abstract operation
9// https://tc39.es/ecma262/#sec-getsubstitution
10module.exports = function (matched, str, position, captures, namedCaptures, replacement) {
11 var tailPos = position + matched.length;
12 var m = captures.length;
13 var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED;
14 if (namedCaptures !== undefined) {
15 namedCaptures = toObject(namedCaptures);
16 symbols = SUBSTITUTION_SYMBOLS;
17 }
18 return replace.call(replacement, symbols, function (match, ch) {
19 var capture;
20 switch (ch.charAt(0)) {
21 case '$': return '$';
22 case '&': return matched;
23 case '`': return str.slice(0, position);
24 case "'": return str.slice(tailPos);
25 case '<':
26 capture = namedCaptures[ch.slice(1, -1)];
27 break;
28 default: // \d\d?
29 var n = +ch;
30 if (n === 0) return match;
31 if (n > m) {
32 var f = floor(n / 10);
33 if (f === 0) return match;
34 if (f <= m) return captures[f - 1] === undefined ? ch.charAt(1) : captures[f - 1] + ch.charAt(1);
35 return match;
36 }
37 capture = captures[n - 1];
38 }
39 return capture === undefined ? '' : capture;
40 });
41};
Note: See TracBrowser for help on using the repository browser.