A very simple system to replace placeholders in a string with values in object.
Sometime we need replace placeholders in translated strings but other alternatives (mustache, handlebars, underscore, etc) are too big for our requirements.
Placeholders delimiters are customizables (default: {}
).
Usage
Options
- context Context with variables to replace in template.
- defaults Default values for context.
- delKeys If
true
, all keys found in template will be removed from context/defaults, depending of which object provide the key (default:false
). - keep Preserve plaholders not replaced (default:
false
). - left Left delimiter (default:
{
). - right Right delimiter (default:
}
). - tpl Template to render.
Examples
// Displaying `Hello Guest, welcome to home` using // differents configurations.const jfTpl = ;// Simpleconsole;// All options used.console;// Param keepconsole; // Hello Guest, welcome toconsole; // Hello Guest, welcome to {site}