Skip to content

Function: template() ​

ts
function template(value, data): string;

Replaces {key} placeholders in a string with values from a data object. 使用数据对象中的值替换字符串中的 {key} 占位符。

Parameters ​

ParameterTypeDescription
valuestringThe template string / 模板字符串
dataRecord<string, unknown>The interpolation data / 插值数据

Returns ​

string

The interpolated string / 插值后的字符串

Example ​

ts
template('Hi, {name}', { name: 'Tom' })
// => 'Hi, Tom'

Since ​

1.2.0

Released under the MIT License.