How to use the randexp.prototype function in randexp

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 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 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 node-muneem / anumargak / src / util.js View on Github external
'use strict';

var RandExp = require('randexp');

RandExp.prototype.randInt = (a, b) => {
    return a;
}

exports.doesMatch = function (a, b) {
    var a_IsRegex = a.indexOf("(") > 0;
    var b_IsRegex = b.indexOf("(") > 0;

    if (a_IsRegex && b_IsRegex) {
        //genetate random string for both regex and pass to the other regex

        var aRegex = new RegExp(a);
        var bRegex = new RegExp(b);

        var aRand = new RandExp(aRegex).gen();
        var bRand = new RandExp(bRegex).gen();

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