Skip to content

@gettoor/core v0.1.0


@gettoor/core / replacePlaceholders

Function: replacePlaceholders()

replacePlaceholders(text: string, values: Record<string, any>): ReplacePlaceholderOutput

Replaces placeholders in a string with values. The placeholders are of the form <key> in the string.

Parameters

ParameterTypeDescription
textstringThe text to replace placeholders in.
valuesRecord<string, any>The values to replace placeholders with.

Returns

ReplacePlaceholderOutput

The string with placeholders replaced with values.

Example

ts
const text = 'Hello <<name>>!';
const values = { name: 'John', age: '27' };
const output = replacePlaceholders(text, values);
// The output will be:
// {
//   text: 'Hello John!',
//   unusedValueKeys: ['age'],
// }