Created
March 23, 2011 15:22
-
-
Save bengl/883274 to your computer and use it in GitHub Desktop.
Because I got tired of var module = require('module');
This file contains 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
//using.js | |
var importThem = function(libs){ | |
for (var i = 0; i < libs.length; i++) { | |
global[libs[i]] = require(libs[i]); | |
} | |
}; | |
module.exports = function(){ | |
if (arguments.length == 1 | |
&& arguments[0].constructor.toString().indexOf("Array") != -1) | |
importThem(arguments[0]); | |
else | |
importThem(arguments); | |
}; | |
// and then in your app.js: | |
require('using')('util','fs'); | |
// or | |
require('using')(['util','fs']); | |
// would be equivalent to: | |
util = require('util'); | |
fs = require('fs'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this make me a bad person?