node-lib

@wtasnorg/node-lib


@wtasnorg/node-lib / format

Function: format()

format(fmt, obj): string

Defined in: src/format.ts:27

Replace {key} placeholders in fmt with values from obj. Keys that do not exist in obj are replaced with undefined.

Parameters

fmt

string

Format string containing {key} placeholders.

obj

Record<string, unknown>

Object whose property values are substituted.

Returns

string

The formatted string.

Examples

format("Hello, {name}!", { name: "World" });
// "Hello, World!"
format("{a} + {b} = {c}", { a: 1, b: 2, c: 3 });
// "1 + 2 = 3"