@robinpath/cli 1.73.0 → 1.75.0
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/README.md +111 -111
- package/dist/cli.mjs +344 -301
- package/modules/_helpers.js +33 -33
- package/modules/assert.js +270 -270
- package/modules/buffer.js +245 -245
- package/modules/child.js +176 -176
- package/modules/crypto.js +352 -352
- package/modules/dns.js +146 -146
- package/modules/events.js +174 -174
- package/modules/file.js +361 -361
- package/modules/http.js +268 -268
- package/modules/index.js +76 -76
- package/modules/net.js +189 -189
- package/modules/os.js +219 -219
- package/modules/path.js +162 -162
- package/modules/process.js +214 -214
- package/modules/stream.js +322 -322
- package/modules/string_decoder.js +106 -106
- package/modules/timer.js +167 -167
- package/modules/tls.js +264 -264
- package/modules/tty.js +169 -169
- package/modules/url.js +189 -189
- package/modules/util.js +275 -275
- package/modules/zlib.js +126 -126
- package/package.json +1 -1
package/modules/util.js
CHANGED
|
@@ -1,275 +1,275 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native util module for RobinPath.
|
|
3
|
-
* Utility functions: inspect, format, types, promisify helpers.
|
|
4
|
-
*/
|
|
5
|
-
import { inspect, format, formatWithOptions, types, TextDecoder, TextEncoder } from 'node:util';
|
|
6
|
-
import { toStr, toNum, requireArgs } from './_helpers.js';
|
|
7
|
-
|
|
8
|
-
export const UtilFunctions = {
|
|
9
|
-
|
|
10
|
-
// --- Inspection & Formatting ---
|
|
11
|
-
|
|
12
|
-
inspect: (args) => {
|
|
13
|
-
requireArgs('util.inspect', args, 1);
|
|
14
|
-
const obj = args[0];
|
|
15
|
-
const opts = args[1] && typeof args[1] === 'object' ? args[1] : {};
|
|
16
|
-
return inspect(obj, {
|
|
17
|
-
depth: opts.depth != null ? toNum(opts.depth, 4) : 4,
|
|
18
|
-
colors: opts.colors !== false,
|
|
19
|
-
showHidden: opts.showHidden === true,
|
|
20
|
-
maxArrayLength: opts.maxArrayLength != null ? toNum(opts.maxArrayLength) : 100,
|
|
21
|
-
maxStringLength: opts.maxStringLength != null ? toNum(opts.maxStringLength) : 200,
|
|
22
|
-
compact: opts.compact !== false,
|
|
23
|
-
sorted: opts.sorted === true,
|
|
24
|
-
breakLength: opts.breakLength != null ? toNum(opts.breakLength) : 80
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
format: (args) => {
|
|
29
|
-
return format(...args.map(a => a));
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
formatWithOptions: (args) => {
|
|
33
|
-
requireArgs('util.formatWithOptions', args, 2);
|
|
34
|
-
const opts = args[0];
|
|
35
|
-
return formatWithOptions(opts, ...args.slice(1));
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
// --- Type Checks ---
|
|
39
|
-
|
|
40
|
-
isArray: (args) => Array.isArray(args[0]),
|
|
41
|
-
isBoolean: (args) => typeof args[0] === 'boolean',
|
|
42
|
-
isNull: (args) => args[0] === null,
|
|
43
|
-
isUndefined: (args) => args[0] === undefined,
|
|
44
|
-
isNullOrUndefined: (args) => args[0] == null,
|
|
45
|
-
isNumber: (args) => typeof args[0] === 'number',
|
|
46
|
-
isString: (args) => typeof args[0] === 'string',
|
|
47
|
-
isObject: (args) => typeof args[0] === 'object' && args[0] !== null,
|
|
48
|
-
isFunction: (args) => typeof args[0] === 'function',
|
|
49
|
-
isRegExp: (args) => args[0] instanceof RegExp,
|
|
50
|
-
isDate: (args) => args[0] instanceof Date,
|
|
51
|
-
isError: (args) => args[0] instanceof Error,
|
|
52
|
-
isPrimitive: (args) => {
|
|
53
|
-
const val = args[0];
|
|
54
|
-
return val === null || (typeof val !== 'object' && typeof val !== 'function');
|
|
55
|
-
},
|
|
56
|
-
isPromise: (args) => types.isPromise(args[0]),
|
|
57
|
-
isMap: (args) => types.isMap(args[0]),
|
|
58
|
-
isSet: (args) => types.isSet(args[0]),
|
|
59
|
-
isTypedArray: (args) => types.isTypedArray(args[0]),
|
|
60
|
-
isArrayBuffer: (args) => types.isArrayBuffer(args[0]),
|
|
61
|
-
|
|
62
|
-
typeOf: (args) => {
|
|
63
|
-
requireArgs('util.typeOf', args, 1);
|
|
64
|
-
const val = args[0];
|
|
65
|
-
if (val === null) return 'null';
|
|
66
|
-
if (Array.isArray(val)) return 'array';
|
|
67
|
-
return typeof val;
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
// --- Text Encoding ---
|
|
71
|
-
|
|
72
|
-
textEncode: (args) => {
|
|
73
|
-
requireArgs('util.textEncode', args, 1);
|
|
74
|
-
const encoder = new TextEncoder();
|
|
75
|
-
const encoded = encoder.encode(toStr(args[0]));
|
|
76
|
-
return Buffer.from(encoded).toString('base64');
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
textDecode: (args) => {
|
|
80
|
-
requireArgs('util.textDecode', args, 1);
|
|
81
|
-
const encoding = toStr(args[1], 'utf-8');
|
|
82
|
-
const decoder = new TextDecoder(encoding);
|
|
83
|
-
const buf = Buffer.from(toStr(args[0]), 'base64');
|
|
84
|
-
return decoder.decode(buf);
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
// --- Object Utilities ---
|
|
88
|
-
|
|
89
|
-
deepClone: (args) => {
|
|
90
|
-
requireArgs('util.deepClone', args, 1);
|
|
91
|
-
return structuredClone(args[0]);
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
deepEqual: (args) => {
|
|
95
|
-
requireArgs('util.deepEqual', args, 2);
|
|
96
|
-
try {
|
|
97
|
-
return JSON.stringify(args[0]) === JSON.stringify(args[1]);
|
|
98
|
-
} catch {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
merge: (args) => {
|
|
104
|
-
const result = {};
|
|
105
|
-
for (const arg of args) {
|
|
106
|
-
if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
|
|
107
|
-
Object.assign(result, arg);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
deepMerge: (args) => {
|
|
114
|
-
function _deepMerge(target, source) {
|
|
115
|
-
const result = { ...target };
|
|
116
|
-
for (const key of Object.keys(source)) {
|
|
117
|
-
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key]) &&
|
|
118
|
-
target[key] && typeof target[key] === 'object' && !Array.isArray(target[key])) {
|
|
119
|
-
result[key] = _deepMerge(target[key], source[key]);
|
|
120
|
-
} else {
|
|
121
|
-
result[key] = source[key];
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
let result = {};
|
|
127
|
-
for (const arg of args) {
|
|
128
|
-
if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
|
|
129
|
-
result = _deepMerge(result, arg);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return result;
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
// --- String Utilities ---
|
|
136
|
-
|
|
137
|
-
inherits: () => {
|
|
138
|
-
// Not applicable in RobinPath — return info message
|
|
139
|
-
return 'util.inherits is not needed in RobinPath — use object composition instead';
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
deprecate: (args) => {
|
|
143
|
-
requireArgs('util.deprecate', args, 1);
|
|
144
|
-
console.error(`[DEPRECATED] ${toStr(args[0])}`);
|
|
145
|
-
return true;
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
// --- Performance ---
|
|
149
|
-
|
|
150
|
-
callbackify: () => {
|
|
151
|
-
return 'util.callbackify is not needed — RobinPath handles async natively';
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
sizeof: (args) => {
|
|
155
|
-
requireArgs('util.sizeof', args, 1);
|
|
156
|
-
const val = args[0];
|
|
157
|
-
if (val === null || val === undefined) return 0;
|
|
158
|
-
if (typeof val === 'string') return Buffer.byteLength(val, 'utf-8');
|
|
159
|
-
if (typeof val === 'number') return 8;
|
|
160
|
-
if (typeof val === 'boolean') return 4;
|
|
161
|
-
try {
|
|
162
|
-
return Buffer.byteLength(JSON.stringify(val), 'utf-8');
|
|
163
|
-
} catch {
|
|
164
|
-
return 0;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export const UtilFunctionMetadata = {
|
|
170
|
-
inspect: {
|
|
171
|
-
description: 'Inspect any value with detailed formatting',
|
|
172
|
-
parameters: [
|
|
173
|
-
{ name: 'value', dataType: 'any', description: 'Value to inspect', formInputType: 'json', required: true },
|
|
174
|
-
{ name: 'options', dataType: 'object', description: 'Options: depth, colors, showHidden, compact, sorted', formInputType: 'json', required: false }
|
|
175
|
-
],
|
|
176
|
-
returnType: 'string', returnDescription: 'Formatted inspection string', example: 'util.inspect $obj'
|
|
177
|
-
},
|
|
178
|
-
format: {
|
|
179
|
-
description: 'Format a string with substitutions (%s, %d, %j, %o)',
|
|
180
|
-
parameters: [{ name: 'args', dataType: 'any', description: 'Format string + values', formInputType: 'text', required: true }],
|
|
181
|
-
returnType: 'string', returnDescription: 'Formatted string', example: 'util.format "Hello %s, you are %d" "World" 42'
|
|
182
|
-
},
|
|
183
|
-
typeOf: {
|
|
184
|
-
description: 'Get the type of a value (null, array, string, number, object, boolean)',
|
|
185
|
-
parameters: [{ name: 'value', dataType: 'any', description: 'Value to check', formInputType: 'json', required: true }],
|
|
186
|
-
returnType: 'string', returnDescription: 'Type string', example: 'util.typeOf [1,2,3]'
|
|
187
|
-
},
|
|
188
|
-
isArray: { description: 'Check if value is an array', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if array', example: 'util.isArray [1,2]' },
|
|
189
|
-
isBoolean: { description: 'Check if value is boolean', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if boolean', example: 'util.isBoolean true' },
|
|
190
|
-
isNull: { description: 'Check if value is null', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if null', example: 'util.isNull $val' },
|
|
191
|
-
isNumber: { description: 'Check if value is a number', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if number', example: 'util.isNumber 42' },
|
|
192
|
-
isString: { description: 'Check if value is a string', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if string', example: 'util.isString "hello"' },
|
|
193
|
-
isObject: { description: 'Check if value is an object (non-null)', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if object', example: 'util.isObject {"a":1}' },
|
|
194
|
-
isPrimitive: { description: 'Check if value is a primitive', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if primitive', example: 'util.isPrimitive 42' },
|
|
195
|
-
textEncode: {
|
|
196
|
-
description: 'Encode string to UTF-8 bytes (base64)',
|
|
197
|
-
parameters: [{ name: 'text', dataType: 'string', description: 'Text to encode', formInputType: 'text', required: true }],
|
|
198
|
-
returnType: 'string', returnDescription: 'Base64-encoded bytes', example: 'util.textEncode "hello"'
|
|
199
|
-
},
|
|
200
|
-
textDecode: {
|
|
201
|
-
description: 'Decode bytes (base64) to string',
|
|
202
|
-
parameters: [
|
|
203
|
-
{ name: 'data', dataType: 'string', description: 'Base64-encoded data', formInputType: 'text', required: true },
|
|
204
|
-
{ name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
|
|
205
|
-
],
|
|
206
|
-
returnType: 'string', returnDescription: 'Decoded string', example: 'util.textDecode $data'
|
|
207
|
-
},
|
|
208
|
-
deepClone: {
|
|
209
|
-
description: 'Deep clone any value',
|
|
210
|
-
parameters: [{ name: 'value', dataType: 'any', description: 'Value to clone', formInputType: 'json', required: true }],
|
|
211
|
-
returnType: 'any', returnDescription: 'Deep cloned value', example: 'util.deepClone $obj'
|
|
212
|
-
},
|
|
213
|
-
deepEqual: {
|
|
214
|
-
description: 'Deep equality comparison',
|
|
215
|
-
parameters: [
|
|
216
|
-
{ name: 'a', dataType: 'any', description: 'First value', formInputType: 'json', required: true },
|
|
217
|
-
{ name: 'b', dataType: 'any', description: 'Second value', formInputType: 'json', required: true }
|
|
218
|
-
],
|
|
219
|
-
returnType: 'boolean', returnDescription: 'true if deeply equal', example: 'util.deepEqual $a $b'
|
|
220
|
-
},
|
|
221
|
-
merge: {
|
|
222
|
-
description: 'Shallow merge objects',
|
|
223
|
-
parameters: [{ name: 'objects', dataType: 'object', description: 'Objects to merge', formInputType: 'json', required: true }],
|
|
224
|
-
returnType: 'object', returnDescription: 'Merged object', example: 'util.merge $a $b $c'
|
|
225
|
-
},
|
|
226
|
-
deepMerge: {
|
|
227
|
-
description: 'Deep merge objects (recursive)',
|
|
228
|
-
parameters: [{ name: 'objects', dataType: 'object', description: 'Objects to merge', formInputType: 'json', required: true }],
|
|
229
|
-
returnType: 'object', returnDescription: 'Deep merged object', example: 'util.deepMerge $a $b'
|
|
230
|
-
},
|
|
231
|
-
sizeof: {
|
|
232
|
-
description: 'Estimate byte size of a value',
|
|
233
|
-
parameters: [{ name: 'value', dataType: 'any', description: 'Value to measure', formInputType: 'json', required: true }],
|
|
234
|
-
returnType: 'number', returnDescription: 'Approximate byte size', example: 'util.sizeof "hello"'
|
|
235
|
-
},
|
|
236
|
-
formatWithOptions: {
|
|
237
|
-
description: 'Format with inspection options',
|
|
238
|
-
parameters: [
|
|
239
|
-
{ name: 'options', dataType: 'object', description: 'Inspection options', formInputType: 'json', required: true },
|
|
240
|
-
{ name: 'args', dataType: 'any', description: 'Format string + values', formInputType: 'text', required: true }
|
|
241
|
-
],
|
|
242
|
-
returnType: 'string', returnDescription: 'Formatted string', example: 'util.formatWithOptions {"colors":true} "value: %s" 42'
|
|
243
|
-
},
|
|
244
|
-
isUndefined: { description: 'Check if value is undefined', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if undefined', example: 'util.isUndefined $val' },
|
|
245
|
-
isNullOrUndefined: { description: 'Check if value is null or undefined', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if null or undefined', example: 'util.isNullOrUndefined $val' },
|
|
246
|
-
isFunction: { description: 'Check if value is a function', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if function', example: 'util.isFunction $val' },
|
|
247
|
-
isRegExp: { description: 'Check if value is a RegExp', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if RegExp', example: 'util.isRegExp $val' },
|
|
248
|
-
isDate: { description: 'Check if value is a Date', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Date', example: 'util.isDate $val' },
|
|
249
|
-
isError: { description: 'Check if value is an Error', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Error', example: 'util.isError $val' },
|
|
250
|
-
isPromise: { description: 'Check if value is a Promise', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Promise', example: 'util.isPromise $val' },
|
|
251
|
-
isMap: { description: 'Check if value is a Map', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Map', example: 'util.isMap $val' },
|
|
252
|
-
isSet: { description: 'Check if value is a Set', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Set', example: 'util.isSet $val' },
|
|
253
|
-
isTypedArray: { description: 'Check if value is a TypedArray', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if TypedArray', example: 'util.isTypedArray $val' },
|
|
254
|
-
isArrayBuffer: { description: 'Check if value is an ArrayBuffer', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if ArrayBuffer', example: 'util.isArrayBuffer $val' },
|
|
255
|
-
inherits: { description: 'Not needed in RobinPath — use object composition', parameters: [], returnType: 'string', returnDescription: 'Info message', example: 'util.inherits' },
|
|
256
|
-
deprecate: {
|
|
257
|
-
description: 'Log a deprecation warning',
|
|
258
|
-
parameters: [{ name: 'message', dataType: 'string', description: 'Deprecation message', formInputType: 'text', required: true }],
|
|
259
|
-
returnType: 'boolean', returnDescription: 'true', example: 'util.deprecate "Use newFunc instead"'
|
|
260
|
-
},
|
|
261
|
-
callbackify: { description: 'Not needed — RobinPath handles async natively', parameters: [], returnType: 'string', returnDescription: 'Info message', example: 'util.callbackify' }
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
export const UtilModuleMetadata = {
|
|
265
|
-
description: 'Utilities: inspect, format, type checks, deep clone/merge, text encoding, sizeof',
|
|
266
|
-
methods: Object.keys(UtilFunctions)
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
export default {
|
|
270
|
-
name: 'util',
|
|
271
|
-
functions: UtilFunctions,
|
|
272
|
-
functionMetadata: UtilFunctionMetadata,
|
|
273
|
-
moduleMetadata: UtilModuleMetadata,
|
|
274
|
-
global: false
|
|
275
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Native util module for RobinPath.
|
|
3
|
+
* Utility functions: inspect, format, types, promisify helpers.
|
|
4
|
+
*/
|
|
5
|
+
import { inspect, format, formatWithOptions, types, TextDecoder, TextEncoder } from 'node:util';
|
|
6
|
+
import { toStr, toNum, requireArgs } from './_helpers.js';
|
|
7
|
+
|
|
8
|
+
export const UtilFunctions = {
|
|
9
|
+
|
|
10
|
+
// --- Inspection & Formatting ---
|
|
11
|
+
|
|
12
|
+
inspect: (args) => {
|
|
13
|
+
requireArgs('util.inspect', args, 1);
|
|
14
|
+
const obj = args[0];
|
|
15
|
+
const opts = args[1] && typeof args[1] === 'object' ? args[1] : {};
|
|
16
|
+
return inspect(obj, {
|
|
17
|
+
depth: opts.depth != null ? toNum(opts.depth, 4) : 4,
|
|
18
|
+
colors: opts.colors !== false,
|
|
19
|
+
showHidden: opts.showHidden === true,
|
|
20
|
+
maxArrayLength: opts.maxArrayLength != null ? toNum(opts.maxArrayLength) : 100,
|
|
21
|
+
maxStringLength: opts.maxStringLength != null ? toNum(opts.maxStringLength) : 200,
|
|
22
|
+
compact: opts.compact !== false,
|
|
23
|
+
sorted: opts.sorted === true,
|
|
24
|
+
breakLength: opts.breakLength != null ? toNum(opts.breakLength) : 80
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
format: (args) => {
|
|
29
|
+
return format(...args.map(a => a));
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
formatWithOptions: (args) => {
|
|
33
|
+
requireArgs('util.formatWithOptions', args, 2);
|
|
34
|
+
const opts = args[0];
|
|
35
|
+
return formatWithOptions(opts, ...args.slice(1));
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
// --- Type Checks ---
|
|
39
|
+
|
|
40
|
+
isArray: (args) => Array.isArray(args[0]),
|
|
41
|
+
isBoolean: (args) => typeof args[0] === 'boolean',
|
|
42
|
+
isNull: (args) => args[0] === null,
|
|
43
|
+
isUndefined: (args) => args[0] === undefined,
|
|
44
|
+
isNullOrUndefined: (args) => args[0] == null,
|
|
45
|
+
isNumber: (args) => typeof args[0] === 'number',
|
|
46
|
+
isString: (args) => typeof args[0] === 'string',
|
|
47
|
+
isObject: (args) => typeof args[0] === 'object' && args[0] !== null,
|
|
48
|
+
isFunction: (args) => typeof args[0] === 'function',
|
|
49
|
+
isRegExp: (args) => args[0] instanceof RegExp,
|
|
50
|
+
isDate: (args) => args[0] instanceof Date,
|
|
51
|
+
isError: (args) => args[0] instanceof Error,
|
|
52
|
+
isPrimitive: (args) => {
|
|
53
|
+
const val = args[0];
|
|
54
|
+
return val === null || (typeof val !== 'object' && typeof val !== 'function');
|
|
55
|
+
},
|
|
56
|
+
isPromise: (args) => types.isPromise(args[0]),
|
|
57
|
+
isMap: (args) => types.isMap(args[0]),
|
|
58
|
+
isSet: (args) => types.isSet(args[0]),
|
|
59
|
+
isTypedArray: (args) => types.isTypedArray(args[0]),
|
|
60
|
+
isArrayBuffer: (args) => types.isArrayBuffer(args[0]),
|
|
61
|
+
|
|
62
|
+
typeOf: (args) => {
|
|
63
|
+
requireArgs('util.typeOf', args, 1);
|
|
64
|
+
const val = args[0];
|
|
65
|
+
if (val === null) return 'null';
|
|
66
|
+
if (Array.isArray(val)) return 'array';
|
|
67
|
+
return typeof val;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// --- Text Encoding ---
|
|
71
|
+
|
|
72
|
+
textEncode: (args) => {
|
|
73
|
+
requireArgs('util.textEncode', args, 1);
|
|
74
|
+
const encoder = new TextEncoder();
|
|
75
|
+
const encoded = encoder.encode(toStr(args[0]));
|
|
76
|
+
return Buffer.from(encoded).toString('base64');
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
textDecode: (args) => {
|
|
80
|
+
requireArgs('util.textDecode', args, 1);
|
|
81
|
+
const encoding = toStr(args[1], 'utf-8');
|
|
82
|
+
const decoder = new TextDecoder(encoding);
|
|
83
|
+
const buf = Buffer.from(toStr(args[0]), 'base64');
|
|
84
|
+
return decoder.decode(buf);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// --- Object Utilities ---
|
|
88
|
+
|
|
89
|
+
deepClone: (args) => {
|
|
90
|
+
requireArgs('util.deepClone', args, 1);
|
|
91
|
+
return structuredClone(args[0]);
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
deepEqual: (args) => {
|
|
95
|
+
requireArgs('util.deepEqual', args, 2);
|
|
96
|
+
try {
|
|
97
|
+
return JSON.stringify(args[0]) === JSON.stringify(args[1]);
|
|
98
|
+
} catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
merge: (args) => {
|
|
104
|
+
const result = {};
|
|
105
|
+
for (const arg of args) {
|
|
106
|
+
if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
|
|
107
|
+
Object.assign(result, arg);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
deepMerge: (args) => {
|
|
114
|
+
function _deepMerge(target, source) {
|
|
115
|
+
const result = { ...target };
|
|
116
|
+
for (const key of Object.keys(source)) {
|
|
117
|
+
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key]) &&
|
|
118
|
+
target[key] && typeof target[key] === 'object' && !Array.isArray(target[key])) {
|
|
119
|
+
result[key] = _deepMerge(target[key], source[key]);
|
|
120
|
+
} else {
|
|
121
|
+
result[key] = source[key];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
let result = {};
|
|
127
|
+
for (const arg of args) {
|
|
128
|
+
if (arg && typeof arg === 'object' && !Array.isArray(arg)) {
|
|
129
|
+
result = _deepMerge(result, arg);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
// --- String Utilities ---
|
|
136
|
+
|
|
137
|
+
inherits: () => {
|
|
138
|
+
// Not applicable in RobinPath — return info message
|
|
139
|
+
return 'util.inherits is not needed in RobinPath — use object composition instead';
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
deprecate: (args) => {
|
|
143
|
+
requireArgs('util.deprecate', args, 1);
|
|
144
|
+
console.error(`[DEPRECATED] ${toStr(args[0])}`);
|
|
145
|
+
return true;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
// --- Performance ---
|
|
149
|
+
|
|
150
|
+
callbackify: () => {
|
|
151
|
+
return 'util.callbackify is not needed — RobinPath handles async natively';
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
sizeof: (args) => {
|
|
155
|
+
requireArgs('util.sizeof', args, 1);
|
|
156
|
+
const val = args[0];
|
|
157
|
+
if (val === null || val === undefined) return 0;
|
|
158
|
+
if (typeof val === 'string') return Buffer.byteLength(val, 'utf-8');
|
|
159
|
+
if (typeof val === 'number') return 8;
|
|
160
|
+
if (typeof val === 'boolean') return 4;
|
|
161
|
+
try {
|
|
162
|
+
return Buffer.byteLength(JSON.stringify(val), 'utf-8');
|
|
163
|
+
} catch {
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export const UtilFunctionMetadata = {
|
|
170
|
+
inspect: {
|
|
171
|
+
description: 'Inspect any value with detailed formatting',
|
|
172
|
+
parameters: [
|
|
173
|
+
{ name: 'value', dataType: 'any', description: 'Value to inspect', formInputType: 'json', required: true },
|
|
174
|
+
{ name: 'options', dataType: 'object', description: 'Options: depth, colors, showHidden, compact, sorted', formInputType: 'json', required: false }
|
|
175
|
+
],
|
|
176
|
+
returnType: 'string', returnDescription: 'Formatted inspection string', example: 'util.inspect $obj'
|
|
177
|
+
},
|
|
178
|
+
format: {
|
|
179
|
+
description: 'Format a string with substitutions (%s, %d, %j, %o)',
|
|
180
|
+
parameters: [{ name: 'args', dataType: 'any', description: 'Format string + values', formInputType: 'text', required: true }],
|
|
181
|
+
returnType: 'string', returnDescription: 'Formatted string', example: 'util.format "Hello %s, you are %d" "World" 42'
|
|
182
|
+
},
|
|
183
|
+
typeOf: {
|
|
184
|
+
description: 'Get the type of a value (null, array, string, number, object, boolean)',
|
|
185
|
+
parameters: [{ name: 'value', dataType: 'any', description: 'Value to check', formInputType: 'json', required: true }],
|
|
186
|
+
returnType: 'string', returnDescription: 'Type string', example: 'util.typeOf [1,2,3]'
|
|
187
|
+
},
|
|
188
|
+
isArray: { description: 'Check if value is an array', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if array', example: 'util.isArray [1,2]' },
|
|
189
|
+
isBoolean: { description: 'Check if value is boolean', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if boolean', example: 'util.isBoolean true' },
|
|
190
|
+
isNull: { description: 'Check if value is null', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if null', example: 'util.isNull $val' },
|
|
191
|
+
isNumber: { description: 'Check if value is a number', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if number', example: 'util.isNumber 42' },
|
|
192
|
+
isString: { description: 'Check if value is a string', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if string', example: 'util.isString "hello"' },
|
|
193
|
+
isObject: { description: 'Check if value is an object (non-null)', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if object', example: 'util.isObject {"a":1}' },
|
|
194
|
+
isPrimitive: { description: 'Check if value is a primitive', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if primitive', example: 'util.isPrimitive 42' },
|
|
195
|
+
textEncode: {
|
|
196
|
+
description: 'Encode string to UTF-8 bytes (base64)',
|
|
197
|
+
parameters: [{ name: 'text', dataType: 'string', description: 'Text to encode', formInputType: 'text', required: true }],
|
|
198
|
+
returnType: 'string', returnDescription: 'Base64-encoded bytes', example: 'util.textEncode "hello"'
|
|
199
|
+
},
|
|
200
|
+
textDecode: {
|
|
201
|
+
description: 'Decode bytes (base64) to string',
|
|
202
|
+
parameters: [
|
|
203
|
+
{ name: 'data', dataType: 'string', description: 'Base64-encoded data', formInputType: 'text', required: true },
|
|
204
|
+
{ name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
|
|
205
|
+
],
|
|
206
|
+
returnType: 'string', returnDescription: 'Decoded string', example: 'util.textDecode $data'
|
|
207
|
+
},
|
|
208
|
+
deepClone: {
|
|
209
|
+
description: 'Deep clone any value',
|
|
210
|
+
parameters: [{ name: 'value', dataType: 'any', description: 'Value to clone', formInputType: 'json', required: true }],
|
|
211
|
+
returnType: 'any', returnDescription: 'Deep cloned value', example: 'util.deepClone $obj'
|
|
212
|
+
},
|
|
213
|
+
deepEqual: {
|
|
214
|
+
description: 'Deep equality comparison',
|
|
215
|
+
parameters: [
|
|
216
|
+
{ name: 'a', dataType: 'any', description: 'First value', formInputType: 'json', required: true },
|
|
217
|
+
{ name: 'b', dataType: 'any', description: 'Second value', formInputType: 'json', required: true }
|
|
218
|
+
],
|
|
219
|
+
returnType: 'boolean', returnDescription: 'true if deeply equal', example: 'util.deepEqual $a $b'
|
|
220
|
+
},
|
|
221
|
+
merge: {
|
|
222
|
+
description: 'Shallow merge objects',
|
|
223
|
+
parameters: [{ name: 'objects', dataType: 'object', description: 'Objects to merge', formInputType: 'json', required: true }],
|
|
224
|
+
returnType: 'object', returnDescription: 'Merged object', example: 'util.merge $a $b $c'
|
|
225
|
+
},
|
|
226
|
+
deepMerge: {
|
|
227
|
+
description: 'Deep merge objects (recursive)',
|
|
228
|
+
parameters: [{ name: 'objects', dataType: 'object', description: 'Objects to merge', formInputType: 'json', required: true }],
|
|
229
|
+
returnType: 'object', returnDescription: 'Deep merged object', example: 'util.deepMerge $a $b'
|
|
230
|
+
},
|
|
231
|
+
sizeof: {
|
|
232
|
+
description: 'Estimate byte size of a value',
|
|
233
|
+
parameters: [{ name: 'value', dataType: 'any', description: 'Value to measure', formInputType: 'json', required: true }],
|
|
234
|
+
returnType: 'number', returnDescription: 'Approximate byte size', example: 'util.sizeof "hello"'
|
|
235
|
+
},
|
|
236
|
+
formatWithOptions: {
|
|
237
|
+
description: 'Format with inspection options',
|
|
238
|
+
parameters: [
|
|
239
|
+
{ name: 'options', dataType: 'object', description: 'Inspection options', formInputType: 'json', required: true },
|
|
240
|
+
{ name: 'args', dataType: 'any', description: 'Format string + values', formInputType: 'text', required: true }
|
|
241
|
+
],
|
|
242
|
+
returnType: 'string', returnDescription: 'Formatted string', example: 'util.formatWithOptions {"colors":true} "value: %s" 42'
|
|
243
|
+
},
|
|
244
|
+
isUndefined: { description: 'Check if value is undefined', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if undefined', example: 'util.isUndefined $val' },
|
|
245
|
+
isNullOrUndefined: { description: 'Check if value is null or undefined', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if null or undefined', example: 'util.isNullOrUndefined $val' },
|
|
246
|
+
isFunction: { description: 'Check if value is a function', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if function', example: 'util.isFunction $val' },
|
|
247
|
+
isRegExp: { description: 'Check if value is a RegExp', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if RegExp', example: 'util.isRegExp $val' },
|
|
248
|
+
isDate: { description: 'Check if value is a Date', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Date', example: 'util.isDate $val' },
|
|
249
|
+
isError: { description: 'Check if value is an Error', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Error', example: 'util.isError $val' },
|
|
250
|
+
isPromise: { description: 'Check if value is a Promise', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Promise', example: 'util.isPromise $val' },
|
|
251
|
+
isMap: { description: 'Check if value is a Map', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Map', example: 'util.isMap $val' },
|
|
252
|
+
isSet: { description: 'Check if value is a Set', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if Set', example: 'util.isSet $val' },
|
|
253
|
+
isTypedArray: { description: 'Check if value is a TypedArray', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if TypedArray', example: 'util.isTypedArray $val' },
|
|
254
|
+
isArrayBuffer: { description: 'Check if value is an ArrayBuffer', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if ArrayBuffer', example: 'util.isArrayBuffer $val' },
|
|
255
|
+
inherits: { description: 'Not needed in RobinPath — use object composition', parameters: [], returnType: 'string', returnDescription: 'Info message', example: 'util.inherits' },
|
|
256
|
+
deprecate: {
|
|
257
|
+
description: 'Log a deprecation warning',
|
|
258
|
+
parameters: [{ name: 'message', dataType: 'string', description: 'Deprecation message', formInputType: 'text', required: true }],
|
|
259
|
+
returnType: 'boolean', returnDescription: 'true', example: 'util.deprecate "Use newFunc instead"'
|
|
260
|
+
},
|
|
261
|
+
callbackify: { description: 'Not needed — RobinPath handles async natively', parameters: [], returnType: 'string', returnDescription: 'Info message', example: 'util.callbackify' }
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export const UtilModuleMetadata = {
|
|
265
|
+
description: 'Utilities: inspect, format, type checks, deep clone/merge, text encoding, sizeof',
|
|
266
|
+
methods: Object.keys(UtilFunctions)
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
export default {
|
|
270
|
+
name: 'util',
|
|
271
|
+
functions: UtilFunctions,
|
|
272
|
+
functionMetadata: UtilFunctionMetadata,
|
|
273
|
+
moduleMetadata: UtilModuleMetadata,
|
|
274
|
+
global: false
|
|
275
|
+
};
|