How to use the reregexp.regexpRule.test function in reregexp

To help you get started, we’ve selected a few reregexp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github suchjs / such / src / mockit / regexp.ts View on Github external
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
github suchjs / such / src / parser / config.ts View on Github external
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.`);

reregexp

Generate a random string match a given regular expression, suitable for mocking strings.

MIT
Latest version published 12 months ago

Package Health Score

55 / 100
Full package analysis