[Pkg-javascript-commits] [node-subarg] 05/17: passes the recursive case

Bastien Roucariès rouca at moszumanska.debian.org
Fri Aug 25 19:28:11 UTC 2017


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

rouca pushed a commit to branch master
in repository node-subarg.

commit 0b572d87c9a950053389d4bca99df5ff34ce0dd5
Author: James Halliday <mail at substack.net>
Date:   Sat Feb 8 20:33:09 2014 -0800

    passes the recursive case
---
 index.js | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/index.js b/index.js
index 5bca484..ca2c99d 100644
--- a/index.js
+++ b/index.js
@@ -1,25 +1,35 @@
 var minimist = require('minimist');
 
 module.exports = function parse (args, opts) {
-    var inside = false, index;
+    var level = 0, index;
+    var args_ = [];
+    
     for (var i = 0; i < args.length; i++) {
-        if (/^\[/.test(args[i])) {
-            inside = true;
-            index = i;
+        if (typeof args[i] === 'string' && /^\[/.test(args[i])) {
+            if (level ++ === 0) {
+                index = i;
+            }
         }
-        if (inside && /\]$/.test(args[i])) {
+        if (typeof args[i] === 'string' && /\]$/.test(args[i])) {
+            if (-- level > 0) continue;
+            
             var sub = args.slice(index, i + 1);
-            sub[0] = sub[0].replace(/^\[/, '');
+            if (typeof sub[0] === 'string') {
+                sub[0] = sub[0].replace(/^\[/, '');
+            }
             if (sub[0] === '') sub.shift();
             
-            sub[sub.length-1] = sub[sub.length-1].replace(/\]$/, '');
-            if (sub[sub.length-1] === '') sub.pop();
+            var n = sub.length - 1;
+            if (typeof sub[n] === 'string') {
+                sub[n] = sub[n].replace(/\]$/, '');
+            }
+            if (sub[n] === '') sub.pop();
             
-            args.splice(index, i - 1, parse(sub));
-            inside = false;
+            args_.push(parse(sub));
         }
+        else if (level === 0) args_.push(args[i]);
     }
     
-    var argv = minimist(args, opts);
+    var argv = minimist(args_, opts);
     return argv;
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-subarg.git



More information about the Pkg-javascript-commits mailing list