string-replace-async 
Asynchronous String.prototype.replace()
Install
$ npm install --save string-replace-async
Usage
const stringReplaceAsync = require('string-replace-async');
const ghUser = require('gh-user');
function replacer(match, login) {
return ghUser(login).then(user => user.name);
}
stringReplaceAsync('Sup, {dsblv}', /{([^}]*)}/g, replacer)
.then(console.log);
API
The API is basically the same as String.prototype.replace(), except the first argument is a string itself.
stringReplaceAsync(string, expression, replacer)
Invokes replacers
concurrently, returns a promise
that resolves to processed string.
stringReplaceAsync.seq(string, expression, replacer)
Invokes replacers
sequentially, returns a promise
that resolves to processed string.
string
Type: string
Required
A string to be processed.
expression
Type: regexp
, string
Required
An expression to match substrings to replace.
replacer
Type: function
, string
Required
A function
that takes several arguments and returns a promise
. Resolved value will be used as replacement string.
License
MIT © Dmitriy Sobolev