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
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.`);