@e-mc/types 0.8.6 → 0.9.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/LICENSE +10 -10
- package/README.md +28 -4
- package/constant.d.ts +23 -2
- package/index.d.ts +25 -0
- package/index.js +172 -101
- package/lib/asset.d.ts +4 -2
- package/lib/cloud.d.ts +31 -16
- package/lib/compat-v4.d.ts +7 -14
- package/lib/compress.d.ts +3 -3
- package/lib/core.d.ts +25 -19
- package/lib/db.d.ts +0 -9
- package/lib/filemanager.d.ts +3 -2
- package/lib/http.d.ts +20 -0
- package/lib/index.d.ts +153 -132
- package/lib/logger.d.ts +4 -14
- package/lib/module.d.ts +12 -2
- package/lib/node.d.ts +0 -2
- package/lib/object.d.ts +2 -0
- package/lib/request.d.ts +6 -4
- package/lib/settings.d.ts +72 -68
- package/lib/squared.d.ts +14 -13
- package/lib/type.d.ts +3 -4
- package/lib/watch.d.ts +3 -3
- package/package.json +3 -4
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
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
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
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
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,6 +1,6 @@
|
|
|
1
1
|
# @e-mc/types
|
|
2
2
|
|
|
3
|
-
* NodeJS 14
|
|
3
|
+
* NodeJS 14/16
|
|
4
4
|
* ES2020
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.0/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogArguments } from "./lib/logger";
|
|
@@ -17,7 +17,9 @@ import type { CloneObjectOptions } from "./lib/module";
|
|
|
17
17
|
|
|
18
18
|
import type { BytesOptions } from "bytes";
|
|
19
19
|
import type { BinaryLike, CipherGCMTypes, Encoding } from "crypto";
|
|
20
|
+
import type { HighResolutionTime } from "perf_hooks";
|
|
20
21
|
|
|
22
|
+
function createAbortError(reject: true): Promise<never>;
|
|
21
23
|
function createAbortError(): Error;
|
|
22
24
|
function hasBit(value: unknown, flags: number): boolean;
|
|
23
25
|
function ignoreFlag(value: unknown): boolean;
|
|
@@ -162,6 +164,12 @@ interface DB_TRANSACTION {
|
|
|
162
164
|
CACHE: 128;
|
|
163
165
|
}
|
|
164
166
|
|
|
167
|
+
interface TRANSFER_TYPE {
|
|
168
|
+
DISK: 1;
|
|
169
|
+
STREAM: 2;
|
|
170
|
+
CHUNK: 4;
|
|
171
|
+
}
|
|
172
|
+
|
|
165
173
|
interface WATCH_EVENT {
|
|
166
174
|
MODIFIED: "modified";
|
|
167
175
|
BROADCAST: "broadcast";
|
|
@@ -184,10 +192,26 @@ interface THRESHOLD {
|
|
|
184
192
|
const IMPORT_MAP: Record<string, string | undefined>;
|
|
185
193
|
```
|
|
186
194
|
|
|
195
|
+
## NodeJS 14 LTS
|
|
196
|
+
|
|
197
|
+
Any optional fail safe dependencies were removed as of `E-mc 0.9`. The code itself will still be *ES2020* and will continue to work equivalently when self-installing these dependencies:
|
|
198
|
+
|
|
199
|
+
### Under 15.4 + 16.0
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
npm i abort-controller event-target-shim
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Under 14.17 + 15.6
|
|
206
|
+
|
|
207
|
+
```sh
|
|
208
|
+
npm i uuid
|
|
209
|
+
```
|
|
210
|
+
|
|
187
211
|
## References
|
|
188
212
|
|
|
189
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
190
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
213
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/logger.d.ts
|
|
214
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/module.d.ts
|
|
191
215
|
|
|
192
216
|
* https://nodejs.org/api/perf_hooks.html
|
|
193
217
|
* 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.
|
|
2
|
+
VERSION = '0.9.0',
|
|
3
3
|
TEMP_DIR = 'tmp',
|
|
4
4
|
CJS = '__cjs__'
|
|
5
5
|
}
|
|
@@ -47,11 +47,16 @@ export const enum ERR_MESSAGE {
|
|
|
47
47
|
PARAMETERS = 'Invalid parameters',
|
|
48
48
|
FORMAT = 'Invalid format',
|
|
49
49
|
CHECKSUM = 'Invalid checksum',
|
|
50
|
+
RESPONSE = 'Invalid response',
|
|
51
|
+
SIZE = 'Size limit was exceeded',
|
|
50
52
|
ERROR_CODE = 'Error code',
|
|
53
|
+
PERMISSION = 'Operation not permitted',
|
|
51
54
|
EXEC_PERMISSION = 'Exec command not permitted',
|
|
52
55
|
NOT_CACHEABLE = 'Not able to cache',
|
|
53
56
|
NOT_COPYABLE = 'Not able to copy file',
|
|
54
57
|
NOT_DIRECTORY = 'Path is not a directory',
|
|
58
|
+
NOT_ABSOLUTE = 'Path is not absolute',
|
|
59
|
+
NOT_READABLE = 'Not able to read buffer',
|
|
55
60
|
CANCELLED = 'Transaction was cancelled',
|
|
56
61
|
INCOMPLETE = 'Transaction was not completed',
|
|
57
62
|
THREAD = 'Thread limit exceeded',
|
|
@@ -62,6 +67,7 @@ export const enum ERR_MESSAGE {
|
|
|
62
67
|
UNSUPPORTED_MIME = 'Unsupported MIME',
|
|
63
68
|
UNSUPPORTED_READ = 'Not permitted to read file',
|
|
64
69
|
UNSUPPORTED_WRITE = 'Not permitted to write file',
|
|
70
|
+
NOTFOUND_PATH = 'Path not found',
|
|
65
71
|
NOTFOUND_FILE = 'File not found',
|
|
66
72
|
NOTFOUND_BINARY = 'Binary not found',
|
|
67
73
|
NOTFOUND_PACKAGE = 'Package not found',
|
|
@@ -161,7 +167,10 @@ export const enum ERR_IMAGE {
|
|
|
161
167
|
}
|
|
162
168
|
|
|
163
169
|
export const enum ERR_HTTP {
|
|
164
|
-
HEADERS = 'Unable to process headers'
|
|
170
|
+
HEADERS = 'Unable to process headers',
|
|
171
|
+
ETAG = 'ETag not supported',
|
|
172
|
+
DOWNLOAD_SUCCESS = 'No files were successfully downloaded',
|
|
173
|
+
MULTIPART_ATTACH = 'No files were attached'
|
|
165
174
|
}
|
|
166
175
|
|
|
167
176
|
export const enum DB_TRANSACTION {
|
|
@@ -175,6 +184,12 @@ export const enum DB_TRANSACTION {
|
|
|
175
184
|
CACHE = 128
|
|
176
185
|
}
|
|
177
186
|
|
|
187
|
+
export const enum TRANSFER_TYPE {
|
|
188
|
+
DISK = 1,
|
|
189
|
+
STREAM = 2,
|
|
190
|
+
CHUNK = 4
|
|
191
|
+
}
|
|
192
|
+
|
|
178
193
|
export const enum TIME {
|
|
179
194
|
Y = 1000 * 60 * 60 * 24 * 7 * 52,
|
|
180
195
|
M = 1000 * 60 * 60 * 24 * 30,
|
|
@@ -247,6 +262,12 @@ export const enum LOG_TYPE {
|
|
|
247
262
|
DB = 65536
|
|
248
263
|
}
|
|
249
264
|
|
|
265
|
+
export const enum LOG_STATE {
|
|
266
|
+
STDIN = 0,
|
|
267
|
+
STDOUT = 1,
|
|
268
|
+
STDERR = 2
|
|
269
|
+
}
|
|
270
|
+
|
|
250
271
|
export const enum READDIR_SORT {
|
|
251
272
|
FILE = 0,
|
|
252
273
|
DIRECTORY = 1,
|
package/index.d.ts
CHANGED
|
@@ -56,6 +56,18 @@ declare namespace types {
|
|
|
56
56
|
DB: 65536;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
interface LOG_STATE {
|
|
60
|
+
STDIN: 0;
|
|
61
|
+
STDOUT: 1;
|
|
62
|
+
STDERR: 2;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const LOG_STATE: {
|
|
66
|
+
STDIN: 0;
|
|
67
|
+
STDOUT: 1;
|
|
68
|
+
STDERR: 2;
|
|
69
|
+
};
|
|
70
|
+
|
|
59
71
|
interface STATUS_TYPE {
|
|
60
72
|
UNKNOWN: 0;
|
|
61
73
|
FATAL: 1;
|
|
@@ -202,6 +214,18 @@ declare namespace types {
|
|
|
202
214
|
CACHE: 128;
|
|
203
215
|
};
|
|
204
216
|
|
|
217
|
+
interface TRANSFER_TYPE {
|
|
218
|
+
DISK: 1;
|
|
219
|
+
STREAM: 2;
|
|
220
|
+
CHUNK: 4;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const TRANSFER_TYPE: {
|
|
224
|
+
DISK: 1;
|
|
225
|
+
STREAM: 2;
|
|
226
|
+
CHUNK: 4;
|
|
227
|
+
};
|
|
228
|
+
|
|
205
229
|
interface WATCH_EVENT {
|
|
206
230
|
MODIFIED: "modified";
|
|
207
231
|
BROADCAST: "broadcast";
|
|
@@ -244,6 +268,7 @@ declare namespace types {
|
|
|
244
268
|
|
|
245
269
|
type WatchEventValue = WATCH_EVENT[keyof WATCH_EVENT];
|
|
246
270
|
|
|
271
|
+
function createAbortError(reject: true): Promise<never>;
|
|
247
272
|
function createAbortError(): AbortError;
|
|
248
273
|
function hasBit(value: unknown, flags: number): boolean;
|
|
249
274
|
function ignoreFlag(value: unknown): boolean;
|
package/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.
|
|
4
|
-
exports.generateUUID = exports.purgeMemory = void 0;
|
|
2
|
+
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.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_TYPE = void 0;
|
|
3
|
+
exports.generateUUID = exports.incrementUUID = exports.purgeMemory = exports.errorMessage = exports.errorValue = exports.validateUUID = void 0;
|
|
5
4
|
const path = require("path");
|
|
6
5
|
const fs = require("fs");
|
|
7
6
|
const crypto = require("crypto");
|
|
8
|
-
const uuid = require("uuid");
|
|
9
7
|
const bytes = require("bytes");
|
|
10
8
|
class AbortError extends Error {
|
|
11
9
|
constructor() {
|
|
@@ -15,11 +13,15 @@ class AbortError extends Error {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
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;
|
|
18
|
-
const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)
|
|
16
|
+
const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)[\w_$]*\s*\(([^)]*)\)\s*\{([\S\s]*)\})$/;
|
|
17
|
+
const REGEXP_FUNCTION_ARROW = /^(async\s+)?(\(([^)]*)\)\s*=>\s*(?:\{([\S\s]*)\}|(?!\s|{)((?:(?<!return\s+)(?:"[^"\n]*"|'[^'\n]*'|`[^`]*`|[^\n;"'`]))*;)))$/;
|
|
18
|
+
const REGEXP_GLOB = /(?<!\\)(?:(?:[^*]|^)\*{1,2}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/;
|
|
19
19
|
const ASYNC_FUNCTION = Object.getPrototypeOf(async () => { }).constructor;
|
|
20
20
|
let CACHE_COERCED = new WeakSet();
|
|
21
21
|
let LOG_CURRENT = null;
|
|
22
22
|
let TEMP_DIR = path.join(process.cwd(), "tmp");
|
|
23
|
+
let INCREMENT_COUNT = 65536;
|
|
24
|
+
let INCREMENT_PREFIX = '';
|
|
23
25
|
function fromObject(value, typedArray) {
|
|
24
26
|
if (isObject(value)) {
|
|
25
27
|
if (value instanceof Map) {
|
|
@@ -234,6 +236,12 @@ var DB_TRANSACTION;
|
|
|
234
236
|
DB_TRANSACTION[DB_TRANSACTION["AUTH"] = 64] = "AUTH";
|
|
235
237
|
DB_TRANSACTION[DB_TRANSACTION["CACHE"] = 128] = "CACHE";
|
|
236
238
|
})(DB_TRANSACTION || (exports.DB_TRANSACTION = DB_TRANSACTION = {}));
|
|
239
|
+
var TRANSFER_TYPE;
|
|
240
|
+
(function (TRANSFER_TYPE) {
|
|
241
|
+
TRANSFER_TYPE[TRANSFER_TYPE["DISK"] = 1] = "DISK";
|
|
242
|
+
TRANSFER_TYPE[TRANSFER_TYPE["STREAM"] = 2] = "STREAM";
|
|
243
|
+
TRANSFER_TYPE[TRANSFER_TYPE["CHUNK"] = 4] = "CHUNK";
|
|
244
|
+
})(TRANSFER_TYPE || (exports.TRANSFER_TYPE = TRANSFER_TYPE = {}));
|
|
237
245
|
var WATCH_EVENT;
|
|
238
246
|
(function (WATCH_EVENT) {
|
|
239
247
|
WATCH_EVENT["MODIFIED"] = "modified";
|
|
@@ -241,6 +249,18 @@ var WATCH_EVENT;
|
|
|
241
249
|
WATCH_EVENT["CLOSE"] = "close";
|
|
242
250
|
WATCH_EVENT["ERROR"] = "error";
|
|
243
251
|
})(WATCH_EVENT || (exports.WATCH_EVENT = WATCH_EVENT = {}));
|
|
252
|
+
var READDIR_SORT;
|
|
253
|
+
(function (READDIR_SORT) {
|
|
254
|
+
READDIR_SORT[READDIR_SORT["FILE"] = 0] = "FILE";
|
|
255
|
+
READDIR_SORT[READDIR_SORT["DIRECTORY"] = 1] = "DIRECTORY";
|
|
256
|
+
READDIR_SORT[READDIR_SORT["DESCENDING"] = 2] = "DESCENDING";
|
|
257
|
+
})(READDIR_SORT || (exports.READDIR_SORT = READDIR_SORT = {}));
|
|
258
|
+
var THRESHOLD;
|
|
259
|
+
(function (THRESHOLD) {
|
|
260
|
+
THRESHOLD[THRESHOLD["FILEMANAGER_INTERVAL"] = 100] = "FILEMANAGER_INTERVAL";
|
|
261
|
+
THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
|
|
262
|
+
THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
|
|
263
|
+
})(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
|
|
244
264
|
var IMPORT_MAP;
|
|
245
265
|
(function (IMPORT_MAP) {
|
|
246
266
|
IMPORT_MAP["@squared-functions/cloud"] = "@e-mc/cloud";
|
|
@@ -321,14 +341,9 @@ var IMPORT_MAP;
|
|
|
321
341
|
IMPORT_MAP["@squared-functions/document/packages/terser"] = "@pi-r/terser";
|
|
322
342
|
IMPORT_MAP["@squared-functions/document/packages/uglify-js"] = "@pi-r/uglify-js";
|
|
323
343
|
})(IMPORT_MAP || (exports.IMPORT_MAP = IMPORT_MAP = {}));
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
|
|
328
|
-
THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
|
|
329
|
-
})(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
|
|
330
|
-
function createAbortError() {
|
|
331
|
-
return new AbortError();
|
|
344
|
+
function createAbortError(reject) {
|
|
345
|
+
const result = new AbortError();
|
|
346
|
+
return (reject ? Promise.reject(result) : result);
|
|
332
347
|
}
|
|
333
348
|
exports.createAbortError = createAbortError;
|
|
334
349
|
function hasBit(value, flags) {
|
|
@@ -396,7 +411,7 @@ function isArray(value) {
|
|
|
396
411
|
}
|
|
397
412
|
exports.isArray = isArray;
|
|
398
413
|
function isPlainObject(value) {
|
|
399
|
-
return
|
|
414
|
+
return typeof value === 'object' && value !== null && (value.constructor === Object || Object.getPrototypeOf(value) === null);
|
|
400
415
|
}
|
|
401
416
|
exports.isPlainObject = isPlainObject;
|
|
402
417
|
function isObject(value) {
|
|
@@ -414,9 +429,8 @@ exports.isEmpty = isEmpty;
|
|
|
414
429
|
function parseTime(value, start = 0) {
|
|
415
430
|
const seconds = +value;
|
|
416
431
|
if (isNaN(seconds) && isString(value)) {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
while (match = pattern.exec(value.toLowerCase())) {
|
|
432
|
+
let result = 0;
|
|
433
|
+
for (const match of value.toLowerCase().matchAll(/\b([\d.]+)\s*(y|M|w|d|h|ms?|s)\b/g)) {
|
|
420
434
|
const n = +match[1];
|
|
421
435
|
if (isNaN(n)) {
|
|
422
436
|
continue;
|
|
@@ -476,13 +490,13 @@ function formatTime(value, elapsed, char = ' ') {
|
|
|
476
490
|
if (value < 1000) {
|
|
477
491
|
return value + 'ms';
|
|
478
492
|
}
|
|
479
|
-
|
|
480
|
-
|
|
493
|
+
if (value >= 3600000) {
|
|
494
|
+
const h = Math.floor(value / 3600000);
|
|
481
495
|
value -= h * 3600000;
|
|
482
496
|
result.push(h + 'h');
|
|
483
497
|
}
|
|
484
|
-
|
|
485
|
-
|
|
498
|
+
if (value >= 60000) {
|
|
499
|
+
const m = Math.floor(value / 60000);
|
|
486
500
|
value -= m * 60000;
|
|
487
501
|
result.push(m + 'm');
|
|
488
502
|
}
|
|
@@ -493,15 +507,19 @@ function formatTime(value, elapsed, char = ' ') {
|
|
|
493
507
|
}
|
|
494
508
|
exports.formatTime = formatTime;
|
|
495
509
|
function convertTime(value, format) {
|
|
510
|
+
let result;
|
|
496
511
|
if (Array.isArray(value)) {
|
|
497
|
-
const
|
|
498
|
-
|
|
512
|
+
const time = Math.ceil((value[0] * 1000000000 + value[1]) / 1000000);
|
|
513
|
+
result = format ? formatTime(time) : time;
|
|
499
514
|
}
|
|
500
|
-
|
|
515
|
+
else {
|
|
516
|
+
result = parseTime(value);
|
|
517
|
+
}
|
|
518
|
+
return result;
|
|
501
519
|
}
|
|
502
520
|
exports.convertTime = convertTime;
|
|
503
521
|
function hasGlob(value) {
|
|
504
|
-
return
|
|
522
|
+
return REGEXP_GLOB.test(value);
|
|
505
523
|
}
|
|
506
524
|
exports.hasGlob = hasGlob;
|
|
507
525
|
function escapePattern(value, lookBehind) {
|
|
@@ -563,11 +581,46 @@ function renameExt(value, ext, when) {
|
|
|
563
581
|
}
|
|
564
582
|
exports.renameExt = renameExt;
|
|
565
583
|
function formatSize(value, options) {
|
|
566
|
-
|
|
584
|
+
let result;
|
|
585
|
+
if (typeof value === 'number') {
|
|
586
|
+
result = bytes(value, options) || ('0' + (options?.unitSeparator || '') + 'B');
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
result = bytes(value) || 0;
|
|
590
|
+
}
|
|
591
|
+
return result;
|
|
567
592
|
}
|
|
568
593
|
exports.formatSize = formatSize;
|
|
594
|
+
function alignSize(value, kb = 0, factor = 0) {
|
|
595
|
+
if (value === undefined) {
|
|
596
|
+
return NaN;
|
|
597
|
+
}
|
|
598
|
+
let result = 0;
|
|
599
|
+
switch (typeof value) {
|
|
600
|
+
case 'number':
|
|
601
|
+
if (value < 0) {
|
|
602
|
+
return NaN;
|
|
603
|
+
}
|
|
604
|
+
result = Math.ceil(factor > 0 ? value * Math.pow(1024, factor) : value);
|
|
605
|
+
break;
|
|
606
|
+
case 'string':
|
|
607
|
+
result = formatSize(value);
|
|
608
|
+
if (result < 0) {
|
|
609
|
+
return NaN;
|
|
610
|
+
}
|
|
611
|
+
break;
|
|
612
|
+
default:
|
|
613
|
+
return NaN;
|
|
614
|
+
}
|
|
615
|
+
if (kb > 0) {
|
|
616
|
+
kb = Math.ceil(kb) * 1024;
|
|
617
|
+
return Math.ceil(result / kb) * kb;
|
|
618
|
+
}
|
|
619
|
+
return result;
|
|
620
|
+
}
|
|
621
|
+
exports.alignSize = alignSize;
|
|
569
622
|
function cascadeObject(data, query, fallback) {
|
|
570
|
-
if (isObject(data)
|
|
623
|
+
if (isObject(data)) {
|
|
571
624
|
const names = query.trim().split(/(?<!\\)\./).map(item => item.includes('.') ? item.replace(/\\(?=\.)/g, '') : item);
|
|
572
625
|
for (let i = 0, length = names.length, match, current = data; i < length; ++i) {
|
|
573
626
|
if (!(match = /^(.+?)(?:\[(.+)\])?$/.exec(names[i]))) {
|
|
@@ -700,16 +753,16 @@ function coerceObject(data, parseString, cache) {
|
|
|
700
753
|
}
|
|
701
754
|
if (!parseString) {
|
|
702
755
|
parseString = (value) => {
|
|
703
|
-
if (value.length
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
756
|
+
if (value.length <= 8) {
|
|
757
|
+
return null;
|
|
758
|
+
}
|
|
759
|
+
switch (value.substring(0, 3)) {
|
|
760
|
+
case 'new': {
|
|
761
|
+
const match = /^new\s+(Date|RegExp|URL|Map|WeakMap|Set|WeakSet)\(([\S\s]*)\)$/.exec(value.trimEnd());
|
|
762
|
+
if (match) {
|
|
710
763
|
try {
|
|
711
764
|
const removeQuotes = (content) => content.trim().replace(/^["']/g, '').replace(/["']$/g, '').trim();
|
|
712
|
-
const errorCreate = () => errorValue(
|
|
765
|
+
const errorCreate = () => errorValue("Invalid parameters", match[2].trim());
|
|
713
766
|
switch (match[1]) {
|
|
714
767
|
case 'Date':
|
|
715
768
|
return new Date(match[2].replace(/["']/g, '').trim());
|
|
@@ -746,39 +799,39 @@ function coerceObject(data, parseString, cache) {
|
|
|
746
799
|
catch {
|
|
747
800
|
return undefined;
|
|
748
801
|
}
|
|
749
|
-
break;
|
|
750
802
|
}
|
|
751
|
-
|
|
752
|
-
if (value.substring(3, 5) === 'nc') {
|
|
753
|
-
return asFunction(value);
|
|
754
|
-
}
|
|
755
|
-
break;
|
|
756
|
-
case 'fun':
|
|
757
|
-
if (value.substring(3, 8) === 'ction') {
|
|
758
|
-
return asFunction(value);
|
|
759
|
-
}
|
|
760
|
-
break;
|
|
761
|
-
case 'Num':
|
|
762
|
-
switch (value) {
|
|
763
|
-
case 'Number.EPSILON':
|
|
764
|
-
return Number.EPSILON;
|
|
765
|
-
case 'Number.MAX_SAFE_INTEGER':
|
|
766
|
-
return Number.MAX_SAFE_INTEGER;
|
|
767
|
-
case 'Number.MAX_VALUE':
|
|
768
|
-
return Number.MAX_VALUE;
|
|
769
|
-
case 'Number.MIN_SAFE_INTEGER':
|
|
770
|
-
return Number.MIN_SAFE_INTEGER;
|
|
771
|
-
case 'Number.MIN_VALUE':
|
|
772
|
-
return Number.MIN_VALUE;
|
|
773
|
-
case 'Number.NaN':
|
|
774
|
-
return Number.NaN;
|
|
775
|
-
case 'Number.NEGATIVE_INFINITY':
|
|
776
|
-
return Number.NEGATIVE_INFINITY;
|
|
777
|
-
case 'Number.POSITIVE_INFINITY':
|
|
778
|
-
return Number.POSITIVE_INFINITY;
|
|
779
|
-
}
|
|
780
|
-
break;
|
|
803
|
+
break;
|
|
781
804
|
}
|
|
805
|
+
case 'asy':
|
|
806
|
+
if (value.substring(3, 5) === 'nc') {
|
|
807
|
+
return asFunction(value);
|
|
808
|
+
}
|
|
809
|
+
break;
|
|
810
|
+
case 'fun':
|
|
811
|
+
if (value.substring(3, 8) === 'ction') {
|
|
812
|
+
return asFunction(value);
|
|
813
|
+
}
|
|
814
|
+
break;
|
|
815
|
+
case 'Num':
|
|
816
|
+
switch (value) {
|
|
817
|
+
case 'Number.EPSILON':
|
|
818
|
+
return Number.EPSILON;
|
|
819
|
+
case 'Number.MAX_SAFE_INTEGER':
|
|
820
|
+
return Number.MAX_SAFE_INTEGER;
|
|
821
|
+
case 'Number.MAX_VALUE':
|
|
822
|
+
return Number.MAX_VALUE;
|
|
823
|
+
case 'Number.MIN_SAFE_INTEGER':
|
|
824
|
+
return Number.MIN_SAFE_INTEGER;
|
|
825
|
+
case 'Number.MIN_VALUE':
|
|
826
|
+
return Number.MIN_VALUE;
|
|
827
|
+
case 'Number.NaN':
|
|
828
|
+
return Number.NaN;
|
|
829
|
+
case 'Number.NEGATIVE_INFINITY':
|
|
830
|
+
return Number.NEGATIVE_INFINITY;
|
|
831
|
+
case 'Number.POSITIVE_INFINITY':
|
|
832
|
+
return Number.POSITIVE_INFINITY;
|
|
833
|
+
}
|
|
834
|
+
break;
|
|
782
835
|
}
|
|
783
836
|
return null;
|
|
784
837
|
};
|
|
@@ -797,10 +850,10 @@ function asFunction(value, sync = true) {
|
|
|
797
850
|
return value;
|
|
798
851
|
}
|
|
799
852
|
let match;
|
|
800
|
-
if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()))) {
|
|
853
|
+
if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()) || REGEXP_FUNCTION_ARROW.exec(value))) {
|
|
801
854
|
if (!sync || match[1]) {
|
|
802
|
-
const args = match[
|
|
803
|
-
args.push(match[5]);
|
|
855
|
+
const args = match[3].trim().split(/\s*,\s*/);
|
|
856
|
+
args.push(match[4] || (match[5] && (match[5] = 'return ' + match[5])));
|
|
804
857
|
return new ASYNC_FUNCTION(...args);
|
|
805
858
|
}
|
|
806
859
|
try {
|
|
@@ -816,7 +869,22 @@ function asFunction(value, sync = true) {
|
|
|
816
869
|
}
|
|
817
870
|
exports.asFunction = asFunction;
|
|
818
871
|
function getEncoding(value, fallback = 'utf-8') {
|
|
819
|
-
|
|
872
|
+
if (typeof value === 'string') {
|
|
873
|
+
switch (value = value.trim().toLowerCase()) {
|
|
874
|
+
case 'utf8':
|
|
875
|
+
case 'utf-8':
|
|
876
|
+
case 'utf16le':
|
|
877
|
+
return value;
|
|
878
|
+
case 'utf-16le':
|
|
879
|
+
case 'utf16':
|
|
880
|
+
case 'utf-16':
|
|
881
|
+
return 'utf16le';
|
|
882
|
+
}
|
|
883
|
+
if (Buffer.isEncoding(value)) {
|
|
884
|
+
return value;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return fallback;
|
|
820
888
|
}
|
|
821
889
|
exports.getEncoding = getEncoding;
|
|
822
890
|
function encryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
|
|
@@ -845,40 +913,35 @@ function randomString(format, dictionary) {
|
|
|
845
913
|
if (format !== '8-4-4-4-12' || dictionary) {
|
|
846
914
|
const match = format.match(/(\d+|[^\d]+)/g);
|
|
847
915
|
if (match) {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
916
|
+
dictionary || (dictionary = '0123456789abcdef');
|
|
917
|
+
const result = format.match(/(\d+|[^\d[]+|\[[^\]]+\]|\[)/g)?.reduce((a, b) => {
|
|
918
|
+
let length, available;
|
|
919
|
+
if (b.startsWith('[') && b.endsWith(']')) {
|
|
920
|
+
length = 1;
|
|
921
|
+
available = b.substring(1, b.length - 1);
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
if (isNaN(length = +b)) {
|
|
925
|
+
return a + b;
|
|
855
926
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
927
|
+
available = dictionary;
|
|
928
|
+
}
|
|
929
|
+
const upperBound = available.length;
|
|
930
|
+
if (isFunction(crypto.getRandomValues) && length > 1 && length <= 65536) {
|
|
931
|
+
const items = crypto.getRandomValues(new Uint32Array(length));
|
|
932
|
+
for (let i = 0; i < length; i++) {
|
|
933
|
+
a += available[items[i] % upperBound];
|
|
859
934
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
for (let i = 0; i < length; i++) {
|
|
865
|
-
a += available[items[i] % j];
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
else {
|
|
869
|
-
for (let i = 0; i < length; ++i) {
|
|
870
|
-
a += available[Math.floor(Math.random() * j)];
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
return a;
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
for (let i = 0; i < length; ++i) {
|
|
938
|
+
a += available[Math.floor(Math.random() * upperBound)];
|
|
874
939
|
}
|
|
875
|
-
return a + b;
|
|
876
|
-
}, '');
|
|
877
|
-
if (result) {
|
|
878
|
-
return result;
|
|
879
940
|
}
|
|
880
|
-
|
|
881
|
-
|
|
941
|
+
return a;
|
|
942
|
+
}, '');
|
|
943
|
+
if (result) {
|
|
944
|
+
return result;
|
|
882
945
|
}
|
|
883
946
|
}
|
|
884
947
|
}
|
|
@@ -901,4 +964,12 @@ function purgeMemory(percent) {
|
|
|
901
964
|
CACHE_COERCED = new WeakSet();
|
|
902
965
|
}
|
|
903
966
|
exports.purgeMemory = purgeMemory;
|
|
904
|
-
|
|
967
|
+
function incrementUUID(restart) {
|
|
968
|
+
if (restart || INCREMENT_COUNT === 65536) {
|
|
969
|
+
INCREMENT_COUNT = 0;
|
|
970
|
+
INCREMENT_PREFIX = (0, exports.generateUUID)().substring(0, 33);
|
|
971
|
+
}
|
|
972
|
+
return INCREMENT_PREFIX + (INCREMENT_COUNT++).toString(16).padStart(4, '0');
|
|
973
|
+
}
|
|
974
|
+
exports.incrementUUID = incrementUUID;
|
|
975
|
+
exports.generateUUID = typeof crypto.randomUUID === 'function' ? crypto.randomUUID.bind(crypto) : require('uuid').v4;
|
package/lib/asset.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export interface ExternalAsset extends FileAsset, BundleAction, BinaryAction, St
|
|
|
58
58
|
id?: number;
|
|
59
59
|
url?: URL;
|
|
60
60
|
socketPath?: string;
|
|
61
|
-
buffer?: Buffer
|
|
61
|
+
buffer?: Null<Buffer>;
|
|
62
62
|
localUri?: string;
|
|
63
63
|
fetchType?: FetchType;
|
|
64
64
|
sourceUTF8?: string;
|
|
@@ -72,4 +72,6 @@ export interface ExternalAsset extends FileAsset, BundleAction, BinaryAction, St
|
|
|
72
72
|
lastModified?: string;
|
|
73
73
|
contentLength?: number;
|
|
74
74
|
invalid?: boolean;
|
|
75
|
-
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type HashAlgorithm = "md5" | "sha1" | "sha256" | "sha224" | "sha384" | "sha512";
|