generate() expands each template by crossing every {{name}} slot against the matching lexicon list, returns the unique rows, and throws when a placeholder is invalid, a used slot has no values, or the expansion would exceed 1,000,000 rows.
Deno:
deno add npm:@neabyte/dataset-generatornpm:
npm install @neabyte/dataset-generatorCDN (jsDelivr/esm.sh):
<script type="module">
import Dataset from 'https://cdn.jsdelivr.net/npm/@neabyte/dataset-generator/dist/index.mjs'
</script>Or via esm.sh:
<script type="module">
import Dataset from 'https://esm.sh/@neabyte/dataset-generator'
</script>import Dataset from '@neabyte/dataset-generator'
// Shared slot values for every template
const parameters = {
name: ['Alice', 'Bob', 'Charlie', 'Support Lead'],
action: ['restart the server', 'verify your account', 'clear cache']
}
// Templates that share those slot names
const templates = [
'Hello {{name}}, I will {{action}} now.',
'Could you please hold on {{name}} while I {{action}}?'
]
// Cross every slot value into unique rows
const dataset = Dataset.generate(templates, parameters)
// [
// 'Hello Alice, I will restart the server now.',
// 'Hello Alice, I will verify your account now.',
// 'Hello Alice, I will clear cache now.',
// 'Hello Bob, I will restart the server now.',
// ...
// ]A slot name must match [A-Za-z_][A-Za-z0-9_]*, and whitespace inside {{ }} is allowed. The same name can appear more than once in one template and is filled with the same value, while a template with no slots is returned as-is. Missing slots, empty value lists, and malformed placeholders throw.
Dataset.generate(pattern, lexicon)pattern<readonly string[]>: Template strings with{{name}}slots.lexicon<Readonly<Record<string, readonly string[]>>>: Named string lists used to fill those slots.- Returns:
<string[]>
Throws:
TypeErrorwhenpatternis not an array, an entry is not a string,lexiconis not a plain object, or a value list contains a non-string.SyntaxErrorwhen a{{opener is not a valid{{name}}placeholder.RangeErrorwhen a used placeholder has no values, or the expansion would exceed 1,000,000 rows.
npm run builddeno task checkThis project is licensed under the MIT license. See the LICENSE file for details.