We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
测试用例: const str = "下周一{{people1}}和{{people2}}去游泳" render(str,{ people1:'小明', people2:'小红' })
The text was updated successfully, but these errors were encountered:
最简单的方法就是 string.replaceAll()了吧
const stringReplace = (template: string, obj: { [k: string]: string }) => { const keys = Object.keys(obj) keys.forEach(k => { template = template.replaceAll(`{{${k}}}`, obj[k]) }) return template }
也可以考虑用template来做
const stringReplace2 = (template: string, obj: { [k: string]: string }) => { return eval('`' + template.replaceAll("{{", "${obj['").replaceAll("}}", "']}") + '`') }
需要考虑的一点就是parameter会不会有一些奇怪的格式和符号, 最基本的应该没问题。 性能上好像是template literal会快一点。
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: