(value = '')
| 3 | * see: http://wiki.bash-hackers.org/syntax/quoting#strong_quoting |
| 4 | */ |
| 5 | export const quote = (value = '') => { |
| 6 | const safe = /^[a-z0-9-_/.@%^=:]+$/i; |
| 7 | |
| 8 | const isShellSafe = safe.test(value); |
| 9 | |
| 10 | if (isShellSafe) { |
| 11 | return value; |
| 12 | } |
| 13 | |
| 14 | // if the value is not shell safe, then quote it |
| 15 | return `'${value.replace(/'/g, "'\\''")}'`; |
| 16 | }; |
| 17 | |
| 18 | export const escape = (value: string) => value.replace(/\r/g, '\\r').replace(/\n/g, '\\n'); |