@e-mc/types 0.8.5 → 0.8.7

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/LICENSE CHANGED
@@ -1,7 +1,11 @@
1
- Copyright 2024 Mile Square Park
1
+ Copyright 2024 An Pham
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
6
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,7 +1,197 @@
1
1
  # @e-mc/types
2
2
 
3
- PEP 402
3
+ * NodeJS 14
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.7/index.d.ts
13
+
14
+ ```typescript
15
+ import type { LogArguments } from "./lib/logger";
16
+ import type { CloneObjectOptions } from "./lib/module";
17
+
18
+ import type { BytesOptions } from "bytes";
19
+ import type { BinaryLike, CipherGCMTypes, Encoding } from "crypto";
20
+
21
+ function createAbortError(): Error;
22
+ function hasBit(value: unknown, flags: number): boolean;
23
+ function ignoreFlag(value: unknown): boolean;
24
+ function cloneFlag(value: unknown): boolean;
25
+ function usingFlag(value: unknown): boolean;
26
+ function watchFlag(value: unknown): boolean;
27
+ function modifiedFlag(value: unknown): boolean;
28
+ function processFlag(value: unknown): boolean;
29
+ function mainFlag(value: unknown): boolean;
30
+ function existsFlag(value: unknown): boolean;
31
+ function getLogCurrent(): LogArguments | null;
32
+ function setLogCurrent(value: LogArguments): void;
33
+ function setTempDir(value: string): boolean;
34
+ function getTempDir(): string;
35
+ function isArray(value: unknown): value is unknown[];
36
+ function isObject(value: unknown): value is object;
37
+ function isPlainObject(value: unknown): value is Record<string | number | symbol, unknown>;
38
+ function isString(value: unknown): value is string;
39
+ function isEmpty(value: unknown): boolean;
40
+ function asFunction(value: unknown, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
41
+ function parseTime(value: number | string, start?: number): number;
42
+ function parseExpires(value: number | string, start?: number): number;
43
+ function formatTime(value: number, char: string): string;
44
+ function formatTime(value: number, elapsed?: boolean, char?: string): string;
45
+ function convertTime(value: number | string): number;
46
+ function convertTime(value: HighResolutionTime, format: true): string;
47
+ function convertTime(value: HighResolutionTime, format?: boolean): number;
48
+ function hasGlob(value: string): boolean;
49
+ function escapePattern(value: unknown, lookBehind?: boolean): string;
50
+ function renameExt(value: string, ext: string, when?: string): string;
51
+ function formatSize(value: string): number;
52
+ function formatSize(value: number, options?: BytesOptions): string;
53
+ function alignSize(value: unknown, kb?: number, factor?: number): number;
54
+ function cascadeObject(data: object, query: string, fallback?: unknown): unknown;
55
+ function cloneObject(data: unknown, deep: boolean): unknown;
56
+ function cloneObject(data: unknown, deepIgnore: WeakSet<object>): unknown;
57
+ function cloneObject(data: unknown, options?: CloneObjectOptions<unknown>): unknown;
58
+ function coerceObject(data: unknown, cache: boolean): unknown;
59
+ function coerceObject(data: unknown, parseString?: (...args: [string]) => unknown, cache?: boolean): unknown;
60
+ function getEncoding(value: unknown, fallback?: BufferEncoding): BufferEncoding;
61
+ function encryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
62
+ function decryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
63
+ function generateUUID(): string;
64
+ function incrementUUID(restart?: boolean): string;
65
+ function validateUUID(value: unknown): boolean;
66
+ function randomString(format: string, dictionary?: string): string;
67
+ function errorValue(value: string, hint?: string): Error;
68
+ function errorMessage(title: number | string, value: string, hint?: string): Error;
69
+ function purgeMemory(percent?: number): number;
70
+
71
+ interface LOG_TYPE {
72
+ UNKNOWN: 0;
73
+ SYSTEM: 1;
74
+ NODE: 2;
75
+ PROCESS: 4;
76
+ COMPRESS: 8;
77
+ WATCH: 16;
78
+ FILE: 32;
79
+ CLOUD: 64;
80
+ TIME_ELAPSED: 128;
81
+ TIME_PROCESS: 256;
82
+ FAIL: 512;
83
+ HTTP: 1024;
84
+ IMAGE: 2048;
85
+ EXEC: 4096;
86
+ PERMISSION: 8192;
87
+ TIMEOUT: 16384;
88
+ STDOUT: 32768;
89
+ DB: 65536;
90
+ }
91
+
92
+ interface STATUS_TYPE {
93
+ UNKNOWN: 0;
94
+ FATAL: 1;
95
+ ERROR: 2;
96
+ WARN: 3;
97
+ INFO: 4;
98
+ DEBUG: 5;
99
+ ASSERT: 6;
100
+ TRACE: 7;
101
+ }
102
+
103
+ interface ASSET_FLAG {
104
+ NONE: 0;
105
+ IGNORE: 1;
106
+ CLONE: 2;
107
+ USING: 4;
108
+ WATCH: 8;
109
+ MODIFIED: 16;
110
+ PROCESS: 32;
111
+ MAIN: 64;
112
+ EXISTS: 128;
113
+ }
114
+
115
+ interface FILE_TYPE {
116
+ UNKNOWN: 0;
117
+ ASSET: 1;
118
+ TRANSFORM: 2;
119
+ COMPRESSED: 4;
120
+ SOURCEMAP: 8;
121
+ TORRENT: 16;
122
+ }
123
+
124
+ interface ACTION_FLAG {
125
+ NONE: 0;
126
+ IGNORE: 1;
127
+ }
128
+
129
+ interface ERR_CODE {
130
+ MODULE_NOT_FOUND: "MODULE_NOT_FOUND";
131
+ }
132
+
133
+ interface DOWNLOAD_TYPE {
134
+ HTTP: 0;
135
+ DISK: 1;
136
+ CACHE: 2;
137
+ }
138
+
139
+ interface FETCH_TYPE {
140
+ UNKNOWN: 0;
141
+ HTTP: 1;
142
+ TORRENT: 2;
143
+ FTP: 3;
144
+ UNIX_SOCKET: 4;
145
+ }
146
+
147
+ interface DB_TYPE {
148
+ SQL: 1;
149
+ NOSQL: 2;
150
+ DOCUMENT: 4;
151
+ KEYVALUE: 8;
152
+ }
153
+
154
+ interface DB_TRANSACTION {
155
+ ACTIVE: 1;
156
+ PARTIAL: 2;
157
+ COMMIT: 4;
158
+ TERMINATE: 8;
159
+ ABORT: 16;
160
+ FAIL: 32;
161
+ AUTH: 64;
162
+ CACHE: 128;
163
+ }
164
+
165
+ interface WATCH_EVENT {
166
+ MODIFIED: "modified";
167
+ BROADCAST: "broadcast";
168
+ CLOSE: "close";
169
+ ERROR: "error";
170
+ }
171
+
172
+ interface READDIR_SORT {
173
+ FILE: number;
174
+ DIRECTORY: number;
175
+ DESCENDING: number;
176
+ }
177
+
178
+ interface THRESHOLD {
179
+ FILEMANAGER_INTERVAL: number;
180
+ WATCH_INTERVAL: number;
181
+ WATCH_CHANGE: number;
182
+ }
183
+
184
+ const IMPORT_MAP: Record<string, string | undefined>;
185
+ ```
186
+
187
+ ## References
188
+
189
+ - https://www.unpkg.com/@e-mc/types@0.8.7/lib/logger.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.8.7/lib/module.d.ts
191
+
192
+ * https://nodejs.org/api/perf_hooks.html
193
+ * https://www.npmjs.com/package/@types/bytes
4
194
 
