@serveryyswys/node.operit 0.0.0-stage → 0.1.2

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.
Files changed (123) hide show
  1. package/BUILTINS.json +233 -0
  2. package/DESIGN.md +513 -0
  3. package/LICENSE +674 -0
  4. package/README.md +301 -2
  5. package/dist/assert/strict.d.ts +2 -0
  6. package/dist/assert/strict.js +7 -0
  7. package/dist/assert.d.ts +3 -0
  8. package/dist/assert.js +483 -0
  9. package/dist/buffer.d.ts +60 -0
  10. package/dist/buffer.js +524 -0
  11. package/dist/child_process.d.ts +56 -0
  12. package/dist/child_process.js +371 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/constants.js +19 -0
  15. package/dist/crypto.d.ts +76 -0
  16. package/dist/crypto.js +312 -0
  17. package/dist/dns/promises.d.ts +34 -0
  18. package/dist/dns/promises.js +190 -0
  19. package/dist/dns.d.ts +88 -0
  20. package/dist/dns.js +259 -0
  21. package/dist/events.d.ts +40 -0
  22. package/dist/events.js +237 -0
  23. package/dist/fs/promises.d.ts +159 -0
  24. package/dist/fs/promises.js +129 -0
  25. package/dist/fs.d.ts +221 -0
  26. package/dist/fs.js +944 -0
  27. package/dist/http.d.ts +92 -0
  28. package/dist/http.js +319 -0
  29. package/dist/https.d.ts +296 -0
  30. package/dist/https.js +50 -0
  31. package/dist/index.d.ts +2422 -0
  32. package/dist/index.js +57 -0
  33. package/dist/lib/bridge.d.ts +60 -0
  34. package/dist/lib/bridge.js +205 -0
  35. package/dist/lib/bytes.d.ts +20 -0
  36. package/dist/lib/bytes.js +239 -0
  37. package/dist/lib/child-process-types.d.ts +45 -0
  38. package/dist/lib/child-process-types.js +2 -0
  39. package/dist/lib/cwd.d.ts +2 -0
  40. package/dist/lib/cwd.js +32 -0
  41. package/dist/lib/deep-equal.d.ts +3 -0
  42. package/dist/lib/deep-equal.js +223 -0
  43. package/dist/lib/deflate.d.ts +2 -0
  44. package/dist/lib/deflate.js +234 -0
  45. package/dist/lib/dns-driver.d.ts +14 -0
  46. package/dist/lib/dns-driver.js +85 -0
  47. package/dist/lib/dns-types.d.ts +22 -0
  48. package/dist/lib/dns-types.js +2 -0
  49. package/dist/lib/errors.d.ts +48 -0
  50. package/dist/lib/errors.js +424 -0
  51. package/dist/lib/fs-driver.d.ts +70 -0
  52. package/dist/lib/fs-driver.js +364 -0
  53. package/dist/lib/fs-env.d.ts +30 -0
  54. package/dist/lib/fs-env.js +157 -0
  55. package/dist/lib/fs-types.d.ts +19 -0
  56. package/dist/lib/fs-types.js +2 -0
  57. package/dist/lib/hashes.d.ts +27 -0
  58. package/dist/lib/hashes.js +432 -0
  59. package/dist/lib/http-driver.d.ts +30 -0
  60. package/dist/lib/http-driver.js +72 -0
  61. package/dist/lib/http-types.d.ts +18 -0
  62. package/dist/lib/http-types.js +2 -0
  63. package/dist/lib/inflate.d.ts +6 -0
  64. package/dist/lib/inflate.js +284 -0
  65. package/dist/lib/path-types.d.ts +37 -0
  66. package/dist/lib/path-types.js +2 -0
  67. package/dist/lib/paths.d.ts +8 -0
  68. package/dist/lib/paths.js +106 -0
  69. package/dist/lib/perf-hooks-types.d.ts +18 -0
  70. package/dist/lib/perf-hooks-types.js +2 -0
  71. package/dist/lib/process-driver.d.ts +31 -0
  72. package/dist/lib/process-driver.js +102 -0
  73. package/dist/lib/punycode.d.ts +8 -0
  74. package/dist/lib/punycode.js +179 -0
  75. package/dist/lib/stream-types.d.ts +29 -0
  76. package/dist/lib/stream-types.js +2 -0
  77. package/dist/lib/timers-types.d.ts +18 -0
  78. package/dist/lib/timers-types.js +2 -0
  79. package/dist/lib/url-search-params.d.ts +26 -0
  80. package/dist/lib/url-search-params.js +281 -0
  81. package/dist/lib/url-types.d.ts +44 -0
  82. package/dist/lib/url-types.js +2 -0
  83. package/dist/lib/url-whatwg.d.ts +78 -0
  84. package/dist/lib/url-whatwg.js +857 -0
  85. package/dist/lib/zlib-types.d.ts +12 -0
  86. package/dist/lib/zlib-types.js +2 -0
  87. package/dist/module.d.ts +8 -0
  88. package/dist/module.js +72 -0
  89. package/dist/os.d.ts +80 -0
  90. package/dist/os.js +247 -0
  91. package/dist/path/posix.d.ts +2 -0
  92. package/dist/path/posix.js +7 -0
  93. package/dist/path/win32.d.ts +2 -0
  94. package/dist/path/win32.js +10 -0
  95. package/dist/path.d.ts +3 -0
  96. package/dist/path.js +1222 -0
  97. package/dist/perf_hooks.d.ts +36 -0
  98. package/dist/perf_hooks.js +144 -0
  99. package/dist/process.d.ts +69 -0
  100. package/dist/process.js +230 -0
  101. package/dist/querystring.d.ts +15 -0
  102. package/dist/querystring.js +209 -0
  103. package/dist/stream/promises.d.ts +5 -0
  104. package/dist/stream/promises.js +10 -0
  105. package/dist/stream.d.ts +84 -0
  106. package/dist/stream.js +875 -0
  107. package/dist/string_decoder.d.ts +15 -0
  108. package/dist/string_decoder.js +237 -0
  109. package/dist/timers/promises.d.ts +19 -0
  110. package/dist/timers/promises.js +74 -0
  111. package/dist/timers.d.ts +21 -0
  112. package/dist/timers.js +41 -0
  113. package/dist/tty.d.ts +9 -0
  114. package/dist/tty.js +25 -0
  115. package/dist/unsupported.d.ts +12 -0
  116. package/dist/unsupported.js +17 -0
  117. package/dist/url.d.ts +28 -0
  118. package/dist/url.js +486 -0
  119. package/dist/util.d.ts +74 -0
  120. package/dist/util.js +515 -0
  121. package/dist/zlib.d.ts +88 -0
  122. package/dist/zlib.js +371 -0
  123. package/package.json +29 -4
