renderTemplate()function

renderTemplate(template: string, values: TemplateValues, caller: AnyCaller = renderTemplate): string
ParamType
templatestring
The template including template placeholders, e.g. :name-${country}/{city} required
valuesTemplateValues
An object containing values, e.g. { name: "Dave", country: "UK", city: "Manchester" } (functions are called, everything else converted to string), or a function or string to use for all placeholders. required
callerAnyCaller
Function to attribute a thrown error to (defaults to renderTemplate itself). Defaults to renderTemplate
Return
string
The rendered string, e.g. Dave-UK/Manchester
Throws
RequiredError
If a placeholder in the template string is not specified in values.

Turn ":year-:month" and { year: "2016"... } etc into "2016-06..." etc.

Examples

renderTemplate(":name-${country}/{city}", { name: "Dave", country: "UK", city: "Manchester" }) // "Dave-UK/Manchester"