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'
})
- Type:
string
- Required:
true
- Type:
RegExp
- Required:
true
- Type:
function
- Required:
true
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
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