[Pkg-javascript-commits] [node-shell-quote] 24/137: externalize the regex declaration

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


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

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

commit 37d60580a4a4656ff836c4a2ecdd7282705ffd27
Author: James Halliday <mail at substack.net>
Date:   Sun Apr 14 20:36:59 2013 -0700

    externalize the regex declaration
---
 index.js | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/index.js b/index.js
index b6c9e3a..f87d77f 100644
--- a/index.js
+++ b/index.js
@@ -12,22 +12,24 @@ exports.quote = function (xs) {
     }).join(' ');
 };
 
+var re = {
+    chunk: /(['"])((\\\1|[^\1])*?)\1|(\\ |\S)+/g
+};
+
 exports.parse = function (s, env) {
     if (!env) env = {};
-    return s.match(/(['"])((\\\1|[^\1])*?)\1|(\\ |\S)+/g)
-        .map(function (s) {
-            if (/^'/.test(s)) {
-                return s
-                    .replace(/^'|'$/g, '')
-                    .replace(/\\(["'\\$`(){}!#&*|])/g, '$1')
-                ;
-            }
-            else if (/^"/.test(s)) {
-                return interpolate(s.replace(/^"|"$/g, ''));
-            }
-            else return interpolate(s);
-        })
-    ;
+    return s.match(re.chunk).map(function (s) {
+        if (/^'/.test(s)) {
+            return s
+                .replace(/^'|'$/g, '')
+                .replace(/\\(["'\\$`(){}!#&*|])/g, '$1')
+            ;
+        }
+        else if (/^"/.test(s)) {
+            return interpolate(s.replace(/^"|"$/g, ''));
+        }
+        else return interpolate(s);
+    });
     
     function interpolate (s) {
         return s

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



More information about the Pkg-javascript-commits mailing list