模板解析
2020-10-09 本文已影响0人
六寸光阴丶
模板解析函数
const render = (str = "") => (obj = {}) => str.replace(/\$\{(\w+)\}/g, (_, key) => obj[key])
测试
const str = render('${year}-${month}-${day}')({
year: '2020',
month: '09',
day: '23'
})
console.log(str)
测试结果
2020-09-23