@j-o-r/sh 1.1.16 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/SH.js CHANGED
@@ -99,9 +99,12 @@ const SH = new Proxy(function(pieces, ...args) {
99
99
  let cmd = pieces[0], i = 0;
100
100
  while (i < args.length) {
101
101
  let s;
102
+
102
103
  if (Array.isArray(args[i])) {
103
104
  s = args[i].map(/** @param {string} x */(x) => {
104
- let str = String(x);
105
+ // Trim every element
106
+ let str = String(x).trim();
107
+ str = str.replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t');
105
108
  // If the string contains special characters, wrap in single quotes
106
109
  if (str.match(/[ "'$`(){}[\]]/)) {
107
110
  // Escape single quotes within the string
@@ -110,15 +113,6 @@ const SH = new Proxy(function(pieces, ...args) {
110
113
  return str;
111
114
  }).join(' ');
112
115
  } else {
113
- // let str = String(args[i]);
114
- // if (str.match(/[ "'$`(){}[\]]/)) {
115
- // s = `'${str.replace(/'/g, `'\\''`)}'`;
116
- // } else {
117
- // s = str;
118
- // }
119
- // Leave string UNALTERED
120
- // Should be escaped in the code and is the responsibility of the developer
121
- // SH`do something "${filename}"`;
122
116
  s = String(args[i]);
123
117
  }
124
118
  cmd += s + pieces[++i];
package/lib/SHExecute.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { spawnSync, spawn, exec } from 'node:child_process';
2
- import { nextTick } from 'node:process';
3
2
 
4
3
  /**
5
4
  * Kills a process and all child processes of a given process ID in Linux/Posix.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@j-o-r/sh",
3
3
  "author": "Jorrit Duin <j-o-r@duin.work>",
4
4
  "type": "module",
5
- "version": "1.1.16",
5
+ "version": "1.1.17",
6
6
  "description": "Execute shell commands on Linux-based systems from javascript",
7
7
  "main": "lib/SH.js",
8
8
  "types": "types/SH.d.ts",