Like String.prototype.replace but supports asynchronous replacer.
MIT License
Like String.prototype.replace but supports asynchronous replacer.
yarn add @egoist/async-replace
const replace = require('@egoist/async-replace')
replace('[foo] [bar]', /\[(.*?)\]/g, async (_, p1) => {
await sleep(300)
return `hi ${p1}`
}).then(str => {
console.log(str)
//=> 'hi foo hi bar'
})
string
true
RegExp
true
function
true
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
async-replace © egoist, Released under the MIT License. Authored and maintained by egoist with help from contributors (list).
github.com/egoist · GitHub @egoist · Twitter @_egoistlily