To escape a shell argument in TypeScript for use with child_process, you can use the shell-escape
package.
First, install the package by running:
index.ts25 chars2 lines
Then, use it in your TypeScript code like this:
index.ts204 chars7 lines
In the example above, the shellEscape
function takes an array of arguments and escapes them for use with the shell. The resulting escapedArg
variable can then be passed to child_process
functions safely.
gistlibby LogSnag