Sha256: 987b4021423d32c676cbc3cd37498f7c23e039a124dbcd05f5a92e5021720d96

Contents?: true

Size: 1009 Bytes

Versions: 4

Compression:

Stored size: 1009 Bytes

Contents

exports.quote = function (xs) {
    return xs.map(function (s) {
        if (/["\s]/.test(s) && !/'/.test(s)) {
            return "'" + s.replace(/(['\\])/g, '\\$1') + "'";
        }
        else if (/["'\s]/.test(s)) {
            return '"' + s.replace(/(["\\$`(){}!#&*|])/g, '\\$1') + '"';
        }
        else {
            return s.replace(/([\\$`(){}!#&*|])/g, '\\$1');
        }
    }).join(' ');
};

exports.parse = function (s) {
    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 s
                    .replace(/^"|"$/g, '')
                    .replace(/\\(["'\\$`(){}!#&*|])/g, '$1');
                ;
            }
            else return s.replace(/\\([ "'\\$`(){}!#&*|])/g, '$1');
        })
    ;
};

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
sprockets-browserify-0.3.0 node_modules/browserify/node_modules/shell-quote/index.js
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/shell-quote/index.js
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/shell-quote/index.js
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/shell-quote/index.js