Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tries = tries - 1
if (!generated.has(newline)) {
generated.add(newline)
result.push(newline)
tries = 0
}
} while (tries > 0)
}
} while (!increment(state))
}
}
}
return result.join(os.EOL)
}
export let SubstitutionsEvaluator = new expr.ExpressionEvaluator('substitutions',
expr.FunctionUtils.apply(
args => {
let path = args[0]
let bindings = args[1]
let replications = args.length > 2 ? args[2] : undefined
let seed = args.length > 3 ? args[3] : undefined
return substitutions(path, bindings, replications, seed)
},
(val, expr, pos) => {
let error
switch (pos) {
case 0:
if (typeof val !== 'string') error = `${expr} does not have a path.`
break
case 1:
if (typeof val !== 'object') error = `${expr} does not have bindings.`
},
(val, expr, pos) => {
let error
switch (pos) {
case 0:
if (typeof val !== 'string') error = `${expr} does not have a name string.`
break
case 1:
if (typeof val !== 'string') error = `${expr} does not have a locale string.`
}
return error
}),
expr.ReturnType.String,
e => expr.ExpressionFunctions.validateOrder(e, [expr.ReturnType.String], expr.ReturnType.String))
export let PhrasesEvaluator = new expr.ExpressionEvaluator('phrases',
expr.ExpressionFunctions.apply(
args => {
let name = args[0]
let locale = args.length > 1 ? args[1] : 'en-us'
let min = args.length > 2 ? args[2] : undefined
let max = args.length > 3 ? args[3] : undefined
return Array.from(generatePhrases(name, locale, min, max))
},
(val, expr, pos) => {
let error
switch (pos) {
case 0:
if (typeof val !== 'string') error = `${expr} does not have a name string.`
break
case 1:
if (typeof val !== 'string') error = `${expr} does not have a locale string.`
}
export function* generatePhrases(name?: string, locale?: string, minLen?: number, maxLen?: number): IterableIterator {
if (name) {
let words = generateWords(name, locale)
minLen = minLen || 1
maxLen = maxLen || words.length
for (let len = minLen; len <= maxLen; ++len) {
for (let start = 0; start <= words.length - len; ++start) {
yield words.slice(start, start + len).join(' ')
}
}
}
}
export let PhraseEvaluator = new expr.ExpressionEvaluator('phrase',
expr.ExpressionFunctions.apply(
args => {
let name = args[0]
let locale = args.length > 1 ? args[1] : 'en-us'
return generateWords(name, locale).join(' ')
},
(val, expr, pos) => {
let error
switch (pos) {
case 0:
if (typeof val !== 'string') error = `${expr} does not have a name string.`
break
case 1:
if (typeof val !== 'string') error = `${expr} does not have a locale string.`
}
return error