renderTemplate()function
renderTemplate(template: string, values: TemplateValues, caller: AnyCaller = renderTemplate): string
| Param | Type | |
|---|---|---|
template | string | The template including template placeholders, e.g. :name-${country}/{city} required |
values | TemplateValues | 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 |
caller | AnyCaller | 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"