All files / coa/lib shell.js

100% Statements 5/5
100% Branches 4/4
100% Functions 2/2
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 151x     2x       2x       6x 6x    
module.exports = { escape, unescape };
 
function unescape(w) {
    w = w.charAt(0) === '"'
        ? w.replace(/^"|([^\\])"$/g, '$1')
        : w.replace(/\\ /g, ' ');
 
    return w.replace(/\\("|'|\$|`|\\)/g, '$1');
}
 
function escape(w) {
    w = w.replace(/(["'$`\\])/g,'\\$1');
    return w.match(/\s+/) ? `"${w}"` : w;
}