How to use reregexp - 7 common examples

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

reregexp

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

MIT
Latest version published 11 months ago

Package Health Score

58 / 100
Full package analysis