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);
exports.preprocess = function(tokens) {
var good = [];
// Traverse tokens in reverse so that tokens in front, which will
// be used to compare `followedBy` and `notFollowedBy` groups,
// are already processed.
for (var i = tokens.length - 1; i >= 0; i--) {
var token = tokens[i];
if (token.type === types.GROUP || token.type === types.ROOT) {
if (token.followedBy || token.notFollowedBy) {
if (token.options) {
token.options = token.options.map(exports.preprocess);
good = [{
type: types.GROUP,
options: token.options.map(function(stack) {
return addTokenList(stack, good, !!token.followedBy);
}),
}];
} else if (token.stack) {
token.stack = exports.preprocess(token.stack);
good = addTokenList(token.stack, good, !!token.followedBy);
}
} else {
good.unshift(exports.preprocessGroup(token));
}
exports.preprocess = function(tokens) {
var good = [];
// Traverse tokens in reverse so that tokens in front, which will
// be used to compare `followedBy` and `notFollowedBy` groups,
// are already processed.
for (var i = tokens.length - 1; i >= 0; i--) {
var token = tokens[i];
if (token.type === types.GROUP || token.type === types.ROOT) {
if (token.followedBy || token.notFollowedBy) {
if (token.options) {
token.options = token.options.map(exports.preprocess);
good = [{
type: types.GROUP,
options: token.options.map(function(stack) {
return addTokenList(stack, good, !!token.followedBy);
}),
}];
} else if (token.stack) {
token.stack = exports.preprocess(token.stack);
good = addTokenList(token.stack, good, !!token.followedBy);
}
} else {
good.unshift(exports.preprocessGroup(token));
}
} else {
good.unshift(token);
}
}
function addTokenList(prevTokens, nextTokens, add) {
console.log('add', prevTokens, nextTokens, add);
var union = [];
var minLength = Math.min(prevTokens.length, nextTokens.length);
for (var i = 0; i < minLength; i++) {
var prevToken = prevTokens[i];
var nextToken = nextTokens[i];
switch (prevToken.type) {
case types.SET:
case types.REPETITION:
case types.REFERENCE:
case types.CHAR:
}
}
return union;
}
function addTokenList(prevTokens, nextTokens, add) {
console.log('add', prevTokens, nextTokens, add);
var union = [];
var minLength = Math.min(prevTokens.length, nextTokens.length);
for (var i = 0; i < minLength; i++) {
var prevToken = prevTokens[i];
var nextToken = nextTokens[i];
switch (prevToken.type) {
case types.SET:
case types.REPETITION:
case types.REFERENCE:
case types.CHAR:
}
}
return union;
}
function addTokenList(prevTokens, nextTokens, add) {
console.log('add', prevTokens, nextTokens, add);
var union = [];
var minLength = Math.min(prevTokens.length, nextTokens.length);
for (var i = 0; i < minLength; i++) {
var prevToken = prevTokens[i];
var nextToken = nextTokens[i];
switch (prevToken.type) {
case types.SET:
case types.REPETITION:
case types.REFERENCE:
case types.CHAR:
}
}
return union;
}
function addTokenList(prevTokens, nextTokens, add) {
console.log('add', prevTokens, nextTokens, add);
var union = [];
var minLength = Math.min(prevTokens.length, nextTokens.length);
for (var i = 0; i < minLength; i++) {
var prevToken = prevTokens[i];
var nextToken = nextTokens[i];
switch (prevToken.type) {
case types.SET:
case types.REPETITION:
case types.REFERENCE:
case types.CHAR:
}
}
return union;
}
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);
}
}