[Pkg-javascript-commits] [node-shell-quote] 98/137: es5 shims
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Aug 25 19:19:43 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 00dc6abfdd2f3ff2908616dbe7b6584bbf1b0e24
Author: James Halliday <mail at substack.net>
Date: Tue Dec 24 12:33:33 2013 -0800
es5 shims
---
index.js | 42 +++++++++++++++++++++++++-----
package.json | 85 ++++++++++++++++++++++++++++++++----------------------------
2 files changed, 81 insertions(+), 46 deletions(-)
diff --git a/index.js b/index.js
index 9f2571b..ae4c8ee 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,7 @@
+var json = typeof JSON !== undefined ? JSON : require('jsonify');
+
exports.quote = function (xs) {
- return xs.map(function (s) {
+ return map(xs, function (s) {
if (s && typeof s === 'object') {
return s.op.replace(/(.)/g, '\\$1');
}
@@ -31,13 +33,13 @@ for (var i = 0; i < 4; i++) {
exports.parse = function (s, env) {
var mapped = parse(s, env);
if (typeof env !== 'function') return mapped;
- return mapped.reduce(function (acc, s) {
+ return reduce(mapped, function (acc, s) {
if (typeof s === 'object') return acc.concat(s);
var xs = s.split(RegExp('(' + TOKEN + '.*?' + TOKEN + ')', 'g'));
if (xs.length === 1) return acc.concat(xs[0]);
- return acc.concat(xs.filter(Boolean).map(function (x) {
+ return acc.concat(map(filter(xs, Boolean), function (x) {
if (RegExp('^' + TOKEN).test(x)) {
- return JSON.parse(x.split(TOKEN)[1]);
+ return json.parse(x.split(TOKEN)[1]);
}
else return x;
}));
@@ -49,11 +51,11 @@ function parse (s, env) {
'(' + CONTROL + ')', // control chars
'(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')*'
].join('|'), 'g');
- var match = s.match(chunker).filter(Boolean);
+ var match = filter(s.match(chunker), Boolean);
if (!match) return [];
if (!env) env = {};
- return match.map(function (s) {
+ return map(match, function (s) {
if (RegExp('^' + CONTROL + '$').test(s)) {
return { op: s };
}
@@ -169,8 +171,34 @@ function parse (s, env) {
if (r === undefined) r = '';
if (typeof r === 'object') {
- return pre + TOKEN + JSON.stringify(r) + TOKEN;
+ return pre + TOKEN + json.stringify(r) + TOKEN;
}
else return pre + r;
}
};
+
+function filter (xs, f) {
+ if (xs.filter) return xs.filter(f);
+ var res = [];
+ for (var i = 0; i < xs.length; i++) {
+ if (f(xs[i], i)) res.push(xs[i]);
+ }
+ return res;
+}
+
+function map (xs, f) {
+ if (xs.map) return xs.map(f);
+ var res = [];
+ for (var i = 0; i < xs.length; i++) {
+ res.push(f(xs[i], i));
+ }
+ return res;
+}
+
+function reduce (xs, f, acc) {
+ if (xs.reduce) return xs.reduce(f, acc);
+ for (var i = 0; i < xs.length; i++) {
+ acc = f(acc, xs[i], i);
+ }
+ return acc;
+}
diff --git a/package.json b/package.json
index b99282f..111da61 100644
--- a/package.json
+++ b/package.json
@@ -1,41 +1,48 @@
{
- "name" : "shell-quote",
- "version" : "1.4.0",
- "description" : "quote and parse shell commands",
- "main" : "index.js",
- "devDependencies" : {
- "tape" : "~2.3.0"
- },
- "scripts" : {
- "test" : "tape test/*.js"
- },
- "repository" : {
- "type" : "git",
- "url" : "http://github.com/substack/node-shell-quote.git"
- },
- "keywords" : [
- "shell",
- "command",
- "quote",
- "parse"
- ],
- "testling": {
- "files": "test/*.js",
- "browsers": [
- "ie/6..latest",
- "firefox/3.5", "firefox/15..latest", "firefox/nightly",
- "chrome/25..latest", "chrome/canary",
- "opera/10..latest", "opera/next",
- "safari/5.1..latest",
- "ipad/6.0..latest",
- "iphone/6.0..latest",
- "android-browser/4.2..latest"
- ]
- },
- "author" : {
- "name" : "James Halliday",
- "email" : "mail at substack.net",
- "url" : "http://substack.net"
- },
- "license" : "MIT"
+ "name": "shell-quote",
+ "version": "1.4.0",
+ "description": "quote and parse shell commands",
+ "main": "index.js",
+ "devDependencies": {
+ "tape": "~2.3.0"
+ },
+ "scripts": {
+ "test": "tape test/*.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/substack/node-shell-quote.git"
+ },
+ "keywords": [
+ "shell",
+ "command",
+ "quote",
+ "parse"
+ ],
+ "testling": {
+ "files": "test/*.js",
+ "browsers": [
+ "ie/6..latest",
+ "firefox/3.5",
+ "firefox/15..latest",
+ "firefox/nightly",
+ "chrome/25..latest",
+ "chrome/canary",
+ "opera/10..latest",
+ "opera/next",
+ "safari/5.1..latest",
+ "ipad/6.0..latest",
+ "iphone/6.0..latest",
+ "android-browser/4.2..latest"
+ ]
+ },
+ "author": {
+ "name": "James Halliday",
+ "email": "mail at substack.net",
+ "url": "http://substack.net"
+ },
+ "license": "MIT",
+ "dependencies": {
+ "jsonify": "0.0.0"
+ }
}
--
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