shell.js 326 B

1234567891011121314
  1. module.exports = { escape, unescape };
  2. function unescape(w) {
  3. w = w.charAt(0) === '"'
  4. ? w.replace(/^"|([^\\])"$/g, '$1')
  5. : w.replace(/\\ /g, ' ');
  6. return w.replace(/\\("|'|\$|`|\\)/g, '$1');
  7. }
  8. function escape(w) {
  9. w = w.replace(/(["'$`\\])/g,'\\$1');
  10. return w.match(/\s+/) ? `"${w}"` : w;
  11. }