@e-mc/types 0.5.4 → 0.5.5
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 +1 -1
- package/constant.d.ts +1 -1
- package/index.js +42 -104
- package/lib/core.d.ts +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Anya Forger
|
|
2
2
|
|
|
3
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:
|
|
4
4
|
|
package/constant.d.ts
CHANGED
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.
|
|
4
|
-
exports.generateUUID = exports.
|
|
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"
|
|
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_$]
|
|
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"
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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'
|
|
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
|
|
426
|
+
result += n * 31449600000;
|
|
435
427
|
break;
|
|
436
428
|
case 'M':
|
|
437
|
-
result += n * 2592000000
|
|
429
|
+
result += n * 2592000000;
|
|
438
430
|
break;
|
|
439
431
|
case 'w':
|
|
440
|
-
result += n * 604800000
|
|
432
|
+
result += n * 604800000;
|
|
441
433
|
break;
|
|
442
434
|
case 'd':
|
|
443
|
-
result += n * 86400000
|
|
435
|
+
result += n * 86400000;
|
|
444
436
|
break;
|
|
445
437
|
case 'h':
|
|
446
|
-
result += n * 3600000
|
|
438
|
+
result += n * 3600000;
|
|
447
439
|
break;
|
|
448
440
|
case 'm':
|
|
449
|
-
result += n * 60000
|
|
441
|
+
result += n * 60000;
|
|
450
442
|
break;
|
|
451
443
|
case 's':
|
|
452
|
-
result += n * 1000
|
|
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
|
|
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
|
|
479
|
+
const h = Math.floor(value / 3600000);
|
|
488
480
|
if (h > 0) {
|
|
489
|
-
value -= h * 3600000
|
|
481
|
+
value -= h * 3600000;
|
|
490
482
|
result.push(h + 'h');
|
|
491
483
|
}
|
|
492
|
-
const m = Math.floor(value / 60000
|
|
484
|
+
const m = Math.floor(value / 60000);
|
|
493
485
|
if (m > 0) {
|
|
494
|
-
value -= m * 60000
|
|
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
|
|
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
|
-
|
|
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 = [];
|
|
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())
|
|
800
|
+
if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()))) {
|
|
840
801
|
if (!sync || match[1]) {
|
|
841
|
-
const args = match[
|
|
842
|
-
args.push(match[
|
|
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
|
-
|
|
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
|
|
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
|
set cacheDir(value: string);
|
|
18
18
|
get cacheDir(): string;
|