@e-mc/types 0.11.7 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/types
2
2
 
3
- * NodeJS 16 LTS
4
- * ES2021
3
+ * NodeJS 18
4
+ * ES2022
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,13 +9,13 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.11.7/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.0/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogArguments } from "./lib/logger";
16
16
  import type { HighResolutionTime } from "./lib/node";
17
17
 
18
- import type { BinaryLike, CipherGCMTypes, Encoding, RandomUUIDOptions } from "node:crypto";
18
+ import type { BinaryLike, CipherGCMTypes, Encoding } from "node:crypto";
19
19
  import type { BytesOptions } from "bytes";
20
20
 
21
21
  function createAbortError(reject: true): Promise<never>;
@@ -32,12 +32,13 @@ function existsFlag(value: unknown): boolean;
32
32
  function getLogCurrent(): LogArguments | null;
33
33
  function setLogCurrent(value: LogArguments): void;
34
34
  function setTempDir(value: string): boolean;
35
- function getTempDir(): string;
35
+ function getTempDir(...values: string[]): string;
36
36
  function isArray(value: unknown): value is unknown[];
37
37
  function isObject(value: unknown): value is object;
38
38
  function isPlainObject(value: unknown): value is Record<string | number | symbol, unknown>;
39
39
  function isString(value: unknown): value is string;
40
40
  function isEmpty(value: unknown): boolean;
41
+ function isFunction<T extends Function>(value: unknown, cjs?: boolean): value is T;
41
42
  function asFunction(value: unknown, sync?: boolean): ((...args: unknown[]) => unknown) | null;
42
43
  function parseTime(value: number | string, start?: number): number;
43
44
  function parseExpires(value: number | string, start?: number): number;
@@ -62,10 +63,11 @@ function getEncoding(value: unknown, fallback?: BufferEncoding): BufferEncoding;
62
63
  function encryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
63
64
  function decryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
64
65
  function hashKey(data: BinaryLike, algorithm?: string, encoding?: BinaryToTextEncoding): string;
65
- /** @deprecated - crypto.randomUUID */
66
- function generateUUID(options?: RandomUUIDOptions): string;
67
66
  function incrementUUID(restart?: boolean): string;
68
67
  function validateUUID(value: unknown): boolean;
68
+ function sanitizeCmd(value: string): string;
69
+ function sanitizeArgs(value: string, doubleQuote?: boolean): string;
70
+ function sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
69
71
  function randomString(format: string, dictionary?: string): string;
70
72
  function errorValue(value: string, hint?: string): Error;
71
73
  function errorMessage(title: number | string, value: string, hint?: string): Error;
@@ -198,10 +200,10 @@ const IMPORT_MAP: Record<string, string | undefined>;
198
200
 
199
201
  ## References
200
202
 
201
- - https://www.unpkg.com/@e-mc/types@0.11.7/index.d.ts
202
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/logger.d.ts
203
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/module.d.ts
204
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/node.d.ts
203
+ - https://www.unpkg.com/@e-mc/types@0.12.0/index.d.ts
204
+ - https://www.unpkg.com/@e-mc/types@0.12.0/lib/logger.d.ts
205
+ - https://www.unpkg.com/@e-mc/types@0.12.0/lib/module.d.ts
206
+ - https://www.unpkg.com/@e-mc/types@0.12.0/lib/node.d.ts
205
207
 
206
208
  * https://developer.mozilla.org/en-US/docs/Web/API/DOMException
207
209
  * https://www.npmjs.com/package/@types/bytes
package/constant.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.11.7',
2
+ VERSION = '0.12.0',
3
3
  TEMP_DIR = 'tmp',
4
4
  CJS = '__cjs__'
5
5
  }
