string templating
template strings and output them to a file (use-case: sql queries, ML datasets)
npm i --save string-templating
usage
const output = console // [`1+2=3`, `3+4=7`, `5+6=11`, `7+8=15`, `9+10=19`]
config
amount
: amount of strings to be generatedtemplate
: the string to be templated.${iterators.yourname}
in the string will be replaced with values from your iterators;${returners.yourname}
in the string will be replaced with values from your returnersoutFile
: if you wish for the output to be saved to a file, specify a file path. If your file will have a json extention it will be saved as a json arrayiterators
: object with your iteratorsreturners
: object with your returners. A returner will get all generated values from iterators as an object. Values will be stored as an array (if recycling is ON) or plain value (if recycling is OFF)recycle
: if true, new values will be generated for each replacement in the template (otherwise each template generation gets one value)
helper functions
General purpose helper functions typical for string templating
range
for let i of console/*0123456789*/for let i of console/*78910*/for let i of console/*5811*/
random
// integer in the range of [0, 5) // decimal in the range of [0, 5) // integer in the range of [-3, 4) // decimal in the range of [-3, 4) // returns random element from the array
examples
cd examples
-> npm i
-> node <example_name>
operations
Generates train.txt
and test.txt
. The files contain calculations: {num1}{operand}{num2}={result}
. A very simple example of a dataset generated for a basic machine learning problem.
typescipt
strongly typed returners
Returners get iterator values as an unknown
. There is a helper type ExtractIteratorValues
to help you strongly type the values:
Pass in your iterators and whether you're recycling them.