compose-async
Like compose, but functions can return Promises
var composeAsync = require('compose-async');
var deleteFriends = composeAsync(deleteUsersFriends, findUserById);
deleteFriends(3453).then((deletedFriends) => /* ... */);
var composeAsync = require('compose-async');
function reverse(srt) {
return str.split('').reverse().join('');
}
function nl2br(str) {
return str.replace(/\n/g, '<br />');
}
function fetchLinkTitles(str) {
return new Promise(function(resolve, reject) {
resolve(str.replace(
/https?:\/\/\S+/g,
'California man bitten while taking selfie with rattlesnake'
));
});
}
const defaultTextFormatter = composeAsync(nl2br, fetchLinkTitles, reverse);
defaultTextFormatter('hello everyone check this site out https://www.reddit.com/').then(function(formatted) {
console.log(formatted);
});