mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 07:35:16 +00:00
33 lines
766 B
JavaScript
33 lines
766 B
JavaScript
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 === false) return null;
|
|
if (value === true) return key;
|
|
return key+"="+escapeShellArg(value);
|
|
})
|
|
.compact()
|
|
.value()
|
|
.join(" ");
|
|
}
|
|
|
|
function escapeRegex(str) {
|
|
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
}
|
|
|
|
module.exports = {
|
|
escapeRegex: escapeRegex,
|
|
escapeShellArg: escapeShellArg,
|
|
optionsToShellArgs: optionsToShellArgs,
|
|
toLowerCase: String.prototype.toLowerCase.call.bind(String.prototype.toLowerCase)
|
|
};
|