const seeded = Fiona(1322672)
An easy way to build up a long string is to use a javascript template literal populated from data generated by Fiona.
// input
const data = Fiona(1322672).object({
fullname: Fiona.Fullname(),
age: Fiona.Number({ max: 100 })
}, {
// pass as second argument so values in first argument
// are calculated and can be consumed
playThing: (seeded, value) => value.age < 5 ? 'cuddly toys' : 'friends',
sentences: Fiona.Array({ min: 1, max: 5 }, Fiona.Sentence, '\n\n')
})
const templateFunction = d => `Dear ${d.fullname},
I know you are ${d.age} years old, and like playing with ${d.playThing}.
${d.sentences}
Have a nice day,
Fiona
x x x`
templateFunction(data)
// output
Dear Sir Harry Paterson-Anderson,
I know you are 5 years old, and like playing with friends.
Lorem ipsum eu anim ex ea ad sit incididunt duis laboris id occaecat et exercitation consectetur dolore pariatur sint commodo qui dolor ut do aliqua officia sunt.
Sed ut qui incididunt proident aute commodo in velit laborum dolor quis amet cillum do deserunt eiusmod adipisicing cupidatat elit in nulla ad enim excepteur.
In dolor et labore deserunt ad officia irure ullamco proident culpa aute consectetur eu nisi velit est dolore duis incididunt dolore adipisicing cillum veniam ex.
Deserunt ut amet irure ea nostrud aliqua veniam pariatur excepteur consequat sed mollit voluptate quis sint in consectetur velit exercitation in fugiat labore dolor minim.
Deserunt tempor ullamco duis dolore officia anim commodo id sed excepteur cupidatat aliqua exercitation mollit quis eiusmod sint reprehenderit adipisicing aute voluptate laborum velit ut.
Have a nice day,
Fiona
x x x
To build a custom template plugin, you could use any template language. This example uses a lodash template.
// input
Fiona.register(['template', (seeded, ...data) => (templateArray, ...args) => {
const templateString = templateArray.reduce((a, b) => a + args.shift().toString() + b)
// assuming lodash is loaded, render template with values
return _.template(templateString)(seeded.object(...data))
}])
Fiona(1322672).template({
fullname: seeded => seeded.fullname(),
color: seeded => seeded.oneOf(['red', 'orange', 'yellow', 'green', 'blue'])
})`Hi <%= fullname %>,
Your favourite colour is <%= color %>.
Have a nice day,
Fiona
x x x`
// output
Hi Sir Harry Paterson-Anderson,
Your favourite colour is yellow.
Have a nice day,
Fiona
x x x