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.

19 lines
497 B

1 month ago
  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. };