@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
| Parameter | Type | Description |
|---|---|---|
text | string | The text to replace placeholders in. |
values | Record<string, any> | The values to replace placeholders with. |
Returns
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'],
// }