utils.js
776 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* 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;
}