Type alias Formatter

Formatter: Function<readonly [input: TemplateStringsArray | string, expressions: ReadOnlyArray], string>

Formatter function that takes a string or a tagged template.

Remarks

Type to represent a function that works both directly on a string or as a tagged template function.

Example

const formatter: Formatter = (input, ...expressions) =>
typeof input === "string"
? input
: input
.flatMap((string, index) => [string, expressions[index] ?? ""])
.join("");

formatter("Vangware"); // "Vangware"
formatter`Vangware`; // "Vangware"

See

Tagged templates

Param

Array of strings for template strings or a single string, followed by an array of expressions (if any).

Returns

A plain string.