How to use randexp - 10 common examples

To help you get started, we’ve selected a few randexp 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 asvae / laravel-api-tester / resources / assets / js / components / edit-block / edit-block.vue View on Github external
getRequestInfo () {
                let request = this.prepareRequest(this.request)

                // If we won't stick the following header laravel will
                // process the request as usual and won't give any info.
                request.headers.push({key: 'X-Api-Tester', value: 'route-info'})

                // Modifies path if wheres are declared in request.
                // Otherwise, we'll send to unmodified path.

                let path = request.url
                if (request.wheres) {
                    let wheres = request.wheres
                    for (let index in wheres) {
                        let mocker = new RandExp(new RegExp(wheres[index]))
                        let dummy = new RegExp('{' + index + '}', 'g')

                        path = path.replace(dummy, mocker.gen())
                    }
                }

                // Do sending.
                this.$api.ajax(request.method, path, request.data, request.headers)
                    .then((response) => {
                        this.setRequestInfo(response.data)
                        this.setInfoError(false)
                    })
                    .catch(xhr => this.setInfoError(xhr.status))
            },
            send (request){
github YMFE / yapi / common / json-schema-mockjs.js View on Github external
*
 * @param nameOrOptionMap
 * @returns {any}
 */
function optionAPI(nameOrOptionMap) {
  if (typeof nameOrOptionMap === 'string') {
    return registry$1.get(nameOrOptionMap);
  }
  else {
    return registry$1.registerMany(nameOrOptionMap);
  }
}

var RandExp = require('randexp');
// set maximum default, see #193
RandExp.prototype.max = 10;
// same implementation as the original except using our random
RandExp.prototype.randInt = function (a, b) {
  return a + Math.floor(optionAPI('random')() * (1 + b - a));
};
function _randexp(value) {
  var re = new RandExp(value);
  // apply given setting
  re.max = optionAPI('defaultRandExpMax');
  return re.gen();
}
function getSubAttribute(obj, dotSeparatedKey) {
  var keyElements = dotSeparatedKey.split('.');
  while (keyElements.length) {
    var prop = keyElements.shift();
    if (!obj[prop]) {
      break;
github YMFE / yapi / common / json-schema-mockjs.js View on Github external
* @returns {any}
 */
function optionAPI(nameOrOptionMap) {
  if (typeof nameOrOptionMap === 'string') {
    return registry$1.get(nameOrOptionMap);
  }
  else {
    return registry$1.registerMany(nameOrOptionMap);
  }
}

var RandExp = require('randexp');
// set maximum default, see #193
RandExp.prototype.max = 10;
// same implementation as the original except using our random
RandExp.prototype.randInt = function (a, b) {
  return a + Math.floor(optionAPI('random')() * (1 + b - a));
};
function _randexp(value) {
  var re = new RandExp(value);
  // apply given setting
  re.max = optionAPI('defaultRandExpMax');
  return re.gen();
}
function getSubAttribute(obj, dotSeparatedKey) {
  var keyElements = dotSeparatedKey.split('.');
  while (keyElements.length) {
    var prop = keyElements.shift();
    if (!obj[prop]) {
      break;
    }
    obj = obj[prop];
github husainshabbir / form-filler / app / scripts.babel / form-filler / data-generator.js View on Github external
case 'name':
        if (this.previousFirstName.length > 0) {
          username = this.sanitizeName(this.previousFirstName);
        }
        if (this.previousLastName.length > 0) {
          if (username.length > 0) {
            username += `.${this.sanitizeName(this.previousLastName)}`;
          } else {
            username = this.sanitizeName(this.previousLastName);
          }
        }
        break;

      case 'regex':
        try {
          username = new RandExp(emailSettings.usernameRegEx).gen();
        } catch (ex) {
          // Do nothing.
        }
        break;

      default:
        break;
    }

    if (!username || username.length === 0) {
      username = this.generateScrambledWord(4, 10).toLowerCase();
    }

    let domain = '';

    if (emailSettings.hostname === 'list') {
github json-schema-faker / json-schema-faker / lib / class / Container.js View on Github external
"use strict";
var RandExp = require("randexp");
var option = require("../api/option");
// set maximum default, see #193
RandExp.prototype.max = 10;
/**
 * Container is used to wrap external libraries (faker, chance, casual, randexp) that are used among the whole codebase. These
 * libraries might be configured, customized, etc. and each internal JSF module needs to access those instances instead
 * of pure npm module instances. This class supports consistent access to these instances.
 */
var Container = (function () {
    function Container() {
        // static requires - handle both initial dependency load (deps will be available
        // among other modules) as well as they will be included by browserify AST
        this.registry = {
            faker: null,
            chance: null,
            casual: null,
            // randexp is required for "pattern" values
            randexp: RandExp
        };
github johndatserakis / koa-vue-notes-api / src / controllers / UserActionController.js View on Github external
)
            if (!correct) {
                ctx.throw(400, 'INVALID_CREDENTIALS')
            }
        } catch (error) {
            console.log('here', error)
            ctx.throw(400, 'INVALID_DATA')
        }

        //Let's get rid of that password now for security reasons
        delete userData.password

        //Generate the refreshToken data
        let refreshTokenData = {
            username: userData.username,
            refreshToken: new rand(/[a-zA-Z0-9_-]{64,64}/).gen(),
            info:
                ctx.userAgent.os +
                ' ' +
                ctx.userAgent.platform +
                ' ' +
                ctx.userAgent.browser,
            ipAddress: ctx.request.ip,
            expiration: dateAddMonths(new Date(), 1),
            isValid: true,
        }

        //Insert the refresh data into the db
        try {
            await db('refresh_tokens').insert(refreshTokenData)
        } catch (error) {
            ctx.throw(400, 'INVALID_DATA')
github FrediBach / Blowson / src / helpers.js View on Github external
data[type][row][field] = value.replace(/{{\s*([^\}]+)\s*}}/g, function (match, capture) {
                        let randomPart = _.sample(capture.split('||')),
                            defaultParts = randomPart.split('?'),
                            filterParts = defaultParts[0].split('|'),
                            parts = filterParts[0].split('.');

                        if (randomPart[0] === '/' && randomPart.endsWith('/')) {
                            return RandExp.randexp(randomPart.slice(1, -1).replace(/❵/g, '}'));
                        } else if (parts[0] === 'number' && parts.length === 1) {
                            return Math.floor(Math.random() * 10);
                        } else if (parts[0] === 'sentence' && parts.length === 1) {
                            return sentence();
                        } else if (parts[0] === 'paragraph' && parts.length === 1) {
                            return paragraph();
                        } else if (parts[0] === 'word' && parts.length === 2) {
                            if (typeof generator[parts[1]] !== 'undefined') {
                                if (filterParts.length > 1) {
                                    return applyFilters(generator[parts[1]](), filterParts);
                                } else {
                                    return generator[parts[1]]();
                                }
                            }
                        } else if (parts[0] === 'fake' && parts.length === 2) {
                            if (typeof chance[parts[1]] === 'function') {
github FrediBach / Blowson / dist / blowson.esm.js View on Github external
data[type][row][field] = value.replace(/{{\s*([^\}]+)\s*}}/g, function (match, capture) {
                        let randomPart = _.sample(capture.split('||')),
                            defaultParts = randomPart.split('?'),
                            filterParts = defaultParts[0].split('|'),
                            parts = filterParts[0].split('.');

                        if (randomPart[0] === '/' && randomPart.endsWith('/')) {
                            return RandExp.randexp(randomPart.slice(1, -1).replace(/❵/g, '}'));
                        } else if (parts[0] === 'number' && parts.length === 1) {
                            return Math.floor(Math.random() * 10);
                        } else if (parts[0] === 'sentence' && parts.length === 1) {
                            return sentence();
                        } else if (parts[0] === 'paragraph' && parts.length === 1) {
                            return paragraph();
                        } else if (parts[0] === 'word' && parts.length === 2) {
                            if (typeof generator[parts[1]] !== 'undefined') {
                                if (filterParts.length > 1) {
                                    return applyFilters(generator[parts[1]](), filterParts);
                                } else {
                                    return generator[parts[1]]();
                                }
                            }
                        } else if (parts[0] === 'fake' && parts.length === 2) {
                            if (typeof chance[parts[1]] === 'function') {
github hychen / ke-e / src / combinators.js View on Github external
return function(engine) {
        const regexp = new RegExp(s);
        const randexp = new RandExp(regexp);
        randexp.randInt = (from, to) => {
          return Random.integer(from, to)(engine);
        };
        return randexp.gen();
      }
    },
github johndatserakis / koa-vue-notes-api / src / controllers / UserActionController.js View on Github external
async generateUniqueToken() {
        let token = new rand(/[a-zA-Z0-9_-]{7,7}/).gen()

        if (await this.checkUniqueToken(token)) {
            await this.generateUniqueToken()
        } else {
            return token
        }
    }

randexp

Create random strings that match a given regular expression.

MIT
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis

Popular randexp functions