【文件属性】:
文件名称:string-replace-async:异步String.prototype.replace()
文件大小:63KB
文件格式:ZIP
更新时间:2021-05-02 09:39:50
JavaScript
字符串替换异步
知道如何等待的“ string” .replace()函数
安装
$ npm install string-replace-async
用法
let replaceAsync = require ( "string-replace-async" ) ;
await replaceAsync ( "#rebeccapurple" , / # ( \w + ) / g , async ( match , name ) => {
let color = await getColorByName ( name ) ;
return "#" + color + " (" + name + ")" ;
} ) ;
为什么
假设您有一个用各自的十六进制代码替换颜色名称的任务。
let spec = "I want background to be #papayawhip and
【文件预览】:
string-replace-async-main
----.gitignore(19B)
----package.json(659B)
----readme.md(3KB)
----index.js(869B)
----index.d.ts(847B)
----test.js(7KB)
----yarn.lock(147KB)
----license(1KB)