Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First commit

  • Loading branch information...
commit 4f97f72ba72731f9afdc526252eea7330277070e 1 parent a73de66
patison authored
Showing with 38 additions and 0 deletions.
  1. +29 −0 index.js
  2. +9 −0 package.json
View
29 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;
View
9 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"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.