Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
code === null ? '' : String.fromCharCode(
ignoreCase && boolean.random(prng) ? changeCase(code) : code);
const expandCharacter = ({value}) => DRange(value);
const expandRange = ({from, to}) => DRange(from, to);
const expandSet = (token, range) => {
let drange = DRange();
let setRanges = token.set.map((code) => expand(code, range));
setRanges.forEach((setRange) => drange.add(setRange));
return token.not ? range.clone().subtract(drange) : drange;
};
const expanders = {
[ret.types.SET]: expandSet,
[ret.types.RANGE]: expandRange,
[ret.types.CHAR]: expandCharacter
};
const expand = (token, ...args) => expanders[token.type](token, ...args);
// These generators accept a token and the options object and return a character
// code.
const generateCharFromSet = (token, {range, prng}) => {
const set = expand(token, range);
return set.index(integer.boundedRandom(0, set.length - 1, prng));
};
const generateCharFromRange = ({from, to}, {prng}) =>
integer.boundedRandom(from, to, prng);
ignoreCase && boolean.random(prng) ? changeCase(code) : code);
const expandCharacter = ({value}) => DRange(value);
const expandRange = ({from, to}) => DRange(from, to);
const expandSet = (token, range) => {
let drange = DRange();
let setRanges = token.set.map((code) => expand(code, range));
setRanges.forEach((setRange) => drange.add(setRange));
return token.not ? range.clone().subtract(drange) : drange;
};
const expanders = {
[ret.types.SET]: expandSet,
[ret.types.RANGE]: expandRange,
[ret.types.CHAR]: expandCharacter
};
const expand = (token, ...args) => expanders[token.type](token, ...args);
// These generators accept a token and the options object and return a character
// code.
const generateCharFromSet = (token, {range, prng}) => {
const set = expand(token, range);
return set.index(integer.boundedRandom(0, set.length - 1, prng));
};
const generateCharFromRange = ({from, to}, {prng}) =>
integer.boundedRandom(from, to, prng);
const generateFromToken = (token, groups, options) => {
const result = generators[token.type](token, groups, options);
if (token.type === ret.types.GROUP && token.remember) {
groups.push(result);
}
return result;
};
_expand(token) {
if (token.type === ret.types.CHAR) {
return new DRange(token.value);
} else if (token.type === ret.types.RANGE) {
return new DRange(token.from, token.to);
} else {
let drange = new DRange();
for (let i = 0; i < token.set.length; i++) {
let subrange = this._expand(token.set[i]);
drange.add(subrange);
if (this.ignoreCase) {
for (let j = 0; j < subrange.length; j++) {
let code = subrange.index(j);
let otherCaseCode = this._toOtherCase(code);
if (code !== otherCaseCode) {
drange.add(otherCaseCode);
}
}
_expand(token) {
if (token.type === ret.types.CHAR) {
return new DRange(token.value);
} else if (token.type === ret.types.RANGE) {
return new DRange(token.from, token.to);
} else {
let drange = new DRange();
for (let i = 0; i < token.set.length; i++) {
let subrange = this._expand(token.set[i]);
drange.add(subrange);
if (this.ignoreCase) {
for (let j = 0; j < subrange.length; j++) {
let code = subrange.index(j);
let otherCaseCode = this._toOtherCase(code);
if (code !== otherCaseCode) {
drange.add(otherCaseCode);
}
}
}
}
_regexp= function (field,val)
{
var tks= ret(val.source),
_chars= function (start)
{
return _.collect(tks.stack.slice(start),
function (tk) { return String.fromCharCode(tk.value); })
.join('');
};
if (tks.stack
&&tks.stack[0]
&&tks.stack[0].type==ret.types.POSITION
&&tks.stack[0].value=='^'
&&!_.filter(tks.stack.slice(1),function (tk) { return tk.type!=ret.types.CHAR; }).length)
{
var val= _chars(1);
if (val!='')
_field(field,val,'BEGINS_WITH');
}
else
if (tks.stack
&&!_.filter(tks.stack,function (tk) { return tk.type!=ret.types.CHAR; }).length)
{
var val= _chars(0);
if (val!='')
_field(field,val,'CONTAINS');
}
else
},{}],13:[function(require,module,exports){
const ret = require('ret');
const DRange = require('drange');
const types = ret.types;
module.exports = class RandExp {
/**
* @constructor
* @param {RegExp|String} regexp
* @param {String} m
*/
constructor(regexp, m) {
this._setDefaults(regexp);
if (regexp instanceof RegExp) {
this.ignoreCase = regexp.ignoreCase;
this.multiline = regexp.multiline;
regexp = regexp.source;
} else if (typeof regexp === 'string') {
},{}],10:[function(require,module,exports){
const ret = require('ret');
const DRange = require('drange');
const types = ret.types;
module.exports = class RandExp {
/**
* @constructor
* @param {RegExp|String} regexp
* @param {String} m
*/
constructor(regexp, m) {
this._setDefaults(regexp);
if (regexp instanceof RegExp) {
this.ignoreCase = regexp.ignoreCase;
this.multiline = regexp.multiline;
regexp = regexp.source;
} else if (typeof regexp === 'string') {
&&!_.filter(tks.stack.slice(1),function (tk) { return tk.type!=ret.types.CHAR; }).length)
{
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var parse = require('ret');
var types = parse.types;
module.exports = function (re, opts) {
if (!opts) opts = {};
var replimit = opts.limit === undefined ? 25 : opts.limit;
if (isRegExp(re)) re = re.source;
else if (typeof re !== 'string') re = String(re);
try { re = parse(re) }
catch (err) { return false }
var reps = 0;
return (function walk (node, starHeight) {
if (node.type === types.REPETITION) {
starHeight ++;
reps ++;