package/dist/util.js ADDED
@@ -0,0 +1,515 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ /**
36
+ * Node util 模块的移植。
37
+ *
38
+ * 重点在两处:
39
+ * - format():%s/%d/%i/%f/%j/%o/%O/%c 与"多余参数按 inspect 追加"的规则照搬
40
+ * - TextEncoder / TextDecoder:QuickJS 不保证提供,这里用 lib/bytes 自实现
41
+ *
42
+ * inspect 只对齐常用形态(原始值、扁平对象/数组、Map/Set/Date/RegExp/Error/Buffer、循环引用),
43
+ * Node 那套 compact / breakLength 折行算法没有照搬,见 BUILTINS.json 的 partial 说明。
44
+ */
45
+ const bytesCodec = __importStar(require("./lib/bytes"));
46
+ const errors_1 = require("./lib/errors");
47
+ const deep_equal_1 = require("./lib/deep-equal");
48
+ const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
49
+ const promisifyCustom = Symbol.for('nodejs.util.promisify.custom');
50
+ const DEFAULT_DEPTH = 2;
51
+ function quoteString(value, maxLength) {
52
+ let text = value;
53
+ const truncated = maxLength !== undefined && maxLength !== null && text.length > maxLength;
54
+ if (truncated && maxLength !== undefined && maxLength !== null) {
55
+ text = text.slice(0, maxLength);
56
+ }
57
+ let out = "'";
58
+ for (let i = 0; i < text.length; i += 1) {
59
+ const code = text.charCodeAt(i);
60
+ if (code === 39) {
61
+ out += "\\'";
62
+ }
63
+ else if (code === 92) {
64
+ out += '\\\\';
65
+ }
66
+ else if (code === 10) {
67
+ out += '\\n';
68
+ }
69
+ else if (code === 13) {
70
+ out += '\\r';
71
+ }
72
+ else if (code === 9) {
73
+ out += '\\t';
74
+ }
75
+ else if (code < 32) {
76
+ out += '\\x' + pad2(code.toString(16));
77
+ }
78
+ else {
79
+ out += text.charAt(i);
80
+ }
81
+ }
82
+ out += "'";
83
+ if (truncated && maxLength !== undefined && maxLength !== null) {
84
+ out = out.slice(0, out.length - 1) + "... " + (value.length - maxLength) + ' more characters' + "'";
85
+ }
86
+ return out;
87
+ }
88
+ function pad2(value) {
89
+ return value.length >= 2 ? value : '0' + value;
90
+ }
91
+ function functionLabel(value) {
92
+ const name = typeof value.name === 'string' && value.name.length > 0 ? value.name : '';
93
+ const kind = /^class[\s{]/.test(Function.prototype.toString.call(value)) ? 'class' : 'Function';
94
+ return name.length > 0 ? '[Function: ' + name + ']' : '[Function (anonymous)]';
95
+ }
96
+ function inspectValue(value, options, depth, seen) {
97
+ const maxDepth = options.depth === null || options.depth === undefined ? DEFAULT_DEPTH : options.depth;
98
+ if (value === null) {
99
+ return 'null';
100
+ }
101
+ switch (typeof value) {
102
+ case 'undefined':
103
+ return 'undefined';
104
+ case 'boolean':
105
+ return value ? 'true' : 'false';
106
+ case 'number':
107
+ if (Number.isNaN(value)) {
108
+ return 'NaN';
109
+ }
110
+ if (value === Infinity) {
111
+ return 'Infinity';
112
+ }
113
+ if (value === -Infinity) {
114
+ return '-Infinity';
115
+ }
116
+ return Object.is(value, -0) ? '-0' : String(value);
117
+ case 'bigint':
118
+ return String(value) + 'n';
119
+ case 'symbol':
120
+ return value.toString();
121
+ case 'string':
122
+ return quoteString(value, options.maxStringLength);
123
+ case 'function':
124
+ return functionLabel(value);
125
+ default:
126
+ break;
127
+ }
128
+ const object = value;
129
+ const custom = object[inspectCustom];
130
+ if (typeof custom === 'function') {
131
+ return String(custom.call(object));
132
+ }
133
+ if (seen.indexOf(object) >= 0) {
134
+ return '[Circular]';
135
+ }
136
+ if (maxDepth >= 0 && depth > maxDepth) {
137
+ return Array.isArray(object) ? '[Array]' : '[Object]';
138
+ }
139
+ seen.push(object);
140
+ try {
141
+ if (object instanceof Date) {
142
+ return Number.isNaN(object.getTime()) ? 'Invalid Date' : object.toISOString();
143
+ }
144
+ if (object instanceof RegExp) {
145
+ return object.toString();
146
+ }
147
+ if (object instanceof Error) {
148
+ return object.stack !== undefined && typeof object.stack === 'string'
149
+ ? object.stack
150
+ : object.name + ': ' + object.message;
151
+ }
152
+ if (object instanceof Uint8Array) {
153
+ const limit = Math.min(object.length, 50);
154
+ let out = '<Buffer';
155
+ for (let i = 0; i < limit; i += 1) {
156
+ out += ' ' + pad2(object[i].toString(16));
157
+ }
158
+ if (object.length > limit) {
159
+ out += ' ... ' + (object.length - limit) + ' more bytes';
160
+ }
161
+ return out + '>';
162
+ }
163
+ if (object instanceof Map) {
164
+ const parts = [];
165
+ object.forEach(function (entryValue, entryKey) {
166
+ parts.push(inspectValue(entryKey, options, depth + 1, seen) + ' => ' + inspectValue(entryValue, options, depth + 1, seen));
167
+ });
168
+ return formatCollection('Map(' + object.size + ') ', parts, options, depth, '{}');
169
+ }
170
+ if (object instanceof Set) {
171
+ const parts = [];
172
+ object.forEach(function (entryValue) {
173
+ parts.push(inspectValue(entryValue, options, depth + 1, seen));
174
+ });
175
+ return formatCollection('Set(' + object.size + ') ', parts, options, depth, '{}');
176
+ }
177
+ if (Array.isArray(object)) {
178
+ const limit = options.maxArrayLength === undefined ? object.length : Math.min(object.length, options.maxArrayLength);
179
+ const parts = [];
180
+ for (let i = 0; i < limit; i += 1) {
181
+ parts.push(inspectValue(object[i], options, depth + 1, seen));
182
+ }
183
+ if (limit < object.length) {
184
+ parts.push('... ' + (object.length - limit) + ' more items');
185
+ }
186
+ return formatCollection('', parts, options, depth, '[]');
187
+ }
188
+ const keys = Object.keys(object);
189
+ if (options.sorted === true) {
190
+ keys.sort();
191
+ }
192
+ const parts = [];
193
+ for (let i = 0; i < keys.length; i += 1) {
194
+ const key = keys[i];
195
+ parts.push(formatKey(key) + ': ' + inspectValue(object[key], options, depth + 1, seen));
196
+ }
197
+ return formatCollection('', parts, options, depth, '{}');
198
+ }
199
+ finally {
200
+ seen.pop();
201
+ }
202
+ }
203
+ /**
204
+ * 集合的统一排版。
205
+ * compact === false 时强制多行(Node 的 inspect 也是这个开关),
206
+ * 缩进按递归深度算,所以嵌套时每层多缩进两格。
207
+ */
208
+ function formatCollection(head, parts, options, depth, brackets) {
209
+ const open = brackets.charAt(0);
210
+ const close = brackets.charAt(1);
211
+ if (parts.length === 0) {
212
+ return head + open + close;
213
+ }
214
+ if (options.compact === false) {
215
+ const inner = ' '.repeat(depth + 1);
216
+ const outer = ' '.repeat(depth);
217
+ return head + open + '\n' + inner + parts.join(',\n' + inner) + '\n' + outer + close;
218
+ }
219
+ return head + open + ' ' + parts.join(', ') + ' ' + close;
220
+ }
221
+ function formatKey(key) {
222
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : quoteString(key);
223
+ }
224
+ function inspect(value, options) {
225
+ let normalized = {};
226
+ if (typeof options === 'boolean') {
227
+ normalized = { colors: options };
228
+ }
229
+ else if (typeof options === 'number') {
230
+ normalized = { depth: options };
231
+ }
232
+ else if (options !== null && typeof options === 'object') {
233
+ normalized = options;
234
+ }
235
+ return inspectValue(value, normalized, 0, []);
236
+ }
237
+ inspect.custom = inspectCustom;
238
+ function jsonOf(value) {
239
+ try {
240
+ const encoded = JSON.stringify(value);
241
+ return encoded === undefined ? 'undefined' : encoded;
242
+ }
243
+ catch (failure) {
244
+ return '[Circular]';
245
+ }
246
+ }
247
+ function formatWithOptions(options, template, ...rest) {
248
+ const args = [template].concat(rest);
249
+ const first = args[0];
250
+ const inspectOptions = options === undefined || options === null ? {} : options;
251
+ if (typeof first !== 'string') {
252
+ return args.map(function (value) {
253
+ return typeof value === 'string' ? value : inspectValue(value, inspectOptions, 0, []);
254
+ }).join(' ');
255
+ }
256
+ if (args.length === 1) {
257
+ return first;
258
+ }
259
+ let out = '';
260
+ let lastPosition = 0;
261
+ let consumed = 0;
262
+ for (let i = 0; i < first.length; i += 1) {
263
+ if (first.charCodeAt(i) !== 37) {
264
+ continue;
265
+ }
266
+ let replacement = null;
267
+ const specifier = first.charCodeAt(i + 1);
268
+ if (specifier === 37) {
269
+ // %%
270
+ replacement = '%';
271
+ }
272
+ else if (consumed + 1 >= args.length) {
273
+ // 参数不足时占位符原样保留(Node: format('%s %s', 'a') === 'a %s')
274
+ continue;
275
+ }
276
+ else {
277
+ switch (specifier) {
278
+ case 115:
279
+ replacement = String(args[++consumed]);
280
+ break;
281
+ case 100:
282
+ replacement = String(Number(args[++consumed]));
283
+ break;
284
+ case 105:
285
+ replacement = String(parseInt(String(args[++consumed]), 10));
286
+ break;
287
+ case 102:
288
+ replacement = String(parseFloat(String(args[++consumed])));
289
+ break;
290
+ case 106:
291
+ replacement = jsonOf(args[++consumed]);
292
+ break;
293
+ case 111:
294
+ replacement = inspectValue(args[++consumed], { showHidden: true, showProxy: true, depth: 4, colors: inspectOptions.colors }, 0, []);
295
+ break;
296
+ case 79:
297
+ replacement = inspectValue(args[++consumed], inspectOptions, 0, []);
298
+ break;
299
+ case 99:
300
+ // %c 是 CSS 占位符:消费参数但输出空串
301
+ consumed += 1;
302
+ replacement = '';
303
+ break;
304
+ default:
305
+ continue;
306
+ }
307
+ }
308
+ if (i > lastPosition) {
309
+ out += first.slice(lastPosition, i);
310
+ }
311
+ out += replacement;
312
+ i += 1;
313
+ lastPosition = i + 1;
314
+ }
315
+ if (lastPosition < first.length) {
316
+ out += first.slice(lastPosition);
317
+ }
318
+ for (let index = consumed + 1; index < args.length; index += 1) {
319
+ const extra = args[index];
320
+ // 多余参数:字符串按原样追加,其余走 inspect
321
+ out += ' ' + (typeof extra === 'string' ? extra : inspectValue(extra, inspectOptions, 0, []));
322
+ }
323
+ return out;
324
+ }
325
+ function format(template, ...rest) {
326
+ return formatWithOptions({}, template, ...rest);
327
+ }
328
+ function inherits(constructor, superConstructor) {
329
+ if (constructor === undefined || constructor === null) {
330
+ throw new TypeError('The "constructor" argument must be a function.');
331
+ }
332
+ if (superConstructor === undefined || superConstructor === null) {
333
+ throw new TypeError('The "superConstructor" argument must be a function.');
334
+ }
335
+ Object.setPrototypeOf(constructor.prototype, superConstructor.prototype);
336
+ Object.setPrototypeOf(constructor, superConstructor);
337
+ constructor.super_ = superConstructor;
338
+ }
339
+ function promisify(original) {
340
+ if (typeof original !== 'function') {
341
+ throw new TypeError('The "original" argument must be of type function.');
342
+ }
343
+ const custom = original[promisifyCustom];
344
+ if (custom !== undefined) {
345
+ return custom;
346
+ }
347
+ function fn(...args) {
348
+ const self = this;
349
+ return new Promise(function (resolve, reject) {
350
+ args.push(function (error, value) {
351
+ if (error !== null && error !== undefined) {
352
+ reject(error);
353
+ }
354
+ else {
355
+ resolve(value);
356
+ }
357
+ });
358
+ original.apply(self, args);
359
+ });
360
+ }
361
+ Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
362
+ Object.defineProperty(fn, promisifyCustom, { value: custom, configurable: true });
363
+ return fn;
364
+ }
365
+ promisify.custom = promisifyCustom;
366
+ function callbackify(original) {
367
+ if (typeof original !== 'function') {
368
+ throw new TypeError('The "original" argument must be of type function.');
369
+ }
370
+ return function (...args) {
371
+ const callback = args.pop();
372
+ if (typeof callback !== 'function') {
373
+ throw new TypeError('The last argument must be of type function.');
374
+ }
375
+ const runner = callback;
376
+ original.apply(this, args).then(function (value) {
377
+ queueMicrotask(function () {
378
+ runner(null, value);
379
+ });
380
+ }, function (error) {
381
+ queueMicrotask(function () {
382
+ runner(error);
383
+ });
384
+ });
385
+ };
386
+ }
387
+ function deprecate(fn, message) {
388
+ let warned = false;
389
+ return function (...args) {
390
+ if (!warned) {
391
+ warned = true;
392
+ const target = fn.name;
393
+ console.warn('DeprecationWarning: ' + message + (target !== undefined ? ' [' + target + ']' : ''));
394
+ }
395
+ return fn.apply(this, args);
396
+ };
397
+ }
398
+ function debuglog(section) {
399
+ void section;
400
+ const logger = function () {
401
+ // Node 只在 NODE_DEBUG 命中时输出;这里没有环境变量通道,默认静默。
402
+ };
403
+ logger.enabled = false;
404
+ return logger;
405
+ }
406
+ function getSystemErrorName(errno) {
407
+ const names = Object.keys(errors_1.ERRNO);
408
+ for (let i = 0; i < names.length; i += 1) {
409
+ if (errors_1.ERRNO[names[i]] === errno) {
410
+ return names[i];
411
+ }
412
+ }
413
+ return 'Unknown system error ' + errno;
414
+ }
415
+ function stripVTControlCharacters(value) {
416
+ return String(value).replace(/\u001b\[[0-9;]*m/g, '');
417
+ }
418
+ const types = {
419
+ isDate: function (value) {
420
+ return value instanceof Date;
421
+ },
422
+ isRegExp: function (value) {
423
+ return value instanceof RegExp;
424
+ },
425
+ isArray: function (value) {
426
+ return Array.isArray(value);
427
+ },
428
+ isTypedArray: function (value) {
429
+ return value instanceof Uint8Array || value instanceof Int8Array ||
430
+ value instanceof Uint16Array || value instanceof Int16Array ||
431
+ value instanceof Uint32Array || value instanceof Int32Array ||
432
+ value instanceof Float32Array || value instanceof Float64Array;
433
+ },
434
+ isUint8Array: function (value) {
435
+ return value instanceof Uint8Array;
436
+ },
437
+ isArrayBuffer: function (value) {
438
+ return value instanceof ArrayBuffer;
439
+ },
440
+ isPromise: function (value) {
441
+ return value !== null && typeof value === 'object' &&
442
+ typeof value.then === 'function';
443
+ },
444
+ isNativeError: function (value) {
445
+ return value instanceof Error;
446
+ },
447
+ isMap: function (value) {
448
+ return value instanceof Map;
449
+ },
450
+ isSet: function (value) {
451
+ return value instanceof Set;
452
+ },
453
+ isBigInt64Array: function (value) {
454
+ return typeof BigInt64Array !== 'undefined' && value instanceof BigInt64Array;
455
+ },
456
+ isAsyncFunction: function (value) {
457
+ return typeof value === 'function' && value.constructor !== undefined &&
458
+ value.constructor.name === 'AsyncFunction';
459
+ },
460
+ isGeneratorFunction: function (value) {
461
+ return typeof value === 'function' && value.constructor !== undefined &&
462
+ value.constructor.name === 'GeneratorFunction';
463
+ }
464
+ };
465
+ function isDeepStrictEqual(left, right) {
466
+ return (0, deep_equal_1.isDeepStrictEqual)(left, right);
467
+ }
468
+ class TextEncoder {
469
+ constructor() {
470
+ this.encoding = 'utf-8';
471
+ }
472
+ encode(input) {
473
+ return bytesCodec.utf8Encode(input === undefined ? '' : String(input));
474
+ }
475
+ encodeInto(source, destination) {
476
+ const encoded = bytesCodec.utf8Encode(String(source));
477
+ const writable = Math.min(encoded.length, destination.length);
478
+ destination.set(encoded.subarray(0, writable));
479
+ return { read: writable === encoded.length ? source.length : source.length, written: writable };
480
+ }
481
+ }
482
+ class TextDecoder {
483
+ constructor(label, options) {
484
+ const normalized = (label === undefined ? 'utf-8' : String(label)).toLowerCase();
485
+ if (normalized !== 'utf-8' && normalized !== 'utf8') {
486
+ throw new RangeError('node.operit 的 TextDecoder 只支持 utf-8,收到 ' + normalized);
487
+ }
488
+ this.encoding = 'utf-8';
489
+ this.fatal = options !== undefined && options.fatal === true;
490
+ this.ignoreBOM = options !== undefined && options.ignoreBOM === true;
491
+ }
492
+ decode(input) {
493
+ if (input === undefined) {
494
+ return '';
495
+ }
496
+ return bytesCodec.utf8Decode(input);
497
+ }
498
+ }
499
+ const util = {
500
+ format: format,
501
+ formatWithOptions: formatWithOptions,
502
+ inspect: inspect,
503
+ inherits: inherits,
504
+ promisify: promisify,
505
+ callbackify: callbackify,
506
+ deprecate: deprecate,
507
+ debuglog: debuglog,
508
+ getSystemErrorName: getSystemErrorName,
509
+ stripVTControlCharacters: stripVTControlCharacters,
510
+ isDeepStrictEqual: isDeepStrictEqual,
511
+ types: types,
512
+ TextEncoder: TextEncoder,
513
+ TextDecoder: TextDecoder
514
+ };
515
+ module.exports = util;
package/dist/zlib.d.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { Buffer } from './buffer';
2
+ import streamModule = require('./stream');
3
+ import type { DeflateOptions } from './lib/zlib-types';
4
+ /** 从 stream 模块取 Transform 实例类型,避免在 `export =` 的模块里命名内部类。 */
5
+ type ZlibStream = InstanceType<typeof streamModule.Transform>;
6
+ declare function deflateSync(input: unknown, options?: DeflateOptions): Buffer;
7
+ declare function inflateSync(input: unknown): Buffer;
8
+ declare function deflateRawSync(input: unknown, options?: DeflateOptions): Buffer;
9
+ declare function inflateRawSync(input: unknown): Buffer;
10
+ declare function gzipSync(input: unknown, options?: DeflateOptions): Buffer;
11
+ declare function gunzipSync(input: unknown): Buffer;
12
+ /** 自动识别 zlib / gzip 两种包装,对应 Node 的 unzip 系列。 */
13
+ declare function unzipSync(input: unknown): Buffer;
14
+ type NodeCallback = (error: Error | null, result?: Buffer) => void;
15
+ declare function deflate(input: unknown, options?: DeflateOptions | NodeCallback, callback?: NodeCallback): void;
16
+ declare function inflate(input: unknown, options?: NodeCallback, callback?: NodeCallback): void;
17
+ declare function deflateRawAsync(input: unknown, options?: DeflateOptions | NodeCallback, callback?: NodeCallback): void;
18
+ declare function inflateRawAsync(input: unknown, options?: NodeCallback, callback?: NodeCallback): void;
19
+ declare function gzip(input: unknown, options?: DeflateOptions | NodeCallback, callback?: NodeCallback): void;
20
+ declare function gunzip(input: unknown, options?: NodeCallback, callback?: NodeCallback): void;
21
+ declare const zlib: {
22
+ deflateSync: typeof deflateSync;
23
+ inflateSync: typeof inflateSync;
24
+ deflateRawSync: typeof deflateRawSync;
25
+ inflateRawSync: typeof inflateRawSync;
26
+ gzipSync: typeof gzipSync;
27
+ gunzipSync: typeof gunzipSync;
28
+ unzipSync: typeof unzipSync;
29
+ deflate: typeof deflate;
30
+ inflate: typeof inflate;
31
+ deflateRaw: typeof deflateRawAsync;
32
+ inflateRaw: typeof inflateRawAsync;
33
+ gzip: typeof gzip;
34
+ gunzip: typeof gunzip;
35
+ createDeflate: (options?: DeflateOptions) => ZlibStream;
36
+ createInflate: () => ZlibStream;
37
+ createDeflateRaw: (options?: DeflateOptions) => ZlibStream;
38
+ createInflateRaw: () => ZlibStream;
39
+ createGzip: (options?: DeflateOptions) => ZlibStream;
40
+ createGunzip: () => ZlibStream;
41
+ createUnzip: () => ZlibStream;
42
+ constants: {
43
+ DEFLATE: number;
44
+ INFLATE: number;
45
+ GZIP: number;
46
+ GUNZIP: number;
47
+ DEFLATERAW: number;
48
+ INFLATERAW: number;
49
+ UNZIP: number;
50
+ Z_MIN_CHUNK: number;
51
+ Z_MAX_CHUNK: number;
52
+ Z_DEFAULT_CHUNK: number;
53
+ Z_MIN_MEMLEVEL: number;
54
+ Z_MAX_MEMLEVEL: number;
55
+ Z_DEFAULT_MEMLEVEL: number;
56
+ Z_MIN_LEVEL: number;
57
+ Z_MAX_LEVEL: number;
58
+ Z_DEFAULT_LEVEL: number;
59
+ Z_NO_FLUSH: number;
60
+ Z_PARTIAL_FLUSH: number;
61
+ Z_SYNC_FLUSH: number;
62
+ Z_FULL_FLUSH: number;
63
+ Z_FINISH: number;
64
+ Z_BLOCK: number;
65
+ Z_OK: number;
66
+ Z_STREAM_END: number;
67
+ Z_NEED_DICT: number;
68
+ Z_ERRNO: number;
69
+ Z_STREAM_ERROR: number;
70
+ Z_DATA_ERROR: number;
71
+ Z_MEM_ERROR: number;
72
+ Z_BUF_ERROR: number;
73
+ Z_VERSION_ERROR: number;
74
+ Z_NO_COMPRESSION: number;
75
+ Z_BEST_SPEED: number;
76
+ Z_BEST_COMPRESSION: number;
77
+ Z_DEFAULT_COMPRESSION: number;
78
+ Z_DEFAULT_STRATEGY: number;
79
+ Z_FILTERED: number;
80
+ Z_HUFFMAN_ONLY: number;
81
+ Z_RLE: number;
82
+ Z_FIXED: number;
83
+ Z_MIN_WINDOWBITS: number;
84
+ Z_MAX_WINDOWBITS: number;
85
+ Z_DEFAULT_WINDOWBITS: number;
86
+ };
87
+ };
88
+ export = zlib;