UNPKG

poe-i18n

Version:

i18n utility for Path of Exile

29 lines (28 loc) 977 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var NamedGroupsRegexp = /** @class */ (function () { function NamedGroupsRegexp(regexp, groups) { this.regexp = regexp; this.groups = groups; } NamedGroupsRegexp.prototype.match = function (text) { var _this = this; var match = text.match(this.regexp); if (match == null) { return null; } // first element is hole string followed by matches if (match.length - 1 !== this.groups.length) { throw new Error('named groups count did not match matched groups count'); } return match.slice(1).reduce(function (named, matched, i) { named[_this.groups[i]] = matched; return named; }, {}); }; NamedGroupsRegexp.prototype.toString = function () { return this.regexp; }; return NamedGroupsRegexp; }()); exports.default = NamedGroupsRegexp;