[Pkg-javascript-commits] [node-optimist] 05/33: Imported Upstream version 0.4.0

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Fri Feb 27 23:21:46 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-optimist.

commit 8f2c2a3d0f951f362d61f080fb0e99a1563f552a
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Fri Feb 27 20:00:30 2015 +0100

    Imported Upstream version 0.4.0
---
 index.js        |  7 +++++++
 package.json    |  2 +-
 readme.markdown | 13 +++++++++++++
 test/short.js   | 16 ++++++++++++++++
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index 8ac67eb..f6c6e22 100644
--- a/index.js
+++ b/index.js
@@ -360,6 +360,13 @@ function Argv (args, cwd) {
                 
                 var broken = false;
                 for (var j = 0; j < letters.length; j++) {
+                    var next = arg.slice(j+2);
+                    if (/[A-Za-z]/.test(letters[j])
+                    && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
+                        setArg(letters[j], next);
+                        break;
+                    }
+                    
                     if (letters[j+1] && letters[j+1].match(/\W/)) {
                         setArg(letters[j], arg.slice(j+2));
                         broken = true;
diff --git a/package.json b/package.json
index b908004..0a03509 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name" : "optimist",
-    "version" : "0.3.7",
+    "version" : "0.4.0",
     "description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
     "main" : "./index.js",
     "dependencies" : {
diff --git a/readme.markdown b/readme.markdown
index ad9d3fd..ba3d118 100644
--- a/readme.markdown
+++ b/readme.markdown
@@ -465,6 +465,19 @@ This lets you organize arguments into nested objects.
        '$0': 'node ./examples/reflect.js',
          foo: { bar: { baz: 33 }, quux: 5 } }
 
+short numbers
+-------------
+
+Short numeric `head -n5` style argument work too:
+
+    $ node reflect.js -n123 -m456
+    { '3': true,
+      '6': true,
+      _: [],
+      '$0': 'node ./reflect.js',
+      n: 123,
+      m: 456 }
+
 installation
 ============
 
diff --git a/test/short.js b/test/short.js
new file mode 100644
index 0000000..b2c38ad
--- /dev/null
+++ b/test/short.js
@@ -0,0 +1,16 @@
+var optimist = require('../index');
+var test = require('tap').test;
+
+test('-n123', function (t) {
+    t.plan(1);
+    var parse = optimist.parse([ '-n123' ]);
+    t.equal(parse.n, 123);
+});
+
+test('-123', function (t) {
+    t.plan(3);
+    var parse = optimist.parse([ '-123', '456' ]);
+    t.equal(parse['1'], true);
+    t.equal(parse['2'], true);
+    t.equal(parse['3'], 456);
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/node-optimist.git



More information about the Pkg-javascript-commits mailing list