utils.js 409 B

1234567891011121314151617181920212223
  1. /**
  2. * Escape the given shell `arg`.
  3. *
  4. * @param {String} arg
  5. * @return {String}
  6. * @api public
  7. */
  8. exports.escape = function escape (arg) {
  9. return '"' + String(arg).trim().replace(/"/g, '\\"') + '"';
  10. }
  11. exports.argsToArray = function (args) {
  12. var arr = [];
  13. for (var i = 0; i <= arguments.length; i++) {
  14. if ('undefined' != typeof arguments[i])
  15. arr.push(arguments[i]);
  16. }
  17. return arr;
  18. }