Spaces:
Runtime error
Runtime error
File size: 1,236 Bytes
b5ea024 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PartitionPattern = void 0;
var utils_1 = require("./utils");
/**
* https://tc39.es/ecma402/#sec-partitionpattern
* @param pattern
*/
function PartitionPattern(pattern) {
var result = [];
var beginIndex = pattern.indexOf('{');
var endIndex = 0;
var nextIndex = 0;
var length = pattern.length;
while (beginIndex < pattern.length && beginIndex > -1) {
endIndex = pattern.indexOf('}', beginIndex);
(0, utils_1.invariant)(endIndex > beginIndex, "Invalid pattern ".concat(pattern));
if (beginIndex > nextIndex) {
result.push({
type: 'literal',
value: pattern.substring(nextIndex, beginIndex),
});
}
result.push({
type: pattern.substring(beginIndex + 1, endIndex),
value: undefined,
});
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < length) {
result.push({
type: 'literal',
value: pattern.substring(nextIndex, length),
});
}
return result;
}
exports.PartitionPattern = PartitionPattern;
|