quote.js 497 B

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