Last active
August 29, 2015 14:05
-
-
Save rektide/df9a00423783f8f4d356 to your computer and use it in GitHub Desktop.
liftNodeModule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
var node = require('when/node'); | |
function liftNodeModule(o){ | |
return _.chain(o) | |
.pairs() // break into [key,value] | |
.filter(function(fn, slot){ // remove '*Sync' methods | |
var key = slot[0]; | |
var firstLetter = key.charAt(0); | |
return ! (/Sync$/.test(key) || firstChar.toUpperCase() == firstChar); | |
}) | |
.reduce(function(o, slot){ // lift each method | |
var key = slot[0]; | |
var fn = slot[1]; | |
o[key] = node.lift(fn); | |
return o; | |
}, {}) | |
.value(); | |
} | |
module.exports = { | |
fs: liftNodeModule(require('fs')) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment