quote.js 457 B

1234567891011121314151617
  1. 'use strict';
  2. module.exports = function quote(xs) {
  3. return xs.map(function (s) {
  4. if (s && typeof s === 'object') {
  5. return s.op.replace(/(.)/g, '\\$1');
  6. }
  7. if ((/["\s]/).test(s) && !(/'/).test(s)) {
  8. return "'" + s.replace(/(['\\])/g, '\\$1') + "'";
  9. }
  10. if ((/["'\s]/).test(s)) {
  11. return '"' + s.replace(/(["\\$`!])/g, '\\$1') + '"';
  12. }
  13. return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, '$1\\$2');
  14. }).join(' ');
  15. };