summaryrefslogtreecommitdiffstats
path: root/lib/utils/string.js
blob: caa23642840ad2bde1c75b02ecd66fc3ec8a3a82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var _ = require("lodash");

function escapeShellArg(arg) {
    var ret = "";

    ret = arg.replace(/"/g, '\\"');

    return "\"" + ret + "\"";
}

function optionsToShellArgs(options) {
    return _.chain(options)
    .map(function(value, key) {
        if (value === null || value === undefined || value === false) return null;
        if (value === true) return key;
        return key+"="+escapeShellArg(value);
    })
    .compact()
    .value()
    .join(" ");
}

module.exports = {
    escapeShellArg: escapeShellArg,
    optionsToShellArgs: optionsToShellArgs,
    toLowerCase: String.prototype.toLowerCase.call.bind(String.prototype.toLowerCase)
};