Skip to content

Commit

Permalink
support calling from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaelzer committed Mar 21, 2014
1 parent 4a492ae commit 678411b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

/*
color
*/"use strict"
Expand Down Expand Up @@ -133,4 +135,18 @@ color.matches = function(string){
return !!(string + "").match(regexp)
}

var firstArg = function(fn, context) {
return function() {
var args = Array.prototype.slice.call(arguments);
return fn.call(context, args.length ? args[0] : null);
};
}

// http://nodejs.org/api/modules.html#modules_accessing_the_main_module
if (require.main === module) {
process.argv.slice(2)
.map(firstArg(color))
.forEach(firstArg(console.log, console));
}

module.exports = color

0 comments on commit 678411b

Please sign in to comment.