2024-08-15 09:22:33 +08:00
|
|
|
import escapeSpace from "escape-path-with-spaces"
|
|
|
|
import escapeQuote from "escape-quotes"
|
|
|
|
|
2024-08-16 17:37:02 +08:00
|
|
|
/**
|
|
|
|
* Escape a string for use in a shell command
|
|
|
|
* @param valGiven The string to escape
|
|
|
|
* @param shouldEscapeSpace Whether to escape spaces in the string
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
2024-08-15 09:22:33 +08:00
|
|
|
export function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
|
|
|
|
const spaceEscaped = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
|
|
|
|
return escapeQuote(spaceEscaped, "\"", "\\")
|
|
|
|
}
|