5
195
  ## LICENSE
6
196
 
7
- MIT
197
+ BSD 3-Clause
package/constant.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.8.5',
3
- TEMP_DIR = 'tmp', // eslint-disable-line @typescript-eslint/no-shadow
2
+ VERSION = '0.8.7',
3
+ TEMP_DIR = 'tmp',
4
4
  CJS = '__cjs__'
5
5
  }
6
6
 
package/index.js CHANGED
@@ -1,27 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateUUID = exports.randomString = exports.decryptUTF8 = exports.encryptUTF8 = exports.getEncoding = exports.asFunction = exports.coerceObject = exports.cloneObject = exports.cascadeObject = exports.alignSize = exports.formatSize = exports.renameExt = exports.escapePattern = exports.hasGlob = exports.convertTime = exports.formatTime = exports.parseExpires = exports.parseTime = exports.isEmpty = exports.isString = exports.isObject = exports.isPlainObject = exports.isArray = exports.setTempDir = exports.getTempDir = exports.setLogCurrent = exports.getLogCurrent = exports.existsFlag = exports.mainFlag = exports.processFlag = exports.modifiedFlag = exports.watchFlag = exports.usingFlag = exports.cloneFlag = exports.ignoreFlag = exports.hasBit = exports.createAbortError = exports.IMPORT_MAP = exports.THRESHOLD = exports.READDIR_SORT = exports.WATCH_EVENT = 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_TYPE = void 0;
4
- exports.generateUUID = exports.incrementUUID = exports.purgeMemory = exports.errorMessage = exports.errorValue = void 0;
3
+ exports.errorMessage = exports.errorValue = exports.validateUUID = exports.randomString = exports.decryptUTF8 = exports.encryptUTF8 = exports.getEncoding = exports.asFunction = exports.coerceObject = exports.cloneObject = exports.cascadeObject = exports.formatSize = exports.renameExt = exports.escapePattern = exports.hasGlob = exports.convertTime = exports.formatTime = exports.parseExpires = exports.parseTime = exports.isEmpty = exports.isString = exports.isObject = exports.isPlainObject = exports.isArray = exports.setTempDir = exports.getTempDir = exports.setLogCurrent = exports.getLogCurrent = exports.existsFlag = exports.mainFlag = exports.processFlag = exports.modifiedFlag = exports.watchFlag = exports.usingFlag = exports.cloneFlag = exports.ignoreFlag = exports.hasBit = exports.createAbortError = exports.THRESHOLD = exports.IMPORT_MAP = exports.WATCH_EVENT = 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_TYPE = void 0;
4
+ exports.generateUUID = exports.purgeMemory = void 0;
5
5
  const path = require("path");
