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.

14 lines
326 B

4 years ago
  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. }