template
Interpolates {{key}} placeholders in a template string with values from
a data record. Unknown keys are replaced with an empty string.
No eval or Function constructor is used — substitution is purely
regex-based. Nested expressions and logic are intentionally out of scope.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
str | string | The template string containing {{key}} placeholders. |
data | Record<string, unknown> | A record mapping placeholder names to replacement values. |
Returns
Section titled “Returns”string — The template string with all placeholders replaced.
Examples
Section titled “Examples”Simple interpolation
Section titled “Simple interpolation”Replaces {{key}} placeholders with values from the data object.
Multiple placeholders
Section titled “Multiple placeholders”All matching placeholders are replaced in a single pass.
Missing keys become empty string
Section titled “Missing keys become empty string”Unknown placeholders are replaced with an empty string.