6
6
  const fs = require("fs");
7
7
  const crypto = require("crypto");
8
+ const uuid = require("uuid");
8
9
  const bytes = require("bytes");
9
10
  class AbortError extends Error {
10
11
  constructor() {
11
- super("The operation was aborted" /* ERR_MESSAGE.ABORTED_OPERATION */);
12
+ super("The operation was aborted");
12
13
  this.code = 'ABORT_ERR';
13
14
  this.name = 'AbortError';
14
15
  }
15
16
  }
16
17
  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;
17
- const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)[\w_$]*\s*\(([^)]*)\)\s*\{([\S\s]*)\})$/;
18
- const REGEXP_FUNCTION_ARROW = /^(async\s+)?(\s*\(([^)]*)\)\s*=>\s*(?:\{([\S\s]*)\}|(?!\s|{)((?:(?<!return\s+)(?:"[^"\n]*"|'[^'\n]*'|`[^`]*`|[^\n;"'`]))*;)))$/;
18
+ const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)([\w_$]*)\s*\(([^)]*)\)\s*\{([\S\s]*)\})$/;
19
19
  const ASYNC_FUNCTION = Object.getPrototypeOf(async () => { }).constructor;
20
20
  let CACHE_COERCED = new WeakSet();
21
21
  let LOG_CURRENT = null;
22
- let TEMP_DIR = path.join(process.cwd(), "tmp" /* INTERNAL.TEMP_DIR */);
23
- let INCREMENT_COUNT = 65536;
24
- let INCREMENT_PREFIX = '';
22
+ let TEMP_DIR = path.join(process.cwd(), "tmp");
25
23
  function fromObject(value, typedArray) {
26
24
  if (isObject(value)) {
27
25
  if (value instanceof Map) {
@@ -243,18 +241,6 @@ var WATCH_EVENT;
243
241
  WATCH_EVENT["CLOSE"] = "close";
244
242
  WATCH_EVENT["ERROR"] = "error";
245
243
  })(WATCH_EVENT || (exports.WATCH_EVENT = WATCH_EVENT = {}));
246
- var READDIR_SORT;
247
- (function (READDIR_SORT) {
248
- READDIR_SORT[READDIR_SORT["FILE"] = 0] = "FILE";
249
- READDIR_SORT[READDIR_SORT["DIRECTORY"] = 1] = "DIRECTORY";
250
- READDIR_SORT[READDIR_SORT["DESCENDING"] = 2] = "DESCENDING";
251
- })(READDIR_SORT || (exports.READDIR_SORT = READDIR_SORT = {}));
252
- var THRESHOLD;
253
- (function (THRESHOLD) {
254
- THRESHOLD[THRESHOLD["FILEMANAGER_INTERVAL"] = 100] = "FILEMANAGER_INTERVAL";
255
- THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
256
- THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
257
- })(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
258
244
  var IMPORT_MAP;
259
245
  (function (IMPORT_MAP) {
260
246
  IMPORT_MAP["@squared-functions/cloud"] = "@e-mc/cloud";
@@ -322,8 +308,8 @@ var IMPORT_MAP;
322
308
  IMPORT_MAP["@squared-functions/document/packages/@babel/core"] = "@pi-r/babel";
323
309
  IMPORT_MAP["@squared-functions/document/packages/clean-css"] = "@pi-r/clean-css";
324
310
  IMPORT_MAP["@squared-functions/document/packages/eslint"] = "@pi-r/eslint";
325
- IMPORT_MAP["@squared-functions/document/packages/html-minifier"] = "@pi-r/html-minifier";
326
311
  IMPORT_MAP["@squared-functions/document/packages/html-minifier-terser"] = "@pi-r/html-minifier-terser";
312
+ IMPORT_MAP["@squared-functions/document/packages/html-minifier"] = "@pi-r/html-minifier";
327
313
  IMPORT_MAP["@squared-functions/document/packages/html-validate"] = "@pi-r/html-validate";
328
314
  IMPORT_MAP["@squared-functions/document/packages/postcss"] = "@pi-r/postcss";
329
315
  IMPORT_MAP["@squared-functions/document/packages/posthtml"] = "@pi-r/posthtml";
@@ -335,6 +321,12 @@ var IMPORT_MAP;
335
321
  IMPORT_MAP["@squared-functions/document/packages/terser"] = "@pi-r/terser";
336
322
  IMPORT_MAP["@squared-functions/document/packages/uglify-js"] = "@pi-r/uglify-js";
337
323
  })(IMPORT_MAP || (exports.IMPORT_MAP = IMPORT_MAP = {}));
324
+ var THRESHOLD;
325
+ (function (THRESHOLD) {
326
+ THRESHOLD[THRESHOLD["FILEMANAGER_INTERVAL"] = 100] = "FILEMANAGER_INTERVAL";
327
+ THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
328
+ THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
329
+ })(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
338
330
  function createAbortError() {
339
331
  return new AbortError();
340
332
  }
@@ -344,35 +336,35 @@ function hasBit(value, flags) {
344
336
  }
345
337
  exports.hasBit = hasBit;
346
338
  function ignoreFlag(value) {
347
- return typeof value === 'number' && (value & 1 /* IASSET_FLAG.IGNORE */) === 1 /* IASSET_FLAG.IGNORE */;
339
+ return typeof value === 'number' && (value & 1) === 1;
348
340
  }
349
341
  exports.ignoreFlag = ignoreFlag;
350
342
  function cloneFlag(value) {
351
- return typeof value === 'number' && (value & 2 /* IASSET_FLAG.CLONE */) === 2 /* IASSET_FLAG.CLONE */;
343
+ return typeof value === 'number' && (value & 2) === 2;
352
344
  }
353
345
  exports.cloneFlag = cloneFlag;
354
346
  function usingFlag(value) {
355
- return typeof value === 'number' && (value & 4 /* IASSET_FLAG.USING */) === 4 /* IASSET_FLAG.USING */;
347
+ return typeof value === 'number' && (value & 4) === 4;
356
348
  }
357
349
  exports.usingFlag = usingFlag;
358
350
  function watchFlag(value) {
359
- return typeof value === 'number' && (value & 8 /* IASSET_FLAG.WATCH */) === 8 /* IASSET_FLAG.WATCH */;
351
+ return typeof value === 'number' && (value & 8) === 8;
360
352
  }
361
353
  exports.watchFlag = watchFlag;
362
354
  function modifiedFlag(value) {
363
- return typeof value === 'number' && (value & 16 /* IASSET_FLAG.MODIFIED */) === 16 /* IASSET_FLAG.MODIFIED */;
355
+ return typeof value === 'number' && (value & 16) === 16;
364
356
  }
365
357
  exports.modifiedFlag = modifiedFlag;
366
358
  function processFlag(value) {
367
- return typeof value === 'number' && (value & 32 /* IASSET_FLAG.PROCESS */) === 32 /* IASSET_FLAG.PROCESS */;
359
+ return typeof value === 'number' && (value & 32) === 32;
368
360
  }
369
361
  exports.processFlag = processFlag;
370
362
  function mainFlag(value) {
371
- return typeof value === 'number' && (value & 64 /* IASSET_FLAG.MAIN */) === 64 /* IASSET_FLAG.MAIN */;
363
+ return typeof value === 'number' && (value & 64) === 64;
372
364
  }
373
365
  exports.mainFlag = mainFlag;
374
366
  function existsFlag(value) {
375
- return typeof value === 'number' && (value & 128 /* IASSET_FLAG.EXISTS */) === 128 /* IASSET_FLAG.EXISTS */;
367
+ return typeof value === 'number' && (value & 128) === 128;
376
368
  }
377
369
  exports.existsFlag = existsFlag;
378
370
  function getLogCurrent() {
@@ -404,7 +396,7 @@ function isArray(value) {
404
396
  }
405
397
  exports.isArray = isArray;
406
398
  function isPlainObject(value) {
407
- return typeof value === 'object' && value !== null && (value.constructor === Object || Object.getPrototypeOf(value) === null);
399
+ return value && typeof value === 'object' ? value.constructor === Object || Object.getPrototypeOf(value) === null : false;
408
400
  }
409
401
  exports.isPlainObject = isPlainObject;
410
402
  function isObject(value) {
@@ -431,25 +423,25 @@ function parseTime(value, start = 0) {
431
423
  }
432
424
  switch (match[2]) {
433
425
  case 'y':
434
- result += n * 31449600000 /* TIME.Y */;
426
+ result += n * 31449600000;
435
427
  break;
436
428
  case 'M':
437
- result += n * 2592000000 /* TIME.M */;
429
+ result += n * 2592000000;
438
430
  break;
439
431
  case 'w':
440
- result += n * 604800000 /* TIME.W */;
432
+ result += n * 604800000;
441
433
  break;
442
434
  case 'd':
443
- result += n * 86400000 /* TIME.D */;
435
+ result += n * 86400000;
444
436
  break;
445
437
  case 'h':
446
- result += n * 3600000 /* TIME.H */;
438
+ result += n * 3600000;
447
439
  break;
448
440
  case 'm':
449
- result += n * 60000 /* TIME.m */;
441
+ result += n * 60000;
450
442
  break;
451
443
  case 's':
452
- result += n * 1000 /* TIME.S */;
444
+ result += n * 1000;
453
445
  break;
454
446
  case 'ms':
455
447
  result += Math.ceil(n);
@@ -461,7 +453,7 @@ function parseTime(value, start = 0) {
461
453
  }
462
454
  }
463
455
  else if (seconds > 0) {
464
- return Math.ceil(seconds * 1000 /* TIME.S */) + start;
456
+ return Math.ceil(seconds * 1000) + start;
465
457
  }
466
458
  return 0;
467
459
  }
@@ -484,18 +476,18 @@ function formatTime(value, elapsed, char = ' ') {
484
476
  if (value < 1000) {
485
477
  return value + 'ms';
486
478
  }
487
- const h = Math.floor(value / 3600000 /* TIME.H */);
479
+ const h = Math.floor(value / 3600000);
488
480
  if (h > 0) {
489
- value -= h * 3600000 /* TIME.H */;
481
+ value -= h * 3600000;
490
482
  result.push(h + 'h');
491
483
  }
492
- const m = Math.floor(value / 60000 /* TIME.m */);
484
+ const m = Math.floor(value / 60000);
493
485
  if (m > 0) {
494
- value -= m * 60000 /* TIME.m */;
486
+ value -= m * 60000;
495
487
  result.push(m + 'm');
496
488
  }
497
489
  if (value > 0) {
498
- result.push(value < 100 ? value + 'ms' : (value / 1000 /* TIME.S */).toPrecision(value <= 9950 ? 2 : 3).replace(/\.?0+$/, '') + 's');
490
+ result.push(value < 100 ? value + 'ms' : (value / 1000).toPrecision(value <= 9950 ? 2 : 3).replace(/\.?0+$/, '') + 's');
499
491
  }
500
492
  return result.join(char);
501
493
  }
@@ -571,40 +563,9 @@ function renameExt(value, ext, when) {
571
563
  }
572
564
  exports.renameExt = renameExt;
573
565
  function formatSize(value, options) {
574
- if (typeof value === 'number') {
575
- return (bytes(value, options) || ('0' + (options?.unitSeparator || '') + 'B'));
576
- }
577
- return (bytes(value) || 0);
566
+ return (typeof value === 'number' ? bytes(value, options) : bytes(value));
578
567
  }
579
568
  exports.formatSize = formatSize;
580
- function alignSize(value, kb = 0, factor = 0) {
581
- if (value === undefined) {
582
- return NaN;
583
- }
584
- let result = 0;
585
- switch (typeof value) {
586
- case 'number':
587
- if (value < 0) {
588
- return NaN;
589
- }
590
- result = Math.ceil(factor > 0 ? value * Math.pow(1024, factor) : value);
591
- break;
592
- case 'string':
593
- result = formatSize(value);
594
- if (result < 0) {
595
- return NaN;
596
- }
597
- break;
598
- default:
599
- return NaN;
600
- }
601
- if (kb > 0) {
602
- kb = Math.ceil(kb) * 1024;
603
- return Math.ceil(result / kb) * kb;
604
- }
605
- return result;
606
- }
607
- exports.alignSize = alignSize;
608
569
  function cascadeObject(data, query, fallback) {
609
570
  if (isObject(data) && isString(query)) {
610
571
  const names = query.trim().split(/(?<!\\)\./).map(item => item.includes('.') ? item.replace(/\\(?=\.)/g, '') : item);
@@ -762,7 +723,7 @@ function coerceObject(data, parseString, cache) {
762
723
  }
763
724
  default: {
764
725
  const text = match[2].trim();
765
- let values = []; // eslint-disable-line @typescript-eslint/no-explicit-any
726
+ let values = [];
766
727
  if (text.startsWith('[') && text.endsWith(']')) {
767
728
  values = JSON.parse(text);
768
729
  }
@@ -836,10 +797,10 @@ function asFunction(value, sync = true) {
836
797
  return value;
837
798
  }
838
799
  let match;
839
- if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()) || REGEXP_FUNCTION_ARROW.exec(value))) {
800
+ if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()))) {
840
801
  if (!sync || match[1]) {
841
- const args = match[3].trim().split(/\s*,\s*/);
842
- args.push(match[4] || (match[5] && (match[5] = 'return ' + match[5])));
802
+ const args = match[4].trim().split(/\s*,\s*/);
803
+ args.push(match[5]);
843
804
  return new ASYNC_FUNCTION(...args);
844
805
  }
845
806
  try {
@@ -855,22 +816,7 @@ function asFunction(value, sync = true) {
855
816
  }
856
817
  exports.asFunction = asFunction;
857
818
  function getEncoding(value, fallback = 'utf-8') {
858
- if (typeof value === 'string') {
859
- switch (value = value.trim().toLowerCase()) {
860
- case 'utf8':
861
- case 'utf-8':
862
- case 'utf16le':
863
- return value;
864
- case 'utf-16le':
865
- case 'utf16':
866
- case 'utf-16':
867
- return 'utf16le';
868
- }
869
- if (Buffer.isEncoding(value)) {
870
- return value;
871
- }
872
- }
873
- return fallback;
819
+ return typeof value === 'string' && Buffer.isEncoding(value = value.trim().toLowerCase()) ? value : fallback;
874
820
  }
875
821
  exports.getEncoding = getEncoding;
876
822
  function encryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
@@ -955,12 +901,4 @@ function purgeMemory(percent) {
955
901
  CACHE_COERCED = new WeakSet();
956
902
  }
957
903
  exports.purgeMemory = purgeMemory;
958
- function incrementUUID(restart) {
959
- if (restart || INCREMENT_COUNT === 65536) {
960
- INCREMENT_COUNT = 0;
961
- INCREMENT_PREFIX = (0, exports.generateUUID)().substring(0, 33);
962
- }
963
- return INCREMENT_PREFIX + (INCREMENT_COUNT++).toString(16).padStart(4, '0');
964
- }
965
- exports.incrementUUID = incrementUUID;
966
- exports.generateUUID = typeof crypto.randomUUID === 'function' ? crypto.randomUUID.bind(crypto) : require('uuid').v4;
904
+ exports.generateUUID = typeof crypto.randomUUID === 'function' ? crypto.randomUUID.bind(crypto) : uuid.v4;
package/lib/core.d.ts CHANGED
@@ -12,7 +12,7 @@ export interface IdentifierAction {
12
12
  uuidKey?: string;
13
13
  }
14
14
 
15
- export interface IClient<T extends IHost, U extends ClientModule, V extends FunctionType = FunctionType> extends IModule<T>, IExternalConfig<U, U extends ClientModule<infer W> ? W : unknown>, IExternalFunction<V> {
15
+ export interface IClient<T extends IHost, U extends ClientModule, V extends FunctionType<any, any> = FunctionType> extends IModule<T>, IExternalConfig<U, U extends ClientModule<infer W> ? W : unknown>, IExternalFunction<V> {
16
16
  init(...args: unknown[]): this;
17
17
  getUserSettings<X>(): Null<X>;
18
18
  set cacheDir(value: string);
package/lib/index.d.ts CHANGED
@@ -572,9 +572,9 @@ declare namespace functions {
572
572
  readFile(src: string): Undef<Buffer>;
573
573
  readFile<U extends ReadFileOptions>(src: string, options?: U): Undef<U extends { encoding: string } ? U extends { minStreamSize: NumString } ? Promise<string> : string : U extends { minStreamSize: NumString } ? Promise<Buffer> : Buffer>;
574
574
  readFile<U extends Buffer>(src: string, promises: true): Promise<Undef<U>>;
575
- readFile<U extends BufferContent>(src: string, options: ReadFileOptions, promises: true): Promise<Undef<U>>;
576
- readFile<U extends ReadFileCallback<V>, V extends Buffer>(src: string, callback: U): Undef<U extends ReadFileCallback<infer W> ? W : V>;
577
- readFile<U extends ReadFileCallback<V>, V extends BufferContent>(src: string, options: ReadFileOptions, callback: U): Undef<U extends ReadFileCallback<infer W> ? W : V>;
575
+ readFile<U extends BufferContent, V extends ReadFileOptions>(src: string, options: V, promises: true): Promise<Undef<V extends { encoding: string } ? string : U>>;
576
+ readFile<U extends ReadFileCallback>(src: string, callback: U): Undef<U extends ReadFileCallback<infer W> ? W : BufferContent>;
577
+ readFile<U extends ReadFileCallback, V extends ReadFileOptions>(src: string, options: V, callback: U): Undef<V extends { encoding: string } ? string : U extends ReadFileCallback<infer W> ? W : BufferContent>;
578
578
  writeFile<U extends boolean>(src: string, data: BufferView, options?: WriteFileOptions): U;
579
579
  writeFile<U extends Promise<boolean>>(src: string, data: BufferView, promises: true): U;
580
580
  writeFile<U extends Promise<boolean>>(src: string, data: BufferView, options: WriteFileOptions, promises: true): U;
@@ -740,8 +740,8 @@ declare namespace functions {
740
740
  getMemUsage(format: true): string;
741
741
  getMemUsage(format?: boolean): number;
742
742
  formatCpuMem(start: CpuUsage, all?: boolean): string;
743
- getPackageVersion(name: string | TupleOf<string>, startDir: string): string;
744
- getPackageVersion(name: string | TupleOf<string>, unstable?: boolean, startDir?: string): string;
743
+ getPackageVersion(name: string | TupleOf<string>, startDir: string, baseDir?: string): string;
744
+ getPackageVersion(name: string | TupleOf<string>, unstable?: boolean, startDir?: string, baseDir?: string): string;
745
745
  checkSemVer(name: string | TupleOf<string>, options: CheckSemVerOptions): boolean;
746
746
  checkSemVer(name: string | TupleOf<string>, min: NumString, max: NumString, options: CheckSemVerOptions): boolean;
747
747
  checkSemVer(name: string | TupleOf<string>, min: NumString, max?: NumString, unstable?: boolean, startDir?: string): boolean;
package/lib/module.d.ts CHANGED
@@ -127,5 +127,5 @@ export interface GetTempDirOptions {
127
127
 
128
128
  export type NormalizeFlags = typeof NORMALIZE_FLAGS[keyof typeof NORMALIZE_FLAGS];
129
129
  export type ReadTextOptions = ReadBufferOptions;
130
- export type ReadFileCallback<T> = (err: Null<NodeJS.ErrnoException>, data?: T) => void;
130
+ export type ReadFileCallback<T extends BufferContent = BufferContent> = (err: Null<NodeJS.ErrnoException>, data?: T) => void;
131
131
  export type ProtocolType = "http" | "https" | "http/s" | "ftp" | "sftp" | "s/ftp" | "torrent" | "unc";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/types",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Type definitions for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
20
+ "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
23
  "bytes": "^3.1.2",