How to use the reregexp.regexpRule 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 / 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) {

reregexp

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

MIT
Latest version published 1 year ago

Package Health Score

48 / 100
Full package analysis