@gjsify/util 0.3.13 → 0.3.14

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/esm/index.js CHANGED
@@ -1,624 +1,589 @@
1
- import * as types from "./types.js";
2
- import { getSystemErrorName, getSystemErrorMap } from "./errors.js";
3
- const kCustomInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
1
+ import { getSystemErrorMap, getSystemErrorName } from "./errors.js";
2
+ import { types_exports } from "./types.js";
3
+
4
+ //#region src/index.ts
5
+ const kCustomInspect = Symbol.for("nodejs.util.inspect.custom");
4
6
  function inspectValue(value, opts, depth) {
5
- if (value === null) return opts.colors ? "\x1B[1mnull\x1B[22m" : "null";
6
- if (value === void 0) return opts.colors ? "\x1B[90mundefined\x1B[39m" : "undefined";
7
- const maxDepth = opts.depth ?? 2;
8
- if (typeof value === "string") {
9
- const escaped = value.replace(/\\/g, "\\\\");
10
- if (value.includes("'") && !value.includes('"')) {
11
- const dq = escaped.replace(/"/g, '\\"');
12
- return opts.colors ? `\x1B[32m"${dq}"\x1B[39m` : `"${dq}"`;
13
- }
14
- const sq = escaped.replace(/'/g, "\\'");
15
- return opts.colors ? `\x1B[32m'${sq}'\x1B[39m` : `'${sq}'`;
16
- }
17
- if (typeof value === "number") {
18
- return opts.colors ? `\x1B[33m${value}\x1B[39m` : String(value);
19
- }
20
- if (typeof value === "bigint") {
21
- return opts.colors ? `\x1B[33m${value}n\x1B[39m` : `${value}n`;
22
- }
23
- if (typeof value === "boolean") {
24
- return opts.colors ? `\x1B[33m${value}\x1B[39m` : String(value);
25
- }
26
- if (typeof value === "symbol") {
27
- return opts.colors ? `\x1B[32m${value.toString()}\x1B[39m` : value.toString();
28
- }
29
- if (typeof value === "function") {
30
- const name = value.name ? `: ${value.name}` : "";
31
- return opts.colors ? `\x1B[36m[Function${name}]\x1B[39m` : `[Function${name}]`;
32
- }
33
- if (value !== null && typeof value === "object" && kCustomInspect in value) {
34
- const custom = value[kCustomInspect];
35
- if (typeof custom === "function") {
36
- const result = custom.call(value, depth, opts);
37
- if (typeof result === "string") return result;
38
- return inspectValue(result, opts, depth);
39
- }
40
- }
41
- if (value instanceof Date) {
42
- return value.toISOString();
43
- }
44
- if (value instanceof RegExp) {
45
- return opts.colors ? `\x1B[31m${value.toString()}\x1B[39m` : value.toString();
46
- }
47
- if (value instanceof Error) {
48
- return value.stack || value.toString();
49
- }
50
- if (depth > maxDepth) {
51
- return Array.isArray(value) ? "[Array]" : "[Object]";
52
- }
53
- if (Array.isArray(value)) {
54
- return inspectArray(value, opts, depth);
55
- }
56
- if (value instanceof Map) {
57
- const entries = [...value.entries()].map(
58
- ([k, v]) => `${inspectValue(k, opts, depth + 1)} => ${inspectValue(v, opts, depth + 1)}`
59
- );
60
- return `Map(${value.size}) { ${entries.join(", ")} }`;
61
- }
62
- if (value instanceof Set) {
63
- const entries = [...value].map((v) => inspectValue(v, opts, depth + 1));
64
- return `Set(${value.size}) { ${entries.join(", ")} }`;
65
- }
66
- if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
67
- const name = value.constructor?.name || "TypedArray";
68
- const arr = Array.from(value);
69
- return `${name}(${arr.length}) [ ${arr.join(", ")} ]`;
70
- }
71
- return inspectObject(value, opts, depth);
7
+ if (value === null) return opts.colors ? "\x1B[1mnull\x1B[22m" : "null";
8
+ if (value === undefined) return opts.colors ? "\x1B[90mundefined\x1B[39m" : "undefined";
9
+ const maxDepth = opts.depth ?? 2;
10
+ if (typeof value === "string") {
11
+ const escaped = value.replace(/\\/g, "\\\\");
12
+ if (value.includes("'") && !value.includes("\"")) {
13
+ const dq = escaped.replace(/"/g, "\\\"");
14
+ return opts.colors ? `\x1b[32m"${dq}"\x1b[39m` : `"${dq}"`;
15
+ }
16
+ const sq = escaped.replace(/'/g, "\\'");
17
+ return opts.colors ? `\x1b[32m'${sq}'\x1b[39m` : `'${sq}'`;
18
+ }
19
+ if (typeof value === "number") {
20
+ return opts.colors ? `\x1b[33m${value}\x1b[39m` : String(value);
21
+ }
22
+ if (typeof value === "bigint") {
23
+ return opts.colors ? `\x1b[33m${value}n\x1b[39m` : `${value}n`;
24
+ }
25
+ if (typeof value === "boolean") {
26
+ return opts.colors ? `\x1b[33m${value}\x1b[39m` : String(value);
27
+ }
28
+ if (typeof value === "symbol") {
29
+ return opts.colors ? `\x1b[32m${value.toString()}\x1b[39m` : value.toString();
30
+ }
31
+ if (typeof value === "function") {
32
+ const name = value.name ? `: ${value.name}` : "";
33
+ return opts.colors ? `\x1b[36m[Function${name}]\x1b[39m` : `[Function${name}]`;
34
+ }
35
+ if (value !== null && typeof value === "object" && kCustomInspect in value) {
36
+ const custom = value[kCustomInspect];
37
+ if (typeof custom === "function") {
38
+ const result = custom.call(value, depth, opts);
39
+ if (typeof result === "string") return result;
40
+ return inspectValue(result, opts, depth);
41
+ }
42
+ }
43
+ if (value instanceof Date) {
44
+ return value.toISOString();
45
+ }
46
+ if (value instanceof RegExp) {
47
+ return opts.colors ? `\x1b[31m${value.toString()}\x1b[39m` : value.toString();
48
+ }
49
+ if (value instanceof Error) {
50
+ return value.stack || value.toString();
51
+ }
52
+ if (depth > maxDepth) {
53
+ return Array.isArray(value) ? "[Array]" : "[Object]";
54
+ }
55
+ if (Array.isArray(value)) {
56
+ return inspectArray(value, opts, depth);
57
+ }
58
+ if (value instanceof Map) {
59
+ const entries = [...value.entries()].map(([k, v]) => `${inspectValue(k, opts, depth + 1)} => ${inspectValue(v, opts, depth + 1)}`);
60
+ return `Map(${value.size}) { ${entries.join(", ")} }`;
61
+ }
62
+ if (value instanceof Set) {
63
+ const entries = [...value].map((v) => inspectValue(v, opts, depth + 1));
64
+ return `Set(${value.size}) { ${entries.join(", ")} }`;
65
+ }
66
+ if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
67
+ const name = value.constructor?.name || "TypedArray";
68
+ const arr = Array.from(value);
69
+ return `${name}(${arr.length}) [ ${arr.join(", ")} ]`;
70
+ }
71
+ return inspectObject(value, opts, depth);
72
72
  }
73
73
  function inspectArray(arr, opts, depth) {
74
- const maxLen = opts.maxArrayLength ?? 100;
75
- const len = Math.min(arr.length, maxLen);
76
- const items = [];
77
- for (let i = 0; i < len; i++) {
78
- items.push(inspectValue(arr[i], opts, depth + 1));
79
- }
80
- if (arr.length > maxLen) {
81
- items.push(`... ${arr.length - maxLen} more items`);
82
- }
83
- if (opts.showHidden) {
84
- items.push(`[length]: ${arr.length}`);
85
- }
86
- const breakLength = opts.breakLength ?? 72;
87
- const compact = opts.compact ?? 3;
88
- if (typeof compact === "number" && compact > 0 && arr.length > compact) {
89
- const indent = " ";
90
- const indentLen = indent.length;
91
- const stripAnsi = (s) => s.replace(/\x1b\[[0-9;]*m/g, "");
92
- const maxItemLen = Math.max(...items.map((item) => stripAnsi(item).length));
93
- const biasedMax = Math.max(maxItemLen - 2, 1);
94
- const numItems = items.length;
95
- const approxCharHeights = 2.5;
96
- const columns = Math.min(
97
- Math.round(Math.sqrt(approxCharHeights * biasedMax * numItems) / biasedMax),
98
- Math.floor((breakLength - indentLen) / biasedMax),
99
- Math.floor((2.5 + numItems - 1) / 2),
100
- 15
101
- );
102
- if (columns > 1) {
103
- const rows = [];
104
- for (let i = 0; i < numItems; i += columns) {
105
- rows.push(indent + items.slice(i, Math.min(i + columns, numItems)).join(", "));
106
- }
107
- return `[
108
- ${rows.join(",\n")}
109
- ]`;
110
- }
111
- }
112
- const singleLine = `[ ${items.join(", ")} ]`;
113
- if (singleLine.length <= breakLength) return singleLine;
114
- return `[
115
- ${items.map((i) => " " + i).join(",\n")}
116
- ]`;
74
+ const maxLen = opts.maxArrayLength ?? 100;
75
+ const len = Math.min(arr.length, maxLen);
76
+ const items = [];
77
+ for (let i = 0; i < len; i++) {
78
+ items.push(inspectValue(arr[i], opts, depth + 1));
79
+ }
80
+ if (arr.length > maxLen) {
81
+ items.push(`... ${arr.length - maxLen} more items`);
82
+ }
83
+ if (opts.showHidden) {
84
+ items.push(`[length]: ${arr.length}`);
85
+ }
86
+ const breakLength = opts.breakLength ?? 72;
87
+ const compact = opts.compact ?? 3;
88
+ if (typeof compact === "number" && compact > 0 && arr.length > compact) {
89
+ const indent = " ";
90
+ const indentLen = indent.length;
91
+ const stripAnsi = (s) => s.replace(/\x1b\[[0-9;]*m/g, "");
92
+ const maxItemLen = Math.max(...items.map((item) => stripAnsi(item).length));
93
+ const biasedMax = Math.max(maxItemLen - 2, 1);
94
+ const numItems = items.length;
95
+ const approxCharHeights = 2.5;
96
+ const columns = Math.min(Math.round(Math.sqrt(approxCharHeights * biasedMax * numItems) / biasedMax), Math.floor((breakLength - indentLen) / biasedMax), Math.floor((2.5 + numItems - 1) / 2), 15);
97
+ if (columns > 1) {
98
+ const rows = [];
99
+ for (let i = 0; i < numItems; i += columns) {
100
+ rows.push(indent + items.slice(i, Math.min(i + columns, numItems)).join(", "));
101
+ }
102
+ return `[\n${rows.join(",\n")}\n]`;
103
+ }
104
+ }
105
+ const singleLine = `[ ${items.join(", ")} ]`;
106
+ if (singleLine.length <= breakLength) return singleLine;
107
+ return `[\n${items.map((i) => " " + i).join(",\n")}\n]`;
117
108
  }
118
109
  function inspectObject(obj, opts, depth) {
119
- const keys = opts.showHidden ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
120
- if (opts.sorted) keys.sort();
121
- if (keys.length === 0) {
122
- const tag = Object.prototype.toString.call(obj);
123
- if (tag !== "[object Object]") return tag;
124
- return "{}";
125
- }
126
- const items = keys.map((key) => {
127
- const val = inspectValue(obj[key], opts, depth + 1);
128
- return `${key}: ${val}`;
129
- });
130
- const breakLength = opts.breakLength ?? 72;
131
- const singleLine = `{ ${items.join(", ")} }`;
132
- if (singleLine.length <= breakLength) return singleLine;
133
- return `{
134
- ${items.map((i) => " " + i).join(",\n")}
135
- }`;
110
+ const keys = opts.showHidden ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
111
+ if (opts.sorted) keys.sort();
112
+ if (keys.length === 0) {
113
+ const tag = Object.prototype.toString.call(obj);
114
+ if (tag !== "[object Object]") return tag;
115
+ return "{}";
116
+ }
117
+ const items = keys.map((key) => {
118
+ const val = inspectValue(obj[key], opts, depth + 1);
119
+ return `${key}: ${val}`;
120
+ });
121
+ const breakLength = opts.breakLength ?? 72;
122
+ const singleLine = `{ ${items.join(", ")} }`;
123
+ if (singleLine.length <= breakLength) return singleLine;
124
+ return `{\n${items.map((i) => " " + i).join(",\n")}\n}`;
136
125
  }
137
126
  function inspect(value, opts) {
138
- const options = typeof opts === "boolean" ? { showHidden: opts } : { ...opts };
139
- if (options.colors === void 0) options.colors = false;
140
- return inspectValue(value, options, 0);
127
+ const options = typeof opts === "boolean" ? { showHidden: opts } : { ...opts };
128
+ if (options.colors === undefined) options.colors = false;
129
+ return inspectValue(value, options, 0);
141
130
  }
142
131
  inspect.custom = kCustomInspect;
143
132
  inspect.defaultOptions = {
144
- showHidden: false,
145
- depth: 2,
146
- colors: false,
147
- maxArrayLength: 100,
148
- maxStringLength: 1e4,
149
- breakLength: 72,
150
- compact: 3,
151
- sorted: false
133
+ showHidden: false,
134
+ depth: 2,
135
+ colors: false,
136
+ maxArrayLength: 100,
137
+ maxStringLength: 1e4,
138
+ breakLength: 72,
139
+ compact: 3,
140
+ sorted: false
152
141
  };
142
+ /** ANSI color code pairs [open, close] for terminal coloring. */
153
143
  inspect.colors = {
154
- reset: [0, 0],
155
- bold: [1, 22],
156
- dim: [2, 22],
157
- italic: [3, 23],
158
- underline: [4, 24],
159
- blink: [5, 25],
160
- inverse: [7, 27],
161
- hidden: [8, 28],
162
- strikethrough: [9, 29],
163
- doubleunderline: [21, 24],
164
- black: [30, 39],
165
- red: [31, 39],
166
- green: [32, 39],
167
- yellow: [33, 39],
168
- blue: [34, 39],
169
- magenta: [35, 39],
170
- cyan: [36, 39],
171
- white: [37, 39],
172
- bgBlack: [40, 49],
173
- bgRed: [41, 49],
174
- bgGreen: [42, 49],
175
- bgYellow: [43, 49],
176
- bgBlue: [44, 49],
177
- bgMagenta: [45, 49],
178
- bgCyan: [46, 49],
179
- bgWhite: [47, 49],
180
- framed: [51, 54],
181
- overlined: [53, 55],
182
- gray: [90, 39],
183
- grey: [90, 39],
184
- redBright: [91, 39],
185
- greenBright: [92, 39],
186
- yellowBright: [93, 39],
187
- blueBright: [94, 39],
188
- magentaBright: [95, 39],
189
- cyanBright: [96, 39],
190
- whiteBright: [97, 39],
191
- bgBlackBright: [100, 49],
192
- bgRedBright: [101, 49],
193
- bgGreenBright: [102, 49],
194
- bgYellowBright: [103, 49],
195
- bgBlueBright: [104, 49],
196
- bgMagentaBright: [105, 49],
197
- bgCyanBright: [106, 49],
198
- bgWhiteBright: [107, 49]
144
+ reset: [0, 0],
145
+ bold: [1, 22],
146
+ dim: [2, 22],
147
+ italic: [3, 23],
148
+ underline: [4, 24],
149
+ blink: [5, 25],
150
+ inverse: [7, 27],
151
+ hidden: [8, 28],
152
+ strikethrough: [9, 29],
153
+ doubleunderline: [21, 24],
154
+ black: [30, 39],
155
+ red: [31, 39],
156
+ green: [32, 39],
157
+ yellow: [33, 39],
158
+ blue: [34, 39],
159
+ magenta: [35, 39],
160
+ cyan: [36, 39],
161
+ white: [37, 39],
162
+ bgBlack: [40, 49],
163
+ bgRed: [41, 49],
164
+ bgGreen: [42, 49],
165
+ bgYellow: [43, 49],
166
+ bgBlue: [44, 49],
167
+ bgMagenta: [45, 49],
168
+ bgCyan: [46, 49],
169
+ bgWhite: [47, 49],
170
+ framed: [51, 54],
171
+ overlined: [53, 55],
172
+ gray: [90, 39],
173
+ grey: [90, 39],
174
+ redBright: [91, 39],
175
+ greenBright: [92, 39],
176
+ yellowBright: [93, 39],
177
+ blueBright: [94, 39],
178
+ magentaBright: [95, 39],
179
+ cyanBright: [96, 39],
180
+ whiteBright: [97, 39],
181
+ bgBlackBright: [100, 49],
182
+ bgRedBright: [101, 49],
183
+ bgGreenBright: [102, 49],
184
+ bgYellowBright: [103, 49],
185
+ bgBlueBright: [104, 49],
186
+ bgMagentaBright: [105, 49],
187
+ bgCyanBright: [106, 49],
188
+ bgWhiteBright: [107, 49]
199
189
  };
190
+ /** Maps type names to color names for util.inspect output styling. */
200
191
  inspect.styles = {
201
- special: "cyan",
202
- number: "yellow",
203
- bigint: "yellow",
204
- boolean: "yellow",
205
- undefined: "grey",
206
- null: "bold",
207
- string: "green",
208
- symbol: "green",
209
- date: "magenta",
210
- regexp: "red",
211
- module: "underline"
192
+ special: "cyan",
193
+ number: "yellow",
194
+ bigint: "yellow",
195
+ boolean: "yellow",
196
+ undefined: "grey",
197
+ null: "bold",
198
+ string: "green",
199
+ symbol: "green",
200
+ date: "magenta",
201
+ regexp: "red",
202
+ module: "underline"
212
203
  };
213
204
  function format(fmt, ...args) {
214
- if (fmt === void 0 && args.length === 0) return "";
215
- if (typeof fmt !== "string") {
216
- if (args.length === 0) return inspect(fmt);
217
- const parts = [inspect(fmt)];
218
- for (const arg of args) parts.push(inspect(arg));
219
- return parts.join(" ");
220
- }
221
- let i = 0;
222
- let result = "";
223
- let lastIdx = 0;
224
- for (let p = 0; p < fmt.length - 1; p++) {
225
- if (fmt[p] !== "%") continue;
226
- if (p > lastIdx) result += fmt.slice(lastIdx, p);
227
- const next = fmt[p + 1];
228
- if (next === "%") {
229
- result += "%";
230
- lastIdx = p + 2;
231
- p++;
232
- continue;
233
- }
234
- if (i >= args.length) {
235
- result += "%" + next;
236
- lastIdx = p + 2;
237
- p++;
238
- continue;
239
- }
240
- const arg = args[i];
241
- switch (next) {
242
- case "s": {
243
- if (typeof arg === "bigint") {
244
- result += `${arg}n`;
245
- } else if (typeof arg === "symbol") {
246
- result += arg.toString();
247
- } else if (typeof arg === "number" && Object.is(arg, -0)) {
248
- result += "-0";
249
- } else if (typeof arg === "object" && arg !== null) {
250
- const proto = Object.getPrototypeOf(arg);
251
- if (proto === null || typeof arg.toString === "function" && arg.toString !== Object.prototype.toString && arg.toString !== Array.prototype.toString) {
252
- try {
253
- const str = arg.toString();
254
- if (typeof str === "string" && str !== "[object Object]") {
255
- result += str;
256
- } else {
257
- result += inspect(arg, { depth: 0 });
258
- }
259
- } catch {
260
- result += inspect(arg, { depth: 0 });
261
- }
262
- } else {
263
- result += inspect(arg, { depth: 0 });
264
- }
265
- } else {
266
- result += String(arg);
267
- }
268
- i++;
269
- break;
270
- }
271
- case "d": {
272
- if (typeof arg === "bigint") {
273
- result += `${arg}n`;
274
- } else if (typeof arg === "symbol") {
275
- result += "NaN";
276
- } else {
277
- const n = Number(arg);
278
- result += Object.is(n, -0) ? "-0" : String(n);
279
- }
280
- i++;
281
- break;
282
- }
283
- case "i": {
284
- if (typeof arg === "bigint") {
285
- result += `${arg}n`;
286
- } else if (typeof arg === "symbol") {
287
- result += "NaN";
288
- } else {
289
- const n = Number(arg);
290
- if (!isFinite(n)) {
291
- result += "NaN";
292
- } else {
293
- const truncated = Math.trunc(n);
294
- result += Object.is(truncated, -0) ? "-0" : String(truncated);
295
- }
296
- }
297
- i++;
298
- break;
299
- }
300
- case "f": {
301
- if (typeof arg === "bigint") {
302
- result += Number(arg).toString();
303
- } else if (typeof arg === "symbol") {
304
- result += "NaN";
305
- } else {
306
- const n = parseFloat(String(arg));
307
- result += Object.is(n, -0) ? "-0" : String(n);
308
- }
309
- i++;
310
- break;
311
- }
312
- case "j":
313
- try {
314
- result += JSON.stringify(args[i++]);
315
- } catch {
316
- result += "[Circular]";
317
- }
318
- break;
319
- case "o":
320
- result += inspect(args[i++], { showHidden: true, depth: 4 });
321
- break;
322
- case "O":
323
- result += inspect(args[i++], { depth: 4 });
324
- break;
325
- default:
326
- result += "%" + next;
327
- break;
328
- }
329
- lastIdx = p + 2;
330
- p++;
331
- }
332
- if (lastIdx < fmt.length) {
333
- result += fmt.slice(lastIdx);
334
- }
335
- for (; i < args.length; i++) {
336
- const arg = args[i];
337
- if (typeof arg === "string") {
338
- result += " " + arg;
339
- } else {
340
- result += " " + inspect(arg);
341
- }
342
- }
343
- return result;
205
+ if (fmt === undefined && args.length === 0) return "";
206
+ if (typeof fmt !== "string") {
207
+ if (args.length === 0) return inspect(fmt);
208
+ const parts = [inspect(fmt)];
209
+ for (const arg of args) parts.push(inspect(arg));
210
+ return parts.join(" ");
211
+ }
212
+ let i = 0;
213
+ let result = "";
214
+ let lastIdx = 0;
215
+ for (let p = 0; p < fmt.length - 1; p++) {
216
+ if (fmt[p] !== "%") continue;
217
+ if (p > lastIdx) result += fmt.slice(lastIdx, p);
218
+ const next = fmt[p + 1];
219
+ if (next === "%") {
220
+ result += "%";
221
+ lastIdx = p + 2;
222
+ p++;
223
+ continue;
224
+ }
225
+ if (i >= args.length) {
226
+ result += "%" + next;
227
+ lastIdx = p + 2;
228
+ p++;
229
+ continue;
230
+ }
231
+ const arg = args[i];
232
+ switch (next) {
233
+ case "s": {
234
+ if (typeof arg === "bigint") {
235
+ result += `${arg}n`;
236
+ } else if (typeof arg === "symbol") {
237
+ result += arg.toString();
238
+ } else if (typeof arg === "number" && Object.is(arg, -0)) {
239
+ result += "-0";
240
+ } else if (typeof arg === "object" && arg !== null) {
241
+ const proto = Object.getPrototypeOf(arg);
242
+ if (proto === null || typeof arg.toString === "function" && arg.toString !== Object.prototype.toString && arg.toString !== Array.prototype.toString) {
243
+ try {
244
+ const str = arg.toString();
245
+ if (typeof str === "string" && str !== "[object Object]") {
246
+ result += str;
247
+ } else {
248
+ result += inspect(arg, { depth: 0 });
249
+ }
250
+ } catch {
251
+ result += inspect(arg, { depth: 0 });
252
+ }
253
+ } else {
254
+ result += inspect(arg, { depth: 0 });
255
+ }
256
+ } else {
257
+ result += String(arg);
258
+ }
259
+ i++;
260
+ break;
261
+ }
262
+ case "d": {
263
+ if (typeof arg === "bigint") {
264
+ result += `${arg}n`;
265
+ } else if (typeof arg === "symbol") {
266
+ result += "NaN";
267
+ } else {
268
+ const n = Number(arg);
269
+ result += Object.is(n, -0) ? "-0" : String(n);
270
+ }
271
+ i++;
272
+ break;
273
+ }
274
+ case "i": {
275
+ if (typeof arg === "bigint") {
276
+ result += `${arg}n`;
277
+ } else if (typeof arg === "symbol") {
278
+ result += "NaN";
279
+ } else {
280
+ const n = Number(arg);
281
+ if (!isFinite(n)) {
282
+ result += "NaN";
283
+ } else {
284
+ const truncated = Math.trunc(n);
285
+ result += Object.is(truncated, -0) ? "-0" : String(truncated);
286
+ }
287
+ }
288
+ i++;
289
+ break;
290
+ }
291
+ case "f": {
292
+ if (typeof arg === "bigint") {
293
+ result += Number(arg).toString();
294
+ } else if (typeof arg === "symbol") {
295
+ result += "NaN";
296
+ } else {
297
+ const n = parseFloat(String(arg));
298
+ result += Object.is(n, -0) ? "-0" : String(n);
299
+ }
300
+ i++;
301
+ break;
302
+ }
303
+ case "j":
304
+ try {
305
+ result += JSON.stringify(args[i++]);
306
+ } catch {
307
+ result += "[Circular]";
308
+ }
309
+ break;
310
+ case "o":
311
+ result += inspect(args[i++], {
312
+ showHidden: true,
313
+ depth: 4
314
+ });
315
+ break;
316
+ case "O":
317
+ result += inspect(args[i++], { depth: 4 });
318
+ break;
319
+ default:
320
+ result += "%" + next;
321
+ break;
322
+ }
323
+ lastIdx = p + 2;
324
+ p++;
325
+ }
326
+ if (lastIdx < fmt.length) {
327
+ result += fmt.slice(lastIdx);
328
+ }
329
+ for (; i < args.length; i++) {
330
+ const arg = args[i];
331
+ if (typeof arg === "string") {
332
+ result += " " + arg;
333
+ } else {
334
+ result += " " + inspect(arg);
335
+ }
336
+ }
337
+ return result;
344
338
  }
345
339
  function formatWithOptions(inspectOptions, fmt, ...args) {
346
- return format(fmt, ...args);
340
+ return format(fmt, ...args);
347
341
  }
348
- const ANSI_REGEX = new RegExp(
349
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
350
- "g"
351
- );
342
+ const ANSI_REGEX = new RegExp("[\\u001B\\u009B][[\\]()#;?]*" + "(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*" + "|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?" + "(?:\\u0007|\\u001B\\u005C|\\u009C))" + "|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?" + "[\\dA-PR-TZcf-nq-uy=><~]))", "g");
352
343
  function stripVTControlCharacters(str) {
353
- if (typeof str !== "string") {
354
- throw new TypeError('The "str" argument must be of type string. Received ' + typeof str);
355
- }
356
- if (str.indexOf("\x1B") === -1 && str.indexOf("\x9B") === -1) return str;
357
- return str.replace(ANSI_REGEX, "");
344
+ if (typeof str !== "string") {
345
+ throw new TypeError("The \"str\" argument must be of type string. Received " + typeof str);
346
+ }
347
+ if (str.indexOf("\x1B") === -1 && str.indexOf("›") === -1) return str;
348
+ return str.replace(ANSI_REGEX, "");
358
349
  }
359
- function styleText(format2, text, options) {
360
- if (typeof text !== "string") {
361
- throw new TypeError('The "text" argument must be of type string. Received ' + typeof text);
362
- }
363
- const validateStream = options?.validateStream ?? true;
364
- if (validateStream) {
365
- const stream = options?.stream ?? globalThis.process?.stdout;
366
- if (!stream?.isTTY) return text;
367
- }
368
- const formats = Array.isArray(format2) ? format2 : [format2];
369
- let openCodes = "";
370
- let closeCodes = "";
371
- for (const key of formats) {
372
- if (key === "none") continue;
373
- const style = inspect.colors[key];
374
- if (style === void 0) {
375
- throw new TypeError(`The "format" argument must be one of: ${Object.keys(inspect.colors).join(", ")}. Received '${key}'`);
376
- }
377
- openCodes += `\x1B[${style[0]}m`;
378
- closeCodes = `\x1B[${style[1]}m` + closeCodes;
379
- }
380
- return `${openCodes}${text}${closeCodes}`;
350
+ /**
351
+ * Apply ANSI styling to text, using the format names from `inspect.colors`.
352
+ * Per Node's spec, when `validateStream` is true (default) and the target
353
+ * stream is not a TTY, return the unstyled text. We use `process.stdout` as
354
+ * the default stream the same as Node.
355
+ */
356
+ function styleText(format, text, options) {
357
+ if (typeof text !== "string") {
358
+ throw new TypeError("The \"text\" argument must be of type string. Received " + typeof text);
359
+ }
360
+ const validateStream = options?.validateStream ?? true;
361
+ if (validateStream) {
362
+ const stream = options?.stream ?? globalThis.process?.stdout;
363
+ if (!stream?.isTTY) return text;
364
+ }
365
+ const formats = Array.isArray(format) ? format : [format];
366
+ let openCodes = "";
367
+ let closeCodes = "";
368
+ for (const key of formats) {
369
+ if (key === "none") continue;
370
+ const style = inspect.colors[key];
371
+ if (style === undefined) {
372
+ throw new TypeError(`The "format" argument must be one of: ${Object.keys(inspect.colors).join(", ")}. Received '${key}'`);
373
+ }
374
+ openCodes += `[${style[0]}m`;
375
+ closeCodes = `[${style[1]}m` + closeCodes;
376
+ }
377
+ return `${openCodes}${text}${closeCodes}`;
381
378
  }
382
- const kCustomPromisify = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
379
+ const kCustomPromisify = Symbol.for("nodejs.util.promisify.custom");
383
380
  function promisify(fn) {
384
- if (typeof fn !== "function") {
385
- throw new TypeError('The "original" argument must be of type Function');
386
- }
387
- const custom = fn[kCustomPromisify];
388
- if (typeof custom === "function") return custom;
389
- function promisified(...args) {
390
- return new Promise((resolve, reject) => {
391
- fn.call(this, ...args, (err, ...values) => {
392
- if (err) {
393
- reject(err);
394
- } else if (values.length <= 1) {
395
- resolve(values[0]);
396
- } else {
397
- resolve(values);
398
- }
399
- });
400
- });
401
- }
402
- Object.setPrototypeOf(promisified, Object.getPrototypeOf(fn));
403
- Object.defineProperty(promisified, kCustomPromisify, { value: promisified });
404
- return promisified;
381
+ if (typeof fn !== "function") {
382
+ throw new TypeError("The \"original\" argument must be of type Function");
383
+ }
384
+ const custom = fn[kCustomPromisify];
385
+ if (typeof custom === "function") return custom;
386
+ function promisified(...args) {
387
+ return new Promise((resolve, reject) => {
388
+ fn.call(this, ...args, (err, ...values) => {
389
+ if (err) {
390
+ reject(err);
391
+ } else if (values.length <= 1) {
392
+ resolve(values[0]);
393
+ } else {
394
+ resolve(values);
395
+ }
396
+ });
397
+ });
398
+ }
399
+ Object.setPrototypeOf(promisified, Object.getPrototypeOf(fn));
400
+ Object.defineProperty(promisified, kCustomPromisify, { value: promisified });
401
+ return promisified;
405
402
  }
406
403
  promisify.custom = kCustomPromisify;
407
404
  function callbackify(fn) {
408
- if (typeof fn !== "function") {
409
- throw new TypeError('The "original" argument must be of type Function');
410
- }
411
- return function(...args) {
412
- const callback = args.pop();
413
- if (typeof callback !== "function") {
414
- throw new TypeError("The last argument must be of type Function");
415
- }
416
- fn.apply(this, args).then(
417
- (result) => Promise.resolve().then(() => callback(null, result)),
418
- (err) => Promise.resolve().then(() => callback(err || new Error()))
419
- );
420
- };
405
+ if (typeof fn !== "function") {
406
+ throw new TypeError("The \"original\" argument must be of type Function");
407
+ }
408
+ return function(...args) {
409
+ const callback = args.pop();
410
+ if (typeof callback !== "function") {
411
+ throw new TypeError("The last argument must be of type Function");
412
+ }
413
+ fn.apply(this, args).then((result) => Promise.resolve().then(() => callback(null, result)), (err) => Promise.resolve().then(() => callback(err || new Error())));
414
+ };
421
415
  }
422
416
  function deprecate(fn, msg, code) {
423
- let warned = false;
424
- function deprecated(...args) {
425
- if (!warned) {
426
- warned = true;
427
- const warning = code ? `[${code}] ${msg}` : msg;
428
- console.warn(`DeprecationWarning: ${warning}`);
429
- }
430
- return fn.apply(this, args);
431
- }
432
- Object.setPrototypeOf(deprecated, fn);
433
- return deprecated;
417
+ let warned = false;
418
+ function deprecated(...args) {
419
+ if (!warned) {
420
+ warned = true;
421
+ const warning = code ? `[${code}] ${msg}` : msg;
422
+ console.warn(`DeprecationWarning: ${warning}`);
423
+ }
424
+ return fn.apply(this, args);
425
+ }
426
+ Object.setPrototypeOf(deprecated, fn);
427
+ return deprecated;
434
428
  }
435
429
  function debuglog(section) {
436
- let debug;
437
- return (...args) => {
438
- if (debug === void 0) {
439
- const nodeDebug = typeof globalThis.process?.env?.NODE_DEBUG === "string" ? globalThis.process.env.NODE_DEBUG : "";
440
- const regex = new RegExp(`\\b${section}\\b`, "i");
441
- if (regex.test(nodeDebug)) {
442
- const pid = typeof globalThis.process?.pid === "number" ? globalThis.process.pid : 0;
443
- debug = (...a) => {
444
- console.error(`${section.toUpperCase()} ${pid}:`, ...a);
445
- };
446
- } else {
447
- debug = () => {
448
- };
449
- }
450
- }
451
- debug(...args);
452
- };
430
+ let debug;
431
+ return (...args) => {
432
+ if (debug === undefined) {
433
+ const nodeDebug = typeof globalThis.process?.env?.NODE_DEBUG === "string" ? globalThis.process.env.NODE_DEBUG : "";
434
+ const regex = new RegExp(`\\b${section}\\b`, "i");
435
+ if (regex.test(nodeDebug)) {
436
+ const pid = typeof globalThis.process?.pid === "number" ? globalThis.process.pid : 0;
437
+ debug = (...a) => {
438
+ console.error(`${section.toUpperCase()} ${pid}:`, ...a);
439
+ };
440
+ } else {
441
+ debug = () => {};
442
+ }
443
+ }
444
+ debug(...args);
445
+ };
453
446
  }
454
447
  function inherits(ctor, superCtor) {
455
- if (ctor === void 0 || ctor === null) {
456
- const err = new TypeError('The "ctor" argument must be of type Function. Received ' + String(ctor));
457
- err.code = "ERR_INVALID_ARG_TYPE";
458
- throw err;
459
- }
460
- if (superCtor === void 0 || superCtor === null) {
461
- const err = new TypeError('The "superCtor" argument must be of type Function. Received ' + String(superCtor));
462
- err.code = "ERR_INVALID_ARG_TYPE";
463
- throw err;
464
- }
465
- if (superCtor.prototype === void 0) {
466
- const err = new TypeError('The "superCtor.prototype" property must not be undefined');
467
- err.code = "ERR_INVALID_ARG_TYPE";
468
- throw err;
469
- }
470
- Object.defineProperty(ctor, "super_", { value: superCtor, writable: true, configurable: true });
471
- Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
448
+ if (ctor === undefined || ctor === null) {
449
+ const err = new TypeError("The \"ctor\" argument must be of type Function. Received " + String(ctor));
450
+ err.code = "ERR_INVALID_ARG_TYPE";
451
+ throw err;
452
+ }
453
+ if (superCtor === undefined || superCtor === null) {
454
+ const err = new TypeError("The \"superCtor\" argument must be of type Function. Received " + String(superCtor));
455
+ err.code = "ERR_INVALID_ARG_TYPE";
456
+ throw err;
457
+ }
458
+ if (superCtor.prototype === undefined) {
459
+ const err = new TypeError("The \"superCtor.prototype\" property must not be undefined");
460
+ err.code = "ERR_INVALID_ARG_TYPE";
461
+ throw err;
462
+ }
463
+ Object.defineProperty(ctor, "super_", {
464
+ value: superCtor,
465
+ writable: true,
466
+ configurable: true
467
+ });
468
+ Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
472
469
  }
473
470
  function isBoolean(value) {
474
- return typeof value === "boolean";
471
+ return typeof value === "boolean";
475
472
  }
476
473
  function isNull(value) {
477
- return value === null;
474
+ return value === null;
478
475
  }
479
476
  function isNullOrUndefined(value) {
480
- return value == null;
477
+ return value == null;
481
478
  }
482
479
  function isNumber(value) {
483
- return typeof value === "number";
480
+ return typeof value === "number";
484
481
  }
485
482
  function isString(value) {
486
- return typeof value === "string";
483
+ return typeof value === "string";
487
484
  }
488
485
  function isSymbol(value) {
489
- return typeof value === "symbol";
486
+ return typeof value === "symbol";
490
487
  }
491
488
  function isUndefined(value) {
492
- return value === void 0;
489
+ return value === undefined;
493
490
  }
494
491
  function isObject(value) {
495
- return value !== null && typeof value === "object";
492
+ return value !== null && typeof value === "object";
496
493
  }
497
494
  function isError(value) {
498
- return value instanceof Error;
495
+ return value instanceof Error;
499
496
  }
500
497
  function isFunction(value) {
501
- return typeof value === "function";
498
+ return typeof value === "function";
502
499
  }
503
500
  function isRegExp(value) {
504
- return value instanceof RegExp;
501
+ return value instanceof RegExp;
505
502
  }
506
503
  function isArray(value) {
507
- return Array.isArray(value);
504
+ return Array.isArray(value);
508
505
  }
509
506
  function isPrimitive(value) {
510
- return value === null || typeof value !== "object" && typeof value !== "function";
507
+ return value === null || typeof value !== "object" && typeof value !== "function";
511
508
  }
512
509
  function isDate(value) {
513
- return value instanceof Date;
510
+ return value instanceof Date;
514
511
  }
515
512
  function isBuffer(value) {
516
- return value instanceof Uint8Array && value.constructor?.name === "Buffer";
513
+ return value instanceof Uint8Array && value.constructor?.name === "Buffer";
517
514
  }
518
515
  const TextDecoder = globalThis.TextDecoder;
519
516
  const TextEncoder = globalThis.TextEncoder;
520
517
  function isDeepStrictEqual(a, b) {
521
- if (Object.is(a, b)) return true;
522
- if (typeof a !== typeof b) return false;
523
- if (a === null || b === null) return false;
524
- if (typeof a !== "object") return false;
525
- const aObj = a;
526
- const bObj = b;
527
- if (Array.isArray(aObj) && Array.isArray(bObj)) {
528
- if (aObj.length !== bObj.length) return false;
529
- for (let i = 0; i < aObj.length; i++) {
530
- if (!isDeepStrictEqual(aObj[i], bObj[i])) return false;
531
- }
532
- return true;
533
- }
534
- if (Array.isArray(aObj) !== Array.isArray(bObj)) return false;
535
- if (aObj instanceof Date && bObj instanceof Date) {
536
- return aObj.getTime() === bObj.getTime();
537
- }
538
- if (aObj instanceof RegExp && bObj instanceof RegExp) {
539
- return aObj.source === bObj.source && aObj.flags === bObj.flags;
540
- }
541
- const aKeys = Object.keys(aObj);
542
- const bKeys = Object.keys(bObj);
543
- if (aKeys.length !== bKeys.length) return false;
544
- for (const key of aKeys) {
545
- if (!Object.prototype.hasOwnProperty.call(bObj, key)) return false;
546
- if (!isDeepStrictEqual(aObj[key], bObj[key])) return false;
547
- }
548
- return true;
518
+ if (Object.is(a, b)) return true;
519
+ if (typeof a !== typeof b) return false;
520
+ if (a === null || b === null) return false;
521
+ if (typeof a !== "object") return false;
522
+ const aObj = a;
523
+ const bObj = b;
524
+ if (Array.isArray(aObj) && Array.isArray(bObj)) {
525
+ if (aObj.length !== bObj.length) return false;
526
+ for (let i = 0; i < aObj.length; i++) {
527
+ if (!isDeepStrictEqual(aObj[i], bObj[i])) return false;
528
+ }
529
+ return true;
530
+ }
531
+ if (Array.isArray(aObj) !== Array.isArray(bObj)) return false;
532
+ if (aObj instanceof Date && bObj instanceof Date) {
533
+ return aObj.getTime() === bObj.getTime();
534
+ }
535
+ if (aObj instanceof RegExp && bObj instanceof RegExp) {
536
+ return aObj.source === bObj.source && aObj.flags === bObj.flags;
537
+ }
538
+ const aKeys = Object.keys(aObj);
539
+ const bKeys = Object.keys(bObj);
540
+ if (aKeys.length !== bKeys.length) return false;
541
+ for (const key of aKeys) {
542
+ if (!Object.prototype.hasOwnProperty.call(bObj, key)) return false;
543
+ if (!isDeepStrictEqual(aObj[key], bObj[key])) return false;
544
+ }
545
+ return true;
549
546
  }
550
547
  function toUSVString(string) {
551
- if (typeof string.toWellFormed === "function") {
552
- return string.toWellFormed();
553
- }
554
- return string.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "\uFFFD");
548
+ if (typeof string.toWellFormed === "function") {
549
+ return string.toWellFormed();
550
+ }
551
+ return string.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "");
555
552
  }
556
- var index_default = {
557
- format,
558
- formatWithOptions,
559
- styleText,
560
- stripVTControlCharacters,
561
- inspect,
562
- promisify,
563
- callbackify,
564
- deprecate,
565
- debuglog,
566
- inherits,
567
- types,
568
- isBoolean,
569
- isNull,
570
- isNullOrUndefined,
571
- isNumber,
572
- isString,
573
- isSymbol,
574
- isUndefined,
575
- isObject,
576
- isError,
577
- isFunction,
578
- isRegExp,
579
- isArray,
580
- isPrimitive,
581
- isDate,
582
- isBuffer,
583
- isDeepStrictEqual,
584
- toUSVString,
585
- TextDecoder: globalThis.TextDecoder,
586
- TextEncoder: globalThis.TextEncoder,
587
- getSystemErrorName,
588
- getSystemErrorMap
589
- };
590
- export {
591
- TextDecoder,
592
- TextEncoder,
593
- callbackify,
594
- debuglog,
595
- index_default as default,
596
- deprecate,
597
- format,
598
- formatWithOptions,
599
- getSystemErrorMap,
600
- getSystemErrorName,
601
- inherits,
602
- inspect,
603
- isArray,
604
- isBoolean,
605
- isBuffer,
606
- isDate,
607
- isDeepStrictEqual,
608
- isError,
609
- isFunction,
610
- isNull,
611
- isNullOrUndefined,
612
- isNumber,
613
- isObject,
614
- isPrimitive,
615
- isRegExp,
616
- isString,
617
- isSymbol,
618
- isUndefined,
619
- promisify,
620
- stripVTControlCharacters,
621
- styleText,
622
- toUSVString,
623
- types
553
+ var src_default = {
554
+ format,
555
+ formatWithOptions,
556
+ styleText,
557
+ stripVTControlCharacters,
558
+ inspect,
559
+ promisify,
560
+ callbackify,
561
+ deprecate,
562
+ debuglog,
563
+ inherits,
564
+ types: types_exports,
565
+ isBoolean,
566
+ isNull,
567
+ isNullOrUndefined,
568
+ isNumber,
569
+ isString,
570
+ isSymbol,
571
+ isUndefined,
572
+ isObject,
573
+ isError,
574
+ isFunction,
575
+ isRegExp,
576
+ isArray,
577
+ isPrimitive,
578
+ isDate,
579
+ isBuffer,
580
+ isDeepStrictEqual,
581
+ toUSVString,
582
+ TextDecoder: globalThis.TextDecoder,
583
+ TextEncoder: globalThis.TextEncoder,
584
+ getSystemErrorName,
585
+ getSystemErrorMap
624
586
  };
587
+
588
+ //#endregion
589
+ export { TextDecoder, TextEncoder, callbackify, debuglog, src_default as default, deprecate, format, formatWithOptions, getSystemErrorMap, getSystemErrorName, inherits, inspect, isArray, isBoolean, isBuffer, isDate, isDeepStrictEqual, isError, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, promisify, stripVTControlCharacters, styleText, toUSVString, types_exports as types };