@@ -48,6 +48,7 @@ export const enum ERR_MESSAGE {
48
48
  FAILED_CHECKSUM = 'Checksum did not match',
49
49
  PARAMETERS = 'Invalid parameters',
50
50
  FORMAT = 'Invalid format',
51
+ COMMAND = 'Invalid command',
51
52
  CHECKSUM = 'Invalid checksum',
52
53
  CONFIG = 'Invalid config',
53
54
  RESPONSE = 'Invalid response',
@@ -66,6 +67,9 @@ export const enum ERR_MESSAGE {
66
67
  INCOMPLETE = 'Transaction was not completed',
67
68
  THREAD = 'Thread limit exceeded',
68
69
  THREAD_KILLED = 'Thread was killed',
70
+ WORKER = 'Worker did not finish',
71
+ WORKER_TIMEOUT = 'Worker timeout was exceeded',
72
+ WORKER_FULL = 'Worker queue is full',
69
73
  TIMEOUT = 'Timeout was exceeded',
70
74
  HANDLED_REJECTION = 'Handled rejection',
71
75
  UNSUPPORTED_ACCESS = 'Unsupported access',
@@ -73,6 +77,7 @@ export const enum ERR_MESSAGE {
73
77
  UNSUPPORTED_MIME = 'Unsupported MIME',
74
78
  UNSUPPORTED_READ = 'Not permitted to read file',
75
79
  UNSUPPORTED_WRITE = 'Not permitted to write file',
80
+ UNSUPPORTED_OVERWRITE = 'Not permitted to overwrite file',
76
81
  NOTFOUND_PATH = 'Path not found',
77
82
  NOTFOUND_FILE = 'File not found',
78
83
  NOTFOUND_BINARY = 'Binary not found',
@@ -315,6 +320,7 @@ export const enum SETTINGS_KEY_NAME {
315
320
  TEMP_WRITE = "temp.write",
316
321
  PROCESS_PASSWORD = "process.password",
317
322
  PROCESS_ENV_APPLY = "process.env.apply",
323
+ PROCESS_THREAD_WORKER_USERS = "process.thread.worker.users",
318
324
  PROCESS_CIPHER_ALGORITHM = "process.cipher.algorithm",
319
325
  PERMISSION_PROCESS_EXEC = "permission.process_exec",
320
326
  PERMISSION_HOMEREAD = "permission.home_read",
package/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  import type { LogArguments } from './lib/logger';
5
5
  import type { HighResolutionTime } from './lib/node';
6
6
 
7
- import type { BinaryLike, BinaryToTextEncoding, CipherGCMTypes, Encoding, RandomUUIDOptions } from 'node:crypto';
7
+ import type { BinaryLike, BinaryToTextEncoding, CipherGCMTypes, Encoding } from 'node:crypto';
8
8
 
9
9
  // @ts-ignore
10
10
  import type { BytesOptions } from 'bytes';
@@ -140,6 +140,7 @@ declare namespace types {
140
140
 
141
141
  interface ERR_CODE {
142
142
  MODULE_NOT_FOUND: "MODULE_NOT_FOUND";
143
+ ERR_MODULE_NOT_FOUND: "ERR_MODULE_NOT_FOUND";
143
144
  }
144
145
 
145
146
  const ERR_CODE: {
@@ -272,6 +273,8 @@ declare namespace types {
272
273
  mergeArray?: MergeArrayMethod;
273
274
  mergeDepth?: number;
274
275
  typedArray?: boolean;
276
+ structured?: boolean;
277
+ shared?: boolean;
275
278
  symbol?: boolean;
276
279
  inherited?: boolean;
277
280
  nonenumerable?: boolean;
@@ -295,12 +298,13 @@ declare namespace types {
295
298
  function getLogCurrent(): LogArguments | null;
296
299
  function setLogCurrent(value: LogArguments | null): void;
297
300
  function setTempDir(value: string): boolean;
298
- function getTempDir(): string;
301
+ function getTempDir(...values: string[]): string;
299
302
  function isArray<T>(value: unknown): value is T[];
300
- function isObject<T = object>(value: unknown): value is T;
303
+ function isObject<T extends object>(value: unknown): value is T;
301
304
  function isPlainObject<T = PlainObject>(value: unknown): value is T;
302
- function isString(value: unknown): value is string;
305
+ function isString<T extends string>(value: unknown): value is T;
303
306
  function isEmpty(value: unknown): boolean;
307
+ function isFunction<T extends Function>(value: unknown, cjs?: boolean): value is T;
304
308
  function asFunction<U = unknown, V = unknown>(value: unknown, sync?: boolean): FunctionType<U, V> | null;
305
309
  function parseTime(value: number | string, start?: number): number;
306
310
  function parseExpires(value: number | string, start?: number): number;
@@ -325,11 +329,12 @@ declare namespace types {
325
329
  function encryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
326
330
  function decryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
327
331
  function hashKey(data: BinaryLike, algorithm?: string, encoding?: BinaryToTextEncoding): string;
328
- /** @deprecated - crypto.randomUUID */
329
- function generateUUID(options?: RandomUUIDOptions): string;
330
332
  function incrementUUID(restart?: boolean): string;
331
333
  function validateUUID(value: unknown): boolean;
332
334
  function randomString(format: string, dictionary?: string): string;
335
+ function sanitizeCmd(value: string): string;
336
+ function sanitizeArgs(value: string, doubleQuote?: boolean): string;
337
+ function sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
333
338
  function errorValue(value: string, hint?: string): Error;
334
339
  function errorMessage(title: number | string, value: string, hint?: string): Error;
335
340
  function supported(major: number, minor: number, lts: boolean): boolean;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- exports.generateUUID = exports.IMPORT_MAP = exports.THRESHOLD = exports.READDIR_SORT = exports.WATCH_EVENT = exports.TRANSFER_TYPE = exports.DB_TRANSACTION = exports.DB_TYPE = exports.FETCH_TYPE = exports.DOWNLOAD_TYPE = exports.ERR_CODE = exports.ASSET_FLAG = exports.FILE_TYPE = exports.STATUS_TYPE = exports.LOG_STATE = exports.LOG_TYPE = void 0;
2
+ exports.IMPORT_MAP = exports.THRESHOLD = exports.READDIR_SORT = exports.WATCH_EVENT = exports.TRANSFER_TYPE = exports.DB_TRANSACTION = exports.DB_TYPE = exports.FETCH_TYPE = exports.DOWNLOAD_TYPE = exports.ERR_CODE = exports.ASSET_FLAG = exports.FILE_TYPE = exports.STATUS_TYPE = exports.LOG_STATE = exports.LOG_TYPE = void 0;
3
3
  exports.createAbortError = createAbortError;
4
4
  exports.hasBit = hasBit;
5
5
  exports.ignoreFlag = ignoreFlag;
@@ -19,6 +19,7 @@ exports.isPlainObject = isPlainObject;
19
19
  exports.isObject = isObject;
20
20
  exports.isString = isString;
21
21
  exports.isEmpty = isEmpty;
22
+ exports.isFunction = isFunction;
22
23
  exports.parseTime = parseTime;
23
24
  exports.parseExpires = parseExpires;
24
25
  exports.formatTime = formatTime;
@@ -37,6 +38,8 @@ exports.encryptUTF8 = encryptUTF8;
37
38
  exports.decryptUTF8 = decryptUTF8;
38
39
  exports.randomString = randomString;
39
40
  exports.validateUUID = validateUUID;
41
+ exports.sanitizeCmd = sanitizeCmd;
42
+ exports.sanitizeArgs = sanitizeArgs;
40
43
  exports.errorValue = errorValue;
41
44
  exports.errorMessage = errorMessage;
42
45
  exports.purgeMemory = purgeMemory;
@@ -49,20 +52,6 @@ const fs = require("node:fs");
49
52
  const crypto = require("node:crypto");
50
53
  const bytes = require("bytes");
51
54
  const node_url_1 = require("node:url");
52
- class AbortError extends Error {
53
- constructor() {
54
- super("This operation was aborted");
55
- Error.captureStackTrace(this, this.constructor);
56
- }
57
- set name(value) { }
58
- get name() {
59
- return 'AbortError';
60
- }
61
- set code(value) { }
62
- get code() {
63
- return 20;
64
- }
65
- }
66
55
  const PATTERN_CHARS = {
67
56
  '&': '\\x26',
68
57
  '!': '\\x21',
@@ -79,36 +68,42 @@ const PATTERN_CHARS = {
79
68
  '~': '\\x7e'
80
69
  };
81
70
  const [VER_MAJOR, VER_MINOR, VER_PATCH] = process.version.substring(1).split('.').map(value => +value);
71
+ const PLATFORM_WIN32 = process.platform === 'win32';
82
72
  const REGEXP_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
83
73
  const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)[\w_$]*\s*\(([^)]*)\)\s*\{(.*)\})$/s;
84
74
  const REGEXP_FUNCTION_ARROW = /^(async\s+)?(\(([^)]*)\)\s*=>\s*(?:\{(.*)\}|(?!\s|{)((?:(?<!return\s+)(?:"[^"\n]*"|'[^'\n]*'|`[^`]*`|[^\n;"'`]))*;)))$/s;
85
75
  const REGEXP_GLOB = /(?<!\\)(?:(?:[^*]|^)\*{1,2}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/;
86
76
  const REGEXP_NATIVE = /^new\s+(Date|RegExp|URL|(?:Weak)?(?:Map|Set))\((.*)\)$/s;
77
+ const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
78
+ const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/s;
87
79
  const ASYNC_FUNCTION = Object.getPrototypeOf(async () => { }).constructor;
80
+ const RESERVED_SHELL = [
81
+ 'if',
82
+ 'then',
83
+ 'elif',
84
+ 'else',
85
+ 'fi',
86
+ 'time',
87
+ 'for',
88
+ 'in',
89
+ 'until',
90
+ 'while',
91
+ 'do',
92
+ 'done',
93
+ 'case',
94
+ 'esac',
95
+ 'coproc',
96
+ 'select',
97
+ 'function'
98
+ ];
88
99
  let CACHE_COERCED = new WeakSet();
89
100
  let LOG_CURRENT = null;
90
- let SUPPORTED_DOMEXCEPTION = false;
91
101
  let SUPPORTED_HASHSINGLE = false;
92
102
  let TEMP_DIR = path.join(process.cwd(), "tmp");
93
103
  let INCREMENT_COUNT = 65536;
94
104
  let INCREMENT_PREFIX = '';
95
- function fromObject(value, typedArray) {
105
+ function fromObject(value, typedArray, structured, shared) {
96
106
  if (isObject(value)) {
97
- if (value instanceof Map) {
98
- return new Map(value);
99
- }
100
- if (value instanceof Set) {
101
- return new Set(value);
102
- }
103
- if (value instanceof Date) {
104
- return new Date(value);
105
- }
106
- if (value instanceof RegExp) {
107
- return new RegExp(value);
108
- }
109
- if (value instanceof URL) {
110
- return new URL(value);
111
- }
112
107
  if (typedArray) {
113
108
  if (value instanceof Buffer) {
114
109
  return Buffer.from(value);
@@ -147,6 +142,31 @@ function fromObject(value, typedArray) {
147
142
  return BigUint64Array.from(value);
148
143
  }
149
144
  }
145
+ if (structured) {
146
+ try {
147
+ return structuredClone(value);
148
+ }
149
+ catch {
150
+ }
151
+ }
152
+ if (value instanceof Map) {
153
+ return new Map(value);
154
+ }
155
+ if (value instanceof Set) {
156
+ return new Set(value);
157
+ }
158
+ if (value instanceof Date) {
159
+ return new Date(value);
160
+ }
161
+ if (value instanceof RegExp) {
162
+ return new RegExp(value);
163
+ }
164
+ if (value instanceof URL) {
165
+ return new URL(value);
166
+ }
167
+ if (shared === false) {
168
+ return;
169
+ }
150
170
  }
151
171
  return value;
152
172
  }
@@ -283,6 +303,14 @@ function parseStringDefault(value) {
283
303
  case 'new': {
284
304
  const match = REGEXP_NATIVE.exec(value.trimEnd());
285
305
  if (match) {
306
+ try {
307
+ const out = eval(match[0]);
308
+ if (isObject(out)) {
309
+ return out;
310
+ }
311
+ }
312
+ catch {
313
+ }
286
314
  try {
287
315
  let text = match[2].trim();
288
316
  switch (match[1]) {
@@ -356,7 +384,7 @@ function checkFlags(value, flags) {
356
384
  return typeof value === 'number' && (value & flags) === flags;
357
385
  }
358
386
  const padStart = (value, char) => value > 9 ? value.toString() : char + value;
359
- const isFunction = (value) => typeof value === 'function';
387
+ const wrapQuote = (value) => '"' + value.replaceAll('"', '\\"') + '"';
360
388
  var LOG_TYPE;
361
389
  (function (LOG_TYPE) {
362
390
  LOG_TYPE[LOG_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
@@ -419,6 +447,7 @@ var ASSET_FLAG;
419
447
  var ERR_CODE;
420
448
  (function (ERR_CODE) {
421
449
  ERR_CODE["MODULE_NOT_FOUND"] = "MODULE_NOT_FOUND";
450
+ ERR_CODE["ERR_MODULE_NOT_FOUND"] = "ERR_MODULE_NOT_FOUND";
422
451
  })(ERR_CODE || (exports.ERR_CODE = ERR_CODE = {}));
423
452
  var DOWNLOAD_TYPE;
424
453
  (function (DOWNLOAD_TYPE) {
@@ -476,6 +505,7 @@ var THRESHOLD;
476
505
  THRESHOLD[THRESHOLD["FILEMANAGER_INTERVAL"] = 100] = "FILEMANAGER_INTERVAL";
477
506
  THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
478
507
  THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
508
+ THRESHOLD[THRESHOLD["WATCH_RECURSIVE_CHANGE"] = 500] = "WATCH_RECURSIVE_CHANGE";
479
509
  THRESHOLD[THRESHOLD["LOGGER_METER_INCREMENT"] = 250] = "LOGGER_METER_INCREMENT";
480
510
  })(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
481
511
  exports.IMPORT_MAP = {
@@ -496,8 +526,6 @@ exports.IMPORT_MAP = {
496
526
  "postgres": "@pi-r/postgres",
497
527
  "redis": "@pi-r/redis",
498
528
  "@babel/core": "@pi-r/babel",
499
- "clean-css": "@pi-r/clean-css",
500
- "csso": "@pi-r/csso",
501
529
  "eslint": "@pi-r/eslint",
502
530
  "html-validate": "@pi-r/html-validate",
503
531
  "postcss": "@pi-r/postcss",
@@ -507,15 +535,18 @@ exports.IMPORT_MAP = {
507
535
  "sass": "@pi-r/sass",
508
536
  "stylelint": "@pi-r/stylelint",
509
537
  "terser": "@pi-r/terser",
510
- "ibm": "@pi-r/ibm",
511
- "minio": "@pi-r/minio",
512
- "html-minifier": "@pi-r/html-minifier",
513
- "html-minifier-terser": "@pi-r/html-minifier-terser",
514
- "svgo": "@pi-r/svgo",
515
- "uglify-js": "@pi-r/uglify-js"
538
+ "ibm": "@pi-r2/ibm",
539
+ "minio": "@pi-r2/minio",
540
+ "imagemin": "@pi-r2/imagemin",
541
+ "clean-css": "@pi-r2/clean-css",
542
+ "csso": "@pi-r2/csso",
543
+ "html-minifier": "@pi-r2/html-minifier",
544
+ "html-minifier-terser": "@pi-r2/html-minifier-terser",
545
+ "svgo": "@pi-r2/svgo",
546
+ "uglify-js": "@pi-r2/uglify-js"
516
547
  };
517
548
  function createAbortError(reject) {
518
- const result = SUPPORTED_DOMEXCEPTION ? new DOMException("This operation was aborted", 'AbortError') : new AbortError();
549
+ const result = new DOMException("This operation was aborted", 'AbortError');
519
550
  return (reject ? Promise.reject(result) : result);
520
551
  }
521
552
  function hasBit(value, flags) {
@@ -551,12 +582,12 @@ function getLogCurrent() {
551
582
  function setLogCurrent(value) {
552
583
  LOG_CURRENT = value;
553
584
  }
554
- function getTempDir() {
555
- return TEMP_DIR;
585
+ function getTempDir(...values) {
586
+ return values.length > 0 ? path.join(TEMP_DIR, ...values) : TEMP_DIR;
556
587
  }
557
588
  function setTempDir(value) {
558
589
  try {
559
- if (path.isAbsolute(value) && fs.statSync(value).isDirectory()) {
590
+ if (path.isAbsolute(value = path.normalize(value)) && fs.statSync(value).isDirectory()) {
560
591
  TEMP_DIR = value;
561
592
  return true;
562
593
  }
@@ -580,6 +611,9 @@ function isString(value) {
580
611
  function isEmpty(value) {
581
612
  return value === undefined || value === null || value === '' || Array.isArray(value) && value.length === 0;
582
613
  }
614
+ function isFunction(value, cjs = false) {
615
+ return typeof value === 'function' && (!cjs || Object.hasOwn(value, "__cjs__"));
616
+ }
583
617
  function parseTime(value, start = 0) {
584
618
  const seconds = +value;
585
619
  if (isNaN(seconds) && isString(value)) {
@@ -822,16 +856,17 @@ function cascadeObject(data, query, fallback) {
822
856
  return fallback;
823
857
  }
824
858
  function cloneObject(data, options) {
825
- let freezeDepth = -1, mergeDepth = Infinity, target, deep, deepIgnore, mergeArray, typedArray, inherited, nonenumerable, symbol, preserve;
859
+ let freezeDepth = -1, mergeDepth = Infinity, target, deep, deepIgnore, mergeArray, typedArray, structured, shared, inherited, nonenumerable, symbol, preserve;
826
860
  if (options === true) {
827
861
  deep = true;
828
862
  }
829
863
  else if (options instanceof WeakSet) {
830
864
  deep = true;
865
+ structured = true;
831
866
  deepIgnore = options;
832
867
  }
833
868
  else if (options) {
834
- ({ target, deep, deepIgnore, mergeArray, typedArray, inherited, nonenumerable, symbol, preserve } = options);
869
+ ({ target, deep, deepIgnore, mergeArray, typedArray, structured, inherited, nonenumerable, symbol, preserve } = options);
835
870
  if (typeof options.freezeDepth === 'number') {
836
871
  freezeDepth = options.freezeDepth - 1;
837
872
  }
@@ -845,7 +880,7 @@ function cloneObject(data, options) {
845
880
  let nested;
846
881
  if (deep || freezeDepth > 0) {
847
882
  deepIgnore ||= new WeakSet();
848
- nested = { deep, deepIgnore, freezeDepth, mergeArray, mergeDepth, typedArray, preserve };
883
+ nested = { deep, deepIgnore, freezeDepth, mergeArray, mergeDepth, typedArray, structured, preserve };
849
884
  }
850
885
  if (Array.isArray(data)) {
851
886
  deepIgnore?.add(data);
@@ -865,7 +900,7 @@ function cloneObject(data, options) {
865
900
  for (let i = 0; i < length; ++i) {
866
901
  const value = data[i];
867
902
  if (deepIgnore) {
868
- target[i] = (Array.isArray(value) || isPlainObject(value)) && !deepIgnore.has(value) ? cloneObject(value, nested) : fromObject(value, typedArray);
903
+ target[i] = (Array.isArray(value) || isPlainObject(value)) && !deepIgnore.has(value) ? cloneObject(value, nested) : fromObject(value, typedArray, structured, shared);
869
904
  }
870
905
  else {
871
906
  target[i] = Array.isArray(value) ? value.slice(0) : value;
@@ -881,7 +916,7 @@ function cloneObject(data, options) {
881
916
  const value = data[attr];
882
917
  let merge;
883
918
  if (deepIgnore) {
884
- merge = (Array.isArray(value) || isPlainObject(value)) && !deepIgnore.has(value) ? cloneObject(value, nested) : fromObject(value, typedArray);
919
+ merge = (Array.isArray(value) || isPlainObject(value)) && !deepIgnore.has(value) ? cloneObject(value, nested) : fromObject(value, typedArray, structured, shared);
885
920
  }
886
921
  else {
887
922
  merge = Array.isArray(value) ? value.slice(0) : value;
@@ -912,7 +947,7 @@ function cloneObject(data, options) {
912
947
  }
913
948
  }
914
949
  else {
915
- return deep ? fromObject(data, typedArray) : data;
950
+ return deep ? fromObject(data, typedArray, structured, false) : data;
916
951
  }
917
952
  if (freezeDepth >= 0) {
918
953
  Object.freeze(target);
@@ -937,7 +972,7 @@ function coerceObject(data, parseString, cache) {
937
972
  return recurseObject(data, parseString, new WeakSet(), cache);
938
973
  }
939
974
  function asFunction(value, sync = true) {
940
- if (isFunction(value)) {
975
+ if (typeof value === 'function') {
941
976
  return value;
942
977
  }
943
978
  let match;
@@ -949,7 +984,7 @@ function asFunction(value, sync = true) {
949
984
  }
950
985
  try {
951
986
  const result = (0, eval)(`(${match[2]})`);
952
- if (isFunction(result)) {
987
+ if (typeof result === 'function') {
953
988
  return result;
954
989
  }
955
990
  }
@@ -958,13 +993,13 @@ function asFunction(value, sync = true) {
958
993
  }
959
994
  return null;
960
995
  }
961
- function getEncoding(value, fallback = 'utf-8') {
996
+ function getEncoding(value, fallback) {
962
997
  if (typeof value === 'string') {
963
998
  switch (value = value.trim().toLowerCase()) {
964
999
  case 'utf8':
965
1000
  case 'utf-8':
966
1001
  case 'unicode-1-1-utf-8':
967
- return 'utf-8';
1002
+ return 'utf8';
968
1003
  case 'utf16le':
969
1004
  case 'utf-16le':
970
1005
  case 'utf16':
@@ -975,7 +1010,7 @@ function getEncoding(value, fallback = 'utf-8') {
975
1010
  return value;
976
1011
  }
977
1012
  }
978
- return fallback;
1013
+ return fallback || 'utf8';
979
1014
  }
980
1015
  function encryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
981
1016
  if (checkCipherType(algorithm) && isString(data)) {
@@ -1009,7 +1044,7 @@ function randomString(format, dictionary) {
1009
1044
  if (match) {
1010
1045
  dictionary ||= '0123456789abcdef';
1011
1046
  const result = format.match(/(\d+|[^\d[]+|\[[^\]]+\]|\[)/g)?.reduce((a, b) => {
1012
- let length, available;
1047
+ let length = 0, available;
1013
1048
  if (b.startsWith('[') && b.endsWith(']')) {
1014
1049
  length = 1;
1015
1050
  available = b.substring(1, b.length - 1);
@@ -1021,7 +1056,7 @@ function randomString(format, dictionary) {
1021
1056
  available = dictionary;
1022
1057
  }
1023
1058
  const upperBound = available.length;
1024
- if (isFunction(crypto.getRandomValues) && length > 1 && length <= 65536) {
1059
+ if (length > 1 && length <= 65536) {
1025
1060
  const items = crypto.getRandomValues(new Uint32Array(length));
1026
1061
  for (let i = 0; i < length; i++) {
1027
1062
  a += available[items[i] % upperBound];
@@ -1044,6 +1079,60 @@ function randomString(format, dictionary) {
1044
1079
  function validateUUID(value) {
1045
1080
  return typeof value === 'string' && value.length === 36 && REGEXP_UUID.test(value);
1046
1081
  }
1082
+ function sanitizeCmd(value) {
1083
+ if (value.includes(' ')) {
1084
+ return PLATFORM_WIN32 ? wrapQuote(value) : value.replaceAll(' ', '\\ ');
1085
+ }
1086
+ return value;
1087
+ }
1088
+ function sanitizeArgs(values, doubleQuote) {
1089
+ const result = typeof values === 'string' ? [values] : values;
1090
+ for (let i = 0; i < result.length; ++i) {
1091
+ let value = result[i].trim(), leading = '';
1092
+ if (value !== '--') {
1093
+ const opt = REGEXP_CLIOPTION.exec(value);
1094
+ if (opt) {
1095
+ if (!opt[2] && !opt[3]) {
1096
+ result[i] = opt[1];
1097
+ continue;
1098
+ }
1099
+ leading = opt[1] + (opt[2] || ' ');
1100
+ value = opt[3];
1101
+ }
1102
+ if (value) {
1103
+ const quoted = /^(["'])(.*)\1$/s.exec(value);
1104
+ if (PLATFORM_WIN32) {
1105
+ if (quoted) {
1106
+ if (quoted[1] === '"') {
1107
+ result[i] = leading + value;
1108
+ continue;
1109
+ }
1110
+ value = quoted[2];
1111
+ }
1112
+ if (value.includes(' ')) {
1113
+ value = wrapQuote(value);
1114
+ }
1115
+ }
1116
+ else if (!quoted) {
1117
+ if (REGEXP_CLIESCAPE.test(value)) {
1118
+ value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replaceAll("'", "'\\''")}'`;
1119
+ }
1120
+ else if (RESERVED_SHELL.includes(value)) {
1121
+ value = `'${value}'`;
1122
+ }
1123
+ }
1124
+ }
1125
+ else if (opt) {
1126
+ leading = leading.trim();
1127
+ if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
1128
+ leading = leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
1129
+ }
1130
+ }
1131
+ }
1132
+ result[i] = leading + value;
1133
+ }
1134
+ return (typeof values === 'string' ? result[0] : result);
1135
+ }
1047
1136
  function errorValue(value, hint) {
1048
1137
  return new Error(value + (hint ? ` (${hint})` : ''));
1049
1138
  }
@@ -1102,6 +1191,4 @@ async function importESM(name, isDefault, fromPath) {
1102
1191
  }
1103
1192
  return result;
1104
1193
  }
1105
- exports.generateUUID = crypto.randomUUID.bind(crypto);
1106
- SUPPORTED_DOMEXCEPTION = supported(17);
1107
1194
  SUPPORTED_HASHSINGLE = supported(20, 12, true) || supported(21, 7);
package/lib/compress.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CompressFormat as ICompressFormat, CompressLevel as ICompressLevel } from './squared';
1
+ import type { CompressFormat as ICompressFormat, CompressLevel as ICompressLevel, MimeTypeAction, WorkerAction } from './squared';
2
2
 
3
3
  import type { LogBaseOptions, LogTime } from './logger';
4
4
  import type { ThrowsAction } from './module';
@@ -6,9 +6,8 @@ import type { ThrowsAction } from './module';
6
6
  type ResultCallback<T = Buffer | Uint8Array | null> = (err: unknown, data?: T, ext?: string) => void;
7
7
  type ResultData = Buffer | Uint8Array | string | null;
8
8
 
9
- export interface CompressFormat extends ICompressFormat, LogBaseOptions, ReadableOptions {
9
+ export interface CompressFormat extends ICompressFormat, LogBaseOptions, ReadableOptions, MimeTypeAction, WorkerAction {
10
10
  filename?: string;
11
- mimeType?: string;
12
11
  startTime?: LogTime;
13
12
  etag?: string;
14
13
  outExt?: string;
@@ -17,10 +16,12 @@ export interface CompressFormat extends ICompressFormat, LogBaseOptions, Readabl
17
16
 
18
17
  export interface CompressLevel extends ICompressLevel, ReadableOptions {}
19
18
 
19
+ export interface BrotliCompressLevel extends CompressLevel, MimeTypeAction {}
20
+
20
21
  export interface ReadableOptions extends ThrowsAction {}
21
22
 
22
23
  export type BufferLike = Buffer | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly number[];
23
24
  export type TryFileCompressor = (data: string | Buffer, output: string, config: CompressFormat, callback?: ResultCallback<ResultData>) => Promise<ResultData | void>;
24
25
  export type TryFileCompressorAsync = (data: string | Buffer, output: string, config: CompressFormat) => Promise<ResultData>;
25
26
  export type BufferResult = Buffer | Uint8Array | null;
26
- export type PluginCompressor = FunctionArgs<[CompressFormat['options'], string?], FunctionArgs<[Buffer], Promise<Buffer | Uint8Array>>>;
27
+ export type PluginCompressor = FunctionArgs<[CompressFormat["options"], CompressFormat["metadata"]?], FunctionArgs<[Buffer], Promise<Buffer | Uint8Array>>>;