1'use strict' 2var path = require('path') 3var isWindows = require('./is-windows.js') 4 5/* 6Escape the name of an executable suitable for passing to the system shell. 7 8Windows is easy, wrap in double quotes and you're done, as there's no 9facility to create files with quotes in their names. 10 11Unix-likes are a little more complicated, wrap in single quotes and escape 12any single quotes in the filename. 13*/ 14 15module.exports = escapify 16 17function windowsQuotes (str) { 18 if (!/ /.test(str)) return str 19 return '"' + str + '"' 20} 21 22function escapify (str) { 23 if (isWindows) { 24 return path.normalize(str).split(/\\/).map(windowsQuotes).join('\\') 25 } else if (/[^-_.~/\w]/.test(str)) { 26 return "'" + str.replace(/'/g, "'\"'\"'") + "'" 27 } else { 28 return str 29 } 30} 31