Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.addRule('Regexp', function(Regexp: ParamsRegexp) {
if(!Regexp) {throw new Error(`the regexp type must has a regexp rule.`); }
const { rule } = Regexp;
if(!regexpRule.test(rule)) {
throw new Error('wrong regexp expression');
}
});
// config rule
var rule = /^\s*([$\w]+)\s*(?:=\s*(?:(['"])((?:(?!\2)[^\\]|\\.)*)\2|(.+))\s*)?$/;
var nativeValues = ['true', 'false', 'null', 'undefined'];
for (var i = 0, j = params.length; i < j; i++) {
var param = params[i];
if (rule.test(param)) {
var key = RegExp.$1, strValue = RegExp.$3, plainValue = RegExp.$4;
if (config.hasOwnProperty(key)) {
throw new Error("the config of \"" + key + "\" has exists,do not define again.");
}
if (strValue) {
config[key] = utils_1.decodeTrans(strValue);
}
else if (plainValue) {
var value = plainValue;
if (value.charAt(0) === '/') {
if (reregexp_1.regexpRule.test(value)) {
config[key] = utils_1.getExp(value);
}
else {
this.halt("wrong regexp:" + value);
}
}
else if (!isNaN(Number(value))) {
config[key] = Number(value);
}
else if (nativeValues.indexOf(value) > -1) {
config[key] = utils_1.getExp(value);
}
else {
this.halt("wrong param:" + param);
}
}
this.addRule('Regexp', function (Regexp) {
if (!Regexp) {
throw new Error("the regexp type must has a regexp rule.");
}
var rule = Regexp.rule;
if (!reregexp_1.regexpRule.test(rule)) {
throw new Error('wrong regexp expression');
}
});
this.addRule('Config', function (Config) {
if(params.length) {
const rule = /^\s*([$\w]+)\s*(?:=\s*(?:(['"])((?:(?!\2)[^\\]|\\.)*)\2|(.+))\s*)?$/;
const nativeValues = ['true', 'false', 'null', 'undefined'];
for(let i = 0, j = params.length; i < j; i++) {
const param = params[i];
if(rule.test(param)) {
const { $1: key, $3: strValue, $4: plainValue } = RegExp;
if(config.hasOwnProperty(key)) {
throw new Error(`the config of "${key}" has exists,do not define again.`);
}
if(strValue) {
config[key] = decodeTrans(strValue);
} else if(plainValue) {
const value = plainValue;
if(value.charAt(0) === '/') {
if(regexpRule.test(value)) {
config[key] = getExp(value);
} else {
this.halt(`wrong regexp:${value}`);
}
} else if(!isNaN(Number(value))) {
config[key] = Number(value);
} else if(nativeValues.indexOf(value) > -1) {
config[key] = getExp(value);
} else {
this.halt(`wrong param:${param}`);
}
} else {
config[key] = true;
}
} else {
this.halt(`the config params of index ${i} "${param}" is wrong,please check it.`);
public generate() {
let { instance } = this;
const { Config, Regexp } = this.params;
if(!instance) {
instance = this.instance = new RegexpParser(Regexp.rule, {
namedGroupConf: Config || {},
});
}
return instance.build();
}
public test() {
ToRegexp.prototype.generate = function () {
var instance = this.instance;
var _a = this.params, Config = _a.Config, Regexp = _a.Regexp;
if (!instance) {
instance = this.instance = new reregexp_1.default(Regexp.rule, {
namedGroupConf: Config || {},
});
}
return instance.build();
};
ToRegexp.prototype.test = function () {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var reregexp_1 = require("reregexp");
var parser = {
config: {
startTag: ['/'],
endTag: [],
rule: reregexp_1.parserRule,
},
parse: function () {
var params = this.info().params;
if (params.length !== 1) {
return this.halt("invalid regexp rule:" + params.join(''));
}
return {
rule: params[0],
};
},
};
exports.default = parser;
//# sourceMappingURL=regexp.js.map