1.0.2 • Published 8 years ago
@egoist/async-replace v1.0.2
async-replace
Like String.prototype.replace but supports asynchronous replacer.
Install
yarn add @egoist/async-replaceUsage
const replace = require('@egoist/async-replace')
const newString = replace('[foo] [bar]', /\[(.*?)\]/g, async (_, p1) => {
await sleep(300)
return `hi ${p1}`
})
//=> 'hi foo hi bar'API
replace(str, regexp, replacer)
str
- Type:
string - Required:
true
regexp
- Type:
RegExp - Required:
true
replacer
- Type:
function - Required:
true
Contributing
- 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
Author
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