UNPKG

vtils

Version:

一个面向业务的 JavaScript/TypeScript 实用程序库。

25 lines 872 B
export var RegExpBuilder = /*#__PURE__*/function () { function RegExpBuilder(options) { this.options = options; } var _proto = RegExpBuilder.prototype; _proto.getBaseRegExp = function getBaseRegExp() { return new RegExp(this.options.baseRegExp); }; _proto.build = function build(options) { var regExpSource = "(?:" + this.options.baseRegExp.source + ")"; if (options != null && options.repeat) { regExpSource = regExpSource + "+"; } if (options != null && options.exact) { regExpSource = "^" + regExpSource + "$"; } var regExpFlags = this.options.baseRegExp.flags; if (options != null && options.global && this.options.baseRegExp.flags.indexOf('g') === -1) { regExpFlags = regExpFlags + "g"; } var regExp = new RegExp(regExpSource, regExpFlags); return regExp; }; return RegExpBuilder; }();