Skip to content

template

使用搜索表达式,通过数据对象中的值对字符串进行模板替换

155 bytes
since v12.1.0

用法说明

给定一个字符串、一个数据对象以及用于搜索的格式表达式,返回一个新字符串,其中所有匹配搜索的元素都会被数据对象中对应的值替换。

import * as _ from 'radashi'
_.template('It is {{color}}', { color: 'blue' }) // => 它是蓝色的
_.template('It is <color>', { color: 'blue' }, /<(.+?)>/g) // => 它是蓝色的