UNPKG

poe-i18n

Version:

i18n utility for Path of Exile

27 lines (26 loc) 897 B
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; }()); export default NamedGroupsRegexp;