mirror of https://gitgud.io/fatchan/gm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
52 lines
1.0 KiB
var stream = require('stream');
|
|
|
|
/**
|
|
* Escape the given shell `arg`.
|
|
*
|
|
* @param {String} arg
|
|
* @return {String}
|
|
* @api public
|
|
*/
|
|
|
|
exports.escape = function escape (arg) {
|
|
return '"' + String(arg).trim().replace(/"/g, '\\"') + '"';
|
|
};
|
|
|
|
exports.unescape = function escape (arg) {
|
|
return String(arg).trim().replace(/"/g, "");
|
|
};
|
|
|
|
exports.argsToArray = function (args) {
|
|
var arr = [];
|
|
|
|
for (var i = 0; i <= arguments.length; i++) {
|
|
if ('undefined' != typeof arguments[i])
|
|
arr.push(arguments[i]);
|
|
}
|
|
|
|
return arr;
|
|
};
|
|
|
|
exports.isUtil = function (v) {
|
|
var ty = 'object';
|
|
switch (Object.prototype.toString.call(v)) {
|
|
case '[object String]':
|
|
ty = 'String';
|
|
break;
|
|
case '[object Array]':
|
|
ty = 'Array';
|
|
break;
|
|
case '[object Boolean]':
|
|
ty = 'Boolean';
|
|
break;
|
|
}
|
|
return ty;
|
|
}
|
|
|
|
var isStream = exports.isStream = function isStream(obj) {
|
|
return obj instanceof stream.Stream;
|
|
}
|
|
|
|
exports.isReadableStream = function isReadableStream(obj) {
|
|
return isStream(obj) && typeof obj._read == 'function' && typeof obj._readableState == 'object';
|
|
} |