apps-script-utils 2.1.1 Help

merge

function merge(template: string, data: object, options: MergeOptions = {}): string;

Whitespace inside the braces is ignored, so {{name}} and {{ name }} are the same placeholder. A key that the object does not carry is left as it stands, which makes a missing value visible rather than silently blank; onMissing: "empty" removes it instead.

escape takes a function applied to every substituted value — pass escapeHtml when the result goes into a page.

Parameters

Parameter

Type

Description

template

string

The template string with {{ key }} placeholders.

data

object

The object the values come from.

options (optional) = {}

MergeOptions

onMissing is "keep" or "empty"; escape is a function applied to each value.

Returns

string — the template with its placeholders filled.

Throws

Exception

Condition

IllegalArgumentException

the template is not a string, or the data is not an object.

Examples

Filling a template

merge("Hi {{ name }}!", { name: "Ada" }); // => "Hi Ada!" merge("Hi {{ name }}!", {}); // => "Hi {{ name }}!" merge("Hi {{ name }}!", {}, { onMissing: "empty" }); // => "Hi !"

See also

Source

src/lang/string/merge.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.