• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 escapify (str) {
18  if (isWindows) {
19    return '"' + path.normalize(str) + '"'
20  } else {
21    if (/[^-_.~/\w]/.test(str)) {
22      return "'" + str.replace(/'/g, "'\"'\"'") + "'"
23    } else {
24      return str
25    }
26  }
27}
28