@e-mc/types 0.8.12 → 0.8.14
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 +3 -3
- package/constant.d.ts +1 -1
- package/index.js +91 -100
- package/lib/compress.d.ts +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.14/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogArguments } from "./lib/logger";
|
|
@@ -186,8 +186,8 @@ const IMPORT_MAP: Record<string, string | undefined>;
|
|
|
186
186
|
|
|
187
187
|
## References
|
|
188
188
|
|
|
189
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
190
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
189
|
+
- https://www.unpkg.com/@e-mc/types@0.8.14/lib/logger.d.ts
|
|
190
|
+
- https://www.unpkg.com/@e-mc/types@0.8.14/lib/module.d.ts
|
|
191
191
|
|
|
192
192
|
* https://nodejs.org/api/perf_hooks.html
|
|
193
193
|
* https://www.npmjs.com/package/@types/bytes
|
package/constant.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.
|
|
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;
|
|
4
5
|
const path = require("path");
|
|
5
6
|
const fs = require("fs");
|
|
6
7
|
const crypto = require("crypto");
|
|
@@ -14,8 +15,7 @@ class AbortError extends Error {
|
|
|
14
15
|
}
|
|
15
16
|
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
17
|
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}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/;
|
|
18
|
+
const REGEXP_FUNCTION_ARROW = /^(async\s+)?(\s*\(([^)]*)\)\s*=>\s*(?:\{([\S\s]*)\}|(?!\s|{)((?:(?<!return\s+)(?:"[^"\n]*"|'[^'\n]*'|`[^`]*`|[^\n;"'`]))*;)))$/;
|
|
19
19
|
const ASYNC_FUNCTION = Object.getPrototypeOf(async () => { }).constructor;
|
|
20
20
|
let CACHE_COERCED = new WeakSet();
|
|
21
21
|
let LOG_CURRENT = null;
|
|
@@ -236,12 +236,6 @@ var DB_TRANSACTION;
|
|
|
236
236
|
DB_TRANSACTION[DB_TRANSACTION["AUTH"] = 64] = "AUTH";
|
|
237
237
|
DB_TRANSACTION[DB_TRANSACTION["CACHE"] = 128] = "CACHE";
|
|
238
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 = {}));
|
|
245
239
|
var WATCH_EVENT;
|
|
246
240
|
(function (WATCH_EVENT) {
|
|
247
241
|
WATCH_EVENT["MODIFIED"] = "modified";
|
|
@@ -328,8 +322,8 @@ var IMPORT_MAP;
|
|
|
328
322
|
IMPORT_MAP["@squared-functions/document/packages/@babel/core"] = "@pi-r/babel";
|
|
329
323
|
IMPORT_MAP["@squared-functions/document/packages/clean-css"] = "@pi-r/clean-css";
|
|
330
324
|
IMPORT_MAP["@squared-functions/document/packages/eslint"] = "@pi-r/eslint";
|
|
331
|
-
IMPORT_MAP["@squared-functions/document/packages/html-minifier-terser"] = "@pi-r/html-minifier-terser";
|
|
332
325
|
IMPORT_MAP["@squared-functions/document/packages/html-minifier"] = "@pi-r/html-minifier";
|
|
326
|
+
IMPORT_MAP["@squared-functions/document/packages/html-minifier-terser"] = "@pi-r/html-minifier-terser";
|
|
333
327
|
IMPORT_MAP["@squared-functions/document/packages/html-validate"] = "@pi-r/html-validate";
|
|
334
328
|
IMPORT_MAP["@squared-functions/document/packages/postcss"] = "@pi-r/postcss";
|
|
335
329
|
IMPORT_MAP["@squared-functions/document/packages/posthtml"] = "@pi-r/posthtml";
|
|
@@ -341,9 +335,8 @@ var IMPORT_MAP;
|
|
|
341
335
|
IMPORT_MAP["@squared-functions/document/packages/terser"] = "@pi-r/terser";
|
|
342
336
|
IMPORT_MAP["@squared-functions/document/packages/uglify-js"] = "@pi-r/uglify-js";
|
|
343
337
|
})(IMPORT_MAP || (exports.IMPORT_MAP = IMPORT_MAP = {}));
|
|
344
|
-
function createAbortError(
|
|
345
|
-
|
|
346
|
-
return (reject ? Promise.reject(result) : result);
|
|
338
|
+
function createAbortError() {
|
|
339
|
+
return new AbortError();
|
|
347
340
|
}
|
|
348
341
|
exports.createAbortError = createAbortError;
|
|
349
342
|
function hasBit(value, flags) {
|
|
@@ -429,8 +422,9 @@ exports.isEmpty = isEmpty;
|
|
|
429
422
|
function parseTime(value, start = 0) {
|
|
430
423
|
const seconds = +value;
|
|
431
424
|
if (isNaN(seconds) && isString(value)) {
|
|
432
|
-
|
|
433
|
-
|
|
425
|
+
const pattern = /\b([\d.]+)\s*(y|M|w|d|h|ms?|s)\b/g;
|
|
426
|
+
let result = 0, match = null;
|
|
427
|
+
while (match = pattern.exec(value.toLowerCase())) {
|
|
434
428
|
const n = +match[1];
|
|
435
429
|
if (isNaN(n)) {
|
|
436
430
|
continue;
|
|
@@ -490,13 +484,13 @@ function formatTime(value, elapsed, char = ' ') {
|
|
|
490
484
|
if (value < 1000) {
|
|
491
485
|
return value + 'ms';
|
|
492
486
|
}
|
|
493
|
-
|
|
494
|
-
|
|
487
|
+
const h = Math.floor(value / 3600000);
|
|
488
|
+
if (h > 0) {
|
|
495
489
|
value -= h * 3600000;
|
|
496
490
|
result.push(h + 'h');
|
|
497
491
|
}
|
|
498
|
-
|
|
499
|
-
|
|
492
|
+
const m = Math.floor(value / 60000);
|
|
493
|
+
if (m > 0) {
|
|
500
494
|
value -= m * 60000;
|
|
501
495
|
result.push(m + 'm');
|
|
502
496
|
}
|
|
@@ -507,19 +501,15 @@ function formatTime(value, elapsed, char = ' ') {
|
|
|
507
501
|
}
|
|
508
502
|
exports.formatTime = formatTime;
|
|
509
503
|
function convertTime(value, format) {
|
|
510
|
-
let result;
|
|
511
504
|
if (Array.isArray(value)) {
|
|
512
|
-
const
|
|
513
|
-
|
|
505
|
+
const result = Math.ceil((value[0] * 1000000000 + value[1]) / 1000000);
|
|
506
|
+
return format ? formatTime(result) : result;
|
|
514
507
|
}
|
|
515
|
-
|
|
516
|
-
result = parseTime(value);
|
|
517
|
-
}
|
|
518
|
-
return result;
|
|
508
|
+
return parseTime(value);
|
|
519
509
|
}
|
|
520
510
|
exports.convertTime = convertTime;
|
|
521
511
|
function hasGlob(value) {
|
|
522
|
-
return
|
|
512
|
+
return /(?<!\\)(?:(?:[^*]|^)\*{1,2}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/.test(value);
|
|
523
513
|
}
|
|
524
514
|
exports.hasGlob = hasGlob;
|
|
525
515
|
function escapePattern(value, lookBehind) {
|
|
@@ -581,14 +571,10 @@ function renameExt(value, ext, when) {
|
|
|
581
571
|
}
|
|
582
572
|
exports.renameExt = renameExt;
|
|
583
573
|
function formatSize(value, options) {
|
|
584
|
-
let result;
|
|
585
574
|
if (typeof value === 'number') {
|
|
586
|
-
|
|
575
|
+
return (bytes(value, options) || ('0' + ((options === null || options === void 0 ? void 0 : options.unitSeparator) || '') + 'B'));
|
|
587
576
|
}
|
|
588
|
-
|
|
589
|
-
result = bytes(value) || 0;
|
|
590
|
-
}
|
|
591
|
-
return result;
|
|
577
|
+
return (bytes(value) || 0);
|
|
592
578
|
}
|
|
593
579
|
exports.formatSize = formatSize;
|
|
594
580
|
function alignSize(value, kb = 0, factor = 0) {
|
|
@@ -620,7 +606,7 @@ function alignSize(value, kb = 0, factor = 0) {
|
|
|
620
606
|
}
|
|
621
607
|
exports.alignSize = alignSize;
|
|
622
608
|
function cascadeObject(data, query, fallback) {
|
|
623
|
-
if (isObject(data)) {
|
|
609
|
+
if (isObject(data) && isString(query)) {
|
|
624
610
|
const names = query.trim().split(/(?<!\\)\./).map(item => item.includes('.') ? item.replace(/\\(?=\.)/g, '') : item);
|
|
625
611
|
for (let i = 0, length = names.length, match, current = data; i < length; ++i) {
|
|
626
612
|
if (!(match = /^(.+?)(?:\[(.+)\])?$/.exec(names[i]))) {
|
|
@@ -753,16 +739,16 @@ function coerceObject(data, parseString, cache) {
|
|
|
753
739
|
}
|
|
754
740
|
if (!parseString) {
|
|
755
741
|
parseString = (value) => {
|
|
756
|
-
if (value.length
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
742
|
+
if (value.length > 8) {
|
|
743
|
+
switch (value.substring(0, 3)) {
|
|
744
|
+
case 'new': {
|
|
745
|
+
const match = /^new\s+(Date|RegExp|URL|Map|WeakMap|Set|WeakSet)\(([\S\s]*)\)$/.exec(value.trimEnd());
|
|
746
|
+
if (!match) {
|
|
747
|
+
break;
|
|
748
|
+
}
|
|
763
749
|
try {
|
|
764
750
|
const removeQuotes = (content) => content.trim().replace(/^["']/g, '').replace(/["']$/g, '').trim();
|
|
765
|
-
const errorCreate = () => errorValue(
|
|
751
|
+
const errorCreate = () => errorValue('Invalid parameters', match[2].trim());
|
|
766
752
|
switch (match[1]) {
|
|
767
753
|
case 'Date':
|
|
768
754
|
return new Date(match[2].replace(/["']/g, '').trim());
|
|
@@ -799,39 +785,39 @@ function coerceObject(data, parseString, cache) {
|
|
|
799
785
|
catch {
|
|
800
786
|
return undefined;
|
|
801
787
|
}
|
|
788
|
+
break;
|
|
802
789
|
}
|
|
803
|
-
|
|
790
|
+
case 'asy':
|
|
791
|
+
if (value.substring(3, 5) === 'nc') {
|
|
792
|
+
return asFunction(value);
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
case 'fun':
|
|
796
|
+
if (value.substring(3, 8) === 'ction') {
|
|
797
|
+
return asFunction(value);
|
|
798
|
+
}
|
|
799
|
+
break;
|
|
800
|
+
case 'Num':
|
|
801
|
+
switch (value) {
|
|
802
|
+
case 'Number.EPSILON':
|
|
803
|
+
return Number.EPSILON;
|
|
804
|
+
case 'Number.MAX_SAFE_INTEGER':
|
|
805
|
+
return Number.MAX_SAFE_INTEGER;
|
|
806
|
+
case 'Number.MAX_VALUE':
|
|
807
|
+
return Number.MAX_VALUE;
|
|
808
|
+
case 'Number.MIN_SAFE_INTEGER':
|
|
809
|
+
return Number.MIN_SAFE_INTEGER;
|
|
810
|
+
case 'Number.MIN_VALUE':
|
|
811
|
+
return Number.MIN_VALUE;
|
|
812
|
+
case 'Number.NaN':
|
|
813
|
+
return Number.NaN;
|
|
814
|
+
case 'Number.NEGATIVE_INFINITY':
|
|
815
|
+
return Number.NEGATIVE_INFINITY;
|
|
816
|
+
case 'Number.POSITIVE_INFINITY':
|
|
817
|
+
return Number.POSITIVE_INFINITY;
|
|
818
|
+
}
|
|
819
|
+
break;
|
|
804
820
|
}
|
|
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
821
|
}
|
|
836
822
|
return null;
|
|
837
823
|
};
|
|
@@ -913,35 +899,40 @@ function randomString(format, dictionary) {
|
|
|
913
899
|
if (format !== '8-4-4-4-12' || dictionary) {
|
|
914
900
|
const match = format.match(/(\d+|[^\d]+)/g);
|
|
915
901
|
if (match) {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
else {
|
|
924
|
-
if (isNaN(length = +b)) {
|
|
925
|
-
return a + b;
|
|
902
|
+
try {
|
|
903
|
+
dictionary || (dictionary = '0123456789abcdef');
|
|
904
|
+
const result = format.match(/(\d+|[^\d[]+|\[[^\]]+\]|\[)/g).reduce((a, b) => {
|
|
905
|
+
let length, available;
|
|
906
|
+
if (b.startsWith('[') && b.endsWith(']')) {
|
|
907
|
+
length = 1;
|
|
908
|
+
available = b.substring(1, b.length - 1);
|
|
926
909
|
}
|
|
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];
|
|
910
|
+
else {
|
|
911
|
+
length = +b;
|
|
912
|
+
available = dictionary;
|
|
934
913
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
914
|
+
if (!isNaN(length)) {
|
|
915
|
+
const j = available.length;
|
|
916
|
+
if (isFunction(crypto.getRandomValues) && length > 1) {
|
|
917
|
+
const items = crypto.getRandomValues(new Uint32Array(length));
|
|
918
|
+
for (let i = 0; i < length; i++) {
|
|
919
|
+
a += available[items[i] % j];
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
else {
|
|
923
|
+
for (let i = 0; i < length; ++i) {
|
|
924
|
+
a += available[Math.floor(Math.random() * j)];
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return a;
|
|
939
928
|
}
|
|
929
|
+
return a + b;
|
|
930
|
+
}, '');
|
|
931
|
+
if (result) {
|
|
932
|
+
return result;
|
|
940
933
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if (result) {
|
|
944
|
-
return result;
|
|
934
|
+
}
|
|
935
|
+
catch {
|
|
945
936
|
}
|
|
946
937
|
}
|
|
947
938
|
}
|
|
@@ -972,4 +963,4 @@ function incrementUUID(restart) {
|
|
|
972
963
|
return INCREMENT_PREFIX + (INCREMENT_COUNT++).toString(16).padStart(4, '0');
|
|
973
964
|
}
|
|
974
965
|
exports.incrementUUID = incrementUUID;
|
|
975
|
-
exports.generateUUID = crypto.randomUUID.bind(crypto);
|
|
966
|
+
exports.generateUUID = typeof crypto.randomUUID === 'function' ? crypto.randomUUID.bind(crypto) : require('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>;
|