Commit a0f88b0

Anton Golub <antongolub@antongolub.com>
2025-06-24 09:45:03
docs: mention `$.delimiter` (#1243)
1 parent 0832d6d
Changed files (4)
build/core.cjs
@@ -391,7 +391,7 @@ var BR_CC = "\n".charCodeAt(0);
 var DLMTR = /\r?\n/;
 var SIGTERM = "SIGTERM";
 var ENV_PREFIX = "ZX_";
-var ENV_ALLOWED = /* @__PURE__ */ new Set([
+var ENV_OPTS = /* @__PURE__ */ new Set([
   "cwd",
   "preferLocal",
   "detached",
@@ -1044,7 +1044,7 @@ var promisifyStream = (stream, from) => (0, import_util.proxyOverride)(stream, {
     return piped instanceof ProcessPromise ? piped : promisifyStream(piped, from);
   }
 });
-function resolveDefaults(defs = defaults, prefix = ENV_PREFIX, env = import_node_process2.default.env, allowed = ENV_ALLOWED) {
+function resolveDefaults(defs = defaults, prefix = ENV_PREFIX, env = import_node_process2.default.env, allowed = ENV_OPTS) {
   return Object.entries(env).reduce((m, [k, v]) => {
     if (v && k.startsWith(prefix)) {
       const _k = (0, import_util.toCamelCase)(k.slice(prefix.length));
docs/api.md
@@ -111,6 +111,7 @@ interface Options {
   kill:           typeof kill
   killSignal:     NodeJS.Signals
   halt:           boolean
+  delimiter:      string | RegExp
 }
 ```
 See also [Configuration](./configuration).
docs/configuration.md
@@ -128,9 +128,19 @@ $.timeoutSignal= 'SIGKILL'
 await $`sleep 999`
 ```
 
+## `$.delimiter`
+Specifies a delimiter for splitting command output into lines.
+Defaults to `\r?\n` (newline or carriage return + newline).
+
+```js
+$.delimiter = /\0/        // null character
+
+await $`find ./ -type f -print0 -maxdepth 1`
+```
+
 ## `$.defaults`
 
-Holds the default configuration values. They will be used if the corresponding
+Holds default configuration values. They will be used if the corresponding
 `$` options are not specified.
 
 ```ts
@@ -151,6 +161,7 @@ $.defaults = {
   spawnSync:      childProcess.spawnSync,
   log:            $.log,
   killSignal:     'SIGTERM',
-  timeoutSignal:  'SIGTERM'
+  timeoutSignal:  'SIGTERM',
+  delimiter:      /\r?\n/,
 }
 ```
src/core.ts
@@ -78,7 +78,7 @@ const BR_CC = '\n'.charCodeAt(0)
 const DLMTR = /\r?\n/
 const SIGTERM = 'SIGTERM'
 const ENV_PREFIX = 'ZX_'
-const ENV_ALLOWED: Set<string> = new Set([
+const ENV_OPTS: Set<string> = new Set([
   'cwd',
   'preferLocal',
   'detached',
@@ -971,7 +971,7 @@ export function resolveDefaults(
   defs: Options = defaults,
   prefix: string = ENV_PREFIX,
   env = process.env,
-  allowed = ENV_ALLOWED
+  allowed = ENV_OPTS
 ): Options {
   return Object.entries(env).reduce<Options>((m, [k, v]) => {
     if (v && k.startsWith(prefix)) {