"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/utils/escape-arg.js" (7 Feb 2017, 673 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 var path = require('path')
    3 var isWindowsShell = require('./is-windows-shell.js')
    4 
    5 /*
    6 Escape the name of an executable suitable for passing to the system shell.
    7 
    8 Windows is easy, wrap in double quotes and you're done, as there's no
    9 facility to create files with quotes in their names.
   10 
   11 Unix-likes are a little more complicated, wrap in single quotes and escape
   12 any single quotes in the filename.
   13 */
   14 
   15 module.exports = escapify
   16 
   17 function escapify (str) {
   18   if (isWindowsShell) {
   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 }