Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
patison committed Aug 14, 2012
1 parent a73de66 commit 4f97f72
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions index.js
@@ -0,0 +1,29 @@
var argOptions = {},
argParams = [];

var rx = /^-?-(\w+)(?:=(.*))?$/;
var argv = process.argv;

argv.shift();
argv.shift();

argv.forEach(function(item) {
if (matches = item.match(rx)) {
var key = matches[1];
var val = matches[2] ? matches[2] : true;

if (argOptions[key]!=undefined) {
if( !(typeof argOptions[key] == "Array") )
argOptions[key] = [argOptions[key]];

argOptions[key].push(val);
}
else
argOptions[key] = val;
}
else
argParams.push(item);
});

exports.opts = argOptions;
exports.params = argParams;
9 changes: 9 additions & 0 deletions package.json
@@ -0,0 +1,9 @@
{
"name":"named-argv",
"description":"a simple node module that helps passing named arguments",
"keywords": [""],
"version":"0.1.0",
"repository": {"type": "git", "url": "git://github.com/ecdeveloper/node-named-argv"},
"author": "ecdeveloper <ec.developer@gmail.com>",
"main":"./index.js"
}

0 comments on commit 4f97f72

Please sign in to comment.