@e-mc/types 0.6.5 → 0.6.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/README.md +0 -2
- package/constant.d.ts +1 -1
- package/index.js +101 -172
- package/lib/compress.d.ts +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
package/constant.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
4
5
|
const path = require("path");
|
|
5
6
|
const fs = require("fs");
|
|
6
7
|
const crypto = require("crypto");
|
|
8
|
+
const uuid = require("uuid");
|
|
7
9
|
const bytes = require("bytes");
|
|
8
10
|
class AbortError extends Error {
|
|
9
11
|
constructor() {
|
|
@@ -13,15 +15,11 @@ class AbortError extends Error {
|
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
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;
|
|
16
|
-
const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)[\w_$]
|
|
17
|
-
const REGEXP_FUNCTION_ARROW = /^(async\s+)?(\(([^)]*)\)\s*=>\s*(?:\{([\S\s]*)\}|(?!\s|{)((?:(?<!return\s+)(?:"[^"\n]*"|'[^'\n]*'|`[^`]*`|[^\n;"'`]))*;)))$/;
|
|
18
|
-
const REGEXP_GLOB = /(?<!\\)(?:(?:[^*]|^)\*{1,2}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/;
|
|
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
22
|
let TEMP_DIR = path.join(process.cwd(), "tmp");
|
|
23
|
-
let INCREMENT_COUNT = 65536;
|
|
24
|
-
let INCREMENT_PREFIX = '';
|
|
25
23
|
function fromObject(value, typedArray) {
|
|
26
24
|
if (isObject(value)) {
|
|
27
25
|
if (value instanceof Map) {
|
|
@@ -236,12 +234,6 @@ var DB_TRANSACTION;
|
|
|
236
234
|
DB_TRANSACTION[DB_TRANSACTION["AUTH"] = 64] = "AUTH";
|
|
237
235
|
DB_TRANSACTION[DB_TRANSACTION["CACHE"] = 128] = "CACHE";
|
|
238
236
|
})(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 = {}));
|
|
245
237
|
var WATCH_EVENT;
|
|
246
238
|
(function (WATCH_EVENT) {
|
|
247
239
|
WATCH_EVENT["MODIFIED"] = "modified";
|
|
@@ -249,18 +241,6 @@ var WATCH_EVENT;
|
|
|
249
241
|
WATCH_EVENT["CLOSE"] = "close";
|
|
250
242
|
WATCH_EVENT["ERROR"] = "error";
|
|
251
243
|
})(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 = {}));
|
|
264
244
|
var IMPORT_MAP;
|
|
265
245
|
(function (IMPORT_MAP) {
|
|
266
246
|
IMPORT_MAP["@squared-functions/cloud"] = "@e-mc/cloud";
|
|
@@ -341,9 +321,14 @@ var IMPORT_MAP;
|
|
|
341
321
|
IMPORT_MAP["@squared-functions/document/packages/terser"] = "@pi-r/terser";
|
|
342
322
|
IMPORT_MAP["@squared-functions/document/packages/uglify-js"] = "@pi-r/uglify-js";
|
|
343
323
|
})(IMPORT_MAP || (exports.IMPORT_MAP = IMPORT_MAP = {}));
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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 = {}));
|
|
330
|
+
function createAbortError() {
|
|
331
|
+
return new AbortError();
|
|
347
332
|
}
|
|
348
333
|
exports.createAbortError = createAbortError;
|
|
349
334
|
function hasBit(value, flags) {
|
|
@@ -411,7 +396,7 @@ function isArray(value) {
|
|
|
411
396
|
}
|
|
412
397
|
exports.isArray = isArray;
|
|
413
398
|
function isPlainObject(value) {
|
|
414
|
-
return typeof value === 'object'
|
|
399
|
+
return value && typeof value === 'object' ? value.constructor === Object || Object.getPrototypeOf(value) === null : false;
|
|
415
400
|
}
|
|
416
401
|
exports.isPlainObject = isPlainObject;
|
|
417
402
|
function isObject(value) {
|
|
@@ -429,8 +414,9 @@ exports.isEmpty = isEmpty;
|
|
|
429
414
|
function parseTime(value, start = 0) {
|
|
430
415
|
const seconds = +value;
|
|
431
416
|
if (isNaN(seconds) && isString(value)) {
|
|
432
|
-
|
|
433
|
-
|
|
417
|
+
const pattern = /\b([\d.]+)\s*(y|M|w|d|h|ms?|s)\b/g;
|
|
418
|
+
let result = 0, match = null;
|
|
419
|
+
while (match = pattern.exec(value.toLowerCase())) {
|
|
434
420
|
const n = +match[1];
|
|
435
421
|
if (isNaN(n)) {
|
|
436
422
|
continue;
|
|
@@ -490,13 +476,13 @@ function formatTime(value, elapsed, char = ' ') {
|
|
|
490
476
|
if (value < 1000) {
|
|
491
477
|
return value + 'ms';
|
|
492
478
|
}
|
|
493
|
-
|
|
494
|
-
|
|
479
|
+
const h = Math.floor(value / 3600000);
|
|
480
|
+
if (h > 0) {
|
|
495
481
|
value -= h * 3600000;
|
|
496
482
|
result.push(h + 'h');
|
|
497
483
|
}
|
|
498
|
-
|
|
499
|
-
|
|
484
|
+
const m = Math.floor(value / 60000);
|
|
485
|
+
if (m > 0) {
|
|
500
486
|
value -= m * 60000;
|
|
501
487
|
result.push(m + 'm');
|
|
502
488
|
}
|
|
@@ -507,19 +493,15 @@ function formatTime(value, elapsed, char = ' ') {
|
|
|
507
493
|
}
|
|
508
494
|
exports.formatTime = formatTime;
|
|
509
495
|
function convertTime(value, format) {
|
|
510
|
-
let result;
|
|
511
496
|
if (Array.isArray(value)) {
|
|
512
|
-
const
|
|
513
|
-
|
|
497
|
+
const result = Math.ceil((value[0] * 1000000000 + value[1]) / 1000000);
|
|
498
|
+
return format ? formatTime(result) : result;
|
|
514
499
|
}
|
|
515
|
-
|
|
516
|
-
result = parseTime(value);
|
|
517
|
-
}
|
|
518
|
-
return result;
|
|
500
|
+
return parseTime(value);
|
|
519
501
|
}
|
|
520
502
|
exports.convertTime = convertTime;
|
|
521
503
|
function hasGlob(value) {
|
|
522
|
-
return
|
|
504
|
+
return /(?<!\\)(?:(?:[^*]|^)\*{1,2}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/.test(value);
|
|
523
505
|
}
|
|
524
506
|
exports.hasGlob = hasGlob;
|
|
525
507
|
function escapePattern(value, lookBehind) {
|
|
@@ -581,46 +563,11 @@ function renameExt(value, ext, when) {
|
|
|
581
563
|
}
|
|
582
564
|
exports.renameExt = renameExt;
|
|
583
565
|
function formatSize(value, options) {
|
|
584
|
-
|
|
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;
|
|
566
|
+
return (typeof value === 'number' ? bytes(value, options) : bytes(value));
|
|
592
567
|
}
|
|
593
568
|
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;
|
|
622
569
|
function cascadeObject(data, query, fallback) {
|
|
623
|
-
if (isObject(data)) {
|
|
570
|
+
if (isObject(data) && isString(query)) {
|
|
624
571
|
const names = query.trim().split(/(?<!\\)\./).map(item => item.includes('.') ? item.replace(/\\(?=\.)/g, '') : item);
|
|
625
572
|
for (let i = 0, length = names.length, match, current = data; i < length; ++i) {
|
|
626
573
|
if (!(match = /^(.+?)(?:\[(.+)\])?$/.exec(names[i]))) {
|
|
@@ -753,16 +700,16 @@ function coerceObject(data, parseString, cache) {
|
|
|
753
700
|
}
|
|
754
701
|
if (!parseString) {
|
|
755
702
|
parseString = (value) => {
|
|
756
|
-
if (value.length
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
703
|
+
if (value.length > 8) {
|
|
704
|
+
switch (value.substring(0, 3)) {
|
|
705
|
+
case 'new': {
|
|
706
|
+
const match = /^new\s+(Date|RegExp|URL|Map|WeakMap|Set|WeakSet)\(([\S\s]*)\)$/.exec(value.trimEnd());
|
|
707
|
+
if (!match) {
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
763
710
|
try {
|
|
764
711
|
const removeQuotes = (content) => content.trim().replace(/^["']/g, '').replace(/["']$/g, '').trim();
|
|
765
|
-
const errorCreate = () => errorValue(
|
|
712
|
+
const errorCreate = () => errorValue('Invalid parameters', match[2].trim());
|
|
766
713
|
switch (match[1]) {
|
|
767
714
|
case 'Date':
|
|
768
715
|
return new Date(match[2].replace(/["']/g, '').trim());
|
|
@@ -799,39 +746,39 @@ function coerceObject(data, parseString, cache) {
|
|
|
799
746
|
catch {
|
|
800
747
|
return undefined;
|
|
801
748
|
}
|
|
749
|
+
break;
|
|
802
750
|
}
|
|
803
|
-
|
|
751
|
+
case 'asy':
|
|
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;
|
|
804
781
|
}
|
|
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;
|
|
835
782
|
}
|
|
836
783
|
return null;
|
|
837
784
|
};
|
|
@@ -850,10 +797,10 @@ function asFunction(value, sync = true) {
|
|
|
850
797
|
return value;
|
|
851
798
|
}
|
|
852
799
|
let match;
|
|
853
|
-
if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim())
|
|
800
|
+
if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()))) {
|
|
854
801
|
if (!sync || match[1]) {
|
|
855
|
-
const args = match[
|
|
856
|
-
args.push(match[
|
|
802
|
+
const args = match[4].trim().split(/\s*,\s*/);
|
|
803
|
+
args.push(match[5]);
|
|
857
804
|
return new ASYNC_FUNCTION(...args);
|
|
858
805
|
}
|
|
859
806
|
try {
|
|
@@ -869,22 +816,7 @@ function asFunction(value, sync = true) {
|
|
|
869
816
|
}
|
|
870
817
|
exports.asFunction = asFunction;
|
|
871
818
|
function getEncoding(value, fallback = 'utf-8') {
|
|
872
|
-
|
|
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;
|
|
819
|
+
return typeof value === 'string' && Buffer.isEncoding(value = value.trim().toLowerCase()) ? value : fallback;
|
|
888
820
|
}
|
|
889
821
|
exports.getEncoding = getEncoding;
|
|
890
822
|
function encryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
|
|
@@ -913,35 +845,40 @@ function randomString(format, dictionary) {
|
|
|
913
845
|
if (format !== '8-4-4-4-12' || dictionary) {
|
|
914
846
|
const match = format.match(/(\d+|[^\d]+)/g);
|
|
915
847
|
if (match) {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
else {
|
|
924
|
-
if (isNaN(length = +b)) {
|
|
925
|
-
return a + b;
|
|
848
|
+
try {
|
|
849
|
+
dictionary || (dictionary = '0123456789abcdef');
|
|
850
|
+
const result = format.match(/(\d+|[^\d[]+|\[[^\]]+\]|\[)/g).reduce((a, b) => {
|
|
851
|
+
let length, available;
|
|
852
|
+
if (b.startsWith('[') && b.endsWith(']')) {
|
|
853
|
+
length = 1;
|
|
854
|
+
available = b.substring(1, b.length - 1);
|
|
926
855
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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];
|
|
856
|
+
else {
|
|
857
|
+
length = +b;
|
|
858
|
+
available = dictionary;
|
|
934
859
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
860
|
+
if (!isNaN(length)) {
|
|
861
|
+
const j = available.length;
|
|
862
|
+
if (isFunction(crypto.getRandomValues) && length > 1) {
|
|
863
|
+
const items = crypto.getRandomValues(new Uint32Array(length));
|
|
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;
|
|
939
874
|
}
|
|
875
|
+
return a + b;
|
|
876
|
+
}, '');
|
|
877
|
+
if (result) {
|
|
878
|
+
return result;
|
|
940
879
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if (result) {
|
|
944
|
-
return result;
|
|
880
|
+
}
|
|
881
|
+
catch {
|
|
945
882
|
}
|
|
946
883
|
}
|
|
947
884
|
}
|
|
@@ -964,12 +901,4 @@ function purgeMemory(percent) {
|
|
|
964
901
|
CACHE_COERCED = new WeakSet();
|
|
965
902
|
}
|
|
966
903
|
exports.purgeMemory = purgeMemory;
|
|
967
|
-
function
|
|
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 = crypto.randomUUID.bind(crypto);
|
|
904
|
+
exports.generateUUID = typeof crypto.randomUUID === 'function' ? crypto.randomUUID.bind(crypto) : uuid.v4;
|
package/lib/compress.d.ts
CHANGED
|
@@ -2,21 +2,21 @@ import type { CompressFormat as ICompressFormat } from './squared';
|
|
|
2
2
|
|
|
3
3
|
import type { LogBaseOptions, LogTime } from './logger';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type ResultCallback<T = Null<Buffer | Uint8Array>> = (err: unknown, data?: T, ext?: string) => void;
|
|
6
|
+
type ResultData = Null<Buffer | Uint8Array> | string;
|
|
7
|
+
|
|
8
|
+
export interface CompressFormat extends ICompressFormat, LogBaseOptions {
|
|
6
9
|
filename?: string;
|
|
7
10
|
startTime?: LogTime;
|
|
8
11
|
etag?: string;
|
|
9
12
|
proxyUrl?: string | ((uri: string) => Undef<string>);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
interface Woff {
|
|
15
|
+
export interface Woff {
|
|
13
16
|
toWoff(this: void, data: BufferLike): Buffer;
|
|
14
17
|
toSfnt(this: void, data: BufferLike): Buffer;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
type ResultCallback<T = Null<Buffer | Uint8Array>> = (err: unknown, data?: T, ext?: string) => void;
|
|
18
|
-
type ResultData = Null<Buffer | Uint8Array> | string;
|
|
19
|
-
|
|
20
20
|
export type BufferLike = Buffer | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly number[];
|
|
21
21
|
export type TryFileCompressor = (data: string | Buffer, output: string, config: CompressFormat, callback?: TryFileResult) => Void<Promise<ResultData>>;
|
|
22
22
|
export type TryFileCompressorAsync = (data: string | Buffer, output: string, config: CompressFormat) => Promise<ResultData>;
|