@wener/utils 1.1.5 → 1.1.6
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 -1
- package/dist/cjs/_commonjsHelpers-dfec268f.js +2 -0
- package/dist/cjs/_commonjsHelpers-dfec268f.js.map +1 -0
- package/dist/cjs/api-7db97ae3.js +1085 -0
- package/dist/cjs/api-7db97ae3.js.map +1 -0
- package/dist/cjs/index-a6d1d653.js +14 -0
- package/dist/cjs/index-a6d1d653.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/multipart-parser-141ed517.js +3 -0
- package/dist/cjs/multipart-parser-141ed517.js.map +1 -0
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/esm/_commonjsHelpers-28e086c5.js +2 -0
- package/dist/esm/_commonjsHelpers-28e086c5.js.map +1 -0
- package/dist/esm/api-3f555472.js +1085 -0
- package/dist/esm/api-3f555472.js.map +1 -0
- package/dist/esm/index-b50fef91.js +14 -0
- package/dist/esm/index-b50fef91.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/multipart-parser-5c1d6ee9.js +3 -0
- package/dist/esm/multipart-parser-5c1d6ee9.js.map +1 -0
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/system/_commonjsHelpers-07f370a7.js +2 -0
- package/dist/system/_commonjsHelpers-07f370a7.js.map +1 -0
- package/dist/system/api-dc50ebac.js +1085 -0
- package/dist/system/api-dc50ebac.js.map +1 -0
- package/dist/system/index-8f1807ba.js +14 -0
- package/dist/system/index-8f1807ba.js.map +1 -0
- package/dist/system/index.js +1 -1
- package/dist/system/index.js.map +1 -1
- package/dist/system/multipart-parser-53518ee9.js +3 -0
- package/dist/system/multipart-parser-53518ee9.js.map +1 -0
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/lib/asyncs/createLazyPromise.js +55 -0
- package/lib/asyncs/createLazyPromise.js.map +1 -0
- package/lib/crypto/randomUUID.js +3 -5
- package/lib/crypto/randomUUID.js.map +1 -1
- package/lib/i18n/createTranslate.js +37 -0
- package/lib/i18n/createTranslate.js.map +1 -0
- package/lib/index.js +11 -6
- package/lib/index.js.map +1 -1
- package/lib/io/isTransferable.js +23 -0
- package/lib/io/isTransferable.js.map +1 -0
- package/lib/isomorphics/structuredClone.js +70 -0
- package/lib/isomorphics/structuredClone.js.map +1 -0
- package/lib/langs/classOf.js +6 -0
- package/lib/langs/classOf.js.map +1 -0
- package/lib/{validations/dequal.js → langs/deepEqual.js} +7 -7
- package/lib/langs/deepEqual.js.map +1 -0
- package/lib/{validations/shallow.js → langs/shallowEqual.js} +3 -3
- package/lib/langs/shallowEqual.js.map +1 -0
- package/lib/server/polyfillBrowser.js +12 -0
- package/lib/server/polyfillBrowser.js.map +1 -0
- package/lib/server/polyfillCrypto.js +10 -0
- package/lib/server/polyfillCrypto.js.map +1 -0
- package/lib/server/polyfillFetch.js +31 -0
- package/lib/server/polyfillFetch.js.map +1 -0
- package/lib/server/polyfillJsDom.js +49 -0
- package/lib/server/polyfillJsDom.js.map +1 -0
- package/lib/server.js +4 -1
- package/lib/server.js.map +1 -1
- package/lib/{formats → strings}/formatBytes.js +0 -0
- package/lib/{formats → strings}/formatBytes.js.map +1 -1
- package/lib/strings/renderTemplate.js +3 -1
- package/lib/strings/renderTemplate.js.map +1 -1
- package/lib/validations/isUUID.js +6 -0
- package/lib/validations/isUUID.js.map +1 -0
- package/package.json +5 -1
- package/src/asyncs/createLazyPromise.test.ts +39 -0
- package/src/asyncs/createLazyPromise.ts +63 -0
- package/src/crypto/hashing.test.ts +11 -7
- package/src/crypto/randomUUID.ts +3 -4
- package/src/i18n/createTranslate.test.ts +155 -0
- package/src/i18n/createTranslate.ts +52 -0
- package/src/index.ts +20 -8
- package/src/io/isBuffer.test.ts +7 -0
- package/src/io/isTransferable.test.ts +10 -0
- package/src/io/isTransferable.ts +50 -0
- package/src/isomorphics/structuredClone.test.ts +14 -0
- package/src/isomorphics/structuredClone.ts +85 -0
- package/src/langs/classOf.ts +3 -0
- package/src/{validations/dequal.test.ts → langs/deepEqual.test.ts} +2 -2
- package/src/{validations/dequal.ts → langs/deepEqual.ts} +5 -5
- package/src/langs/langs.test.ts +23 -0
- package/src/{validations/shallow.ts → langs/shallowEqual.ts} +1 -1
- package/src/server/polyfillBrowser.test.ts +15 -0
- package/src/server/polyfillBrowser.ts +9 -0
- package/src/server/polyfillCrypto.ts +7 -0
- package/src/server/polyfillFetch.ts +29 -0
- package/src/server/polyfillJsDom.ts +84 -0
- package/src/server.ts +4 -1
- package/src/{formats → strings}/formatBytes.ts +0 -0
- package/src/strings/renderTemplate.ts +4 -1
- package/src/validations/isUUID.ts +3 -0
- package/lib/asyncs/LazyPromise.js +0 -27
- package/lib/asyncs/LazyPromise.js.map +0 -1
- package/lib/server/polyfill.js +0 -8
- package/lib/server/polyfill.js.map +0 -1
- package/lib/validations/dequal.js.map +0 -1
- package/lib/validations/shallow.js.map +0 -1
- package/src/asyncs/LazyPromise.ts +0 -29
- package/src/server/polyfill.ts +0 -5
package/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { arrayOfMaybeArray, firstOfMaybeArray, lastOfMaybeArray, objectOfMaybeAr
|
|
|
2
2
|
export { get } from './objects/get.js';
|
|
3
3
|
export { set } from './objects/set.js';
|
|
4
4
|
export { parseObjectPath } from './objects/parseObjectPath.js';
|
|
5
|
-
export { createLazyPromise } from './asyncs/
|
|
5
|
+
export { createLazyPromise } from './asyncs/createLazyPromise.js';
|
|
6
6
|
export { clearAsyncInterval, setAsyncInterval } from './asyncs/AsyncInterval.js';
|
|
7
7
|
export { sleep } from './asyncs/sleep.js';
|
|
8
8
|
export { TimeoutError, timeout } from './asyncs/timeout.js';
|
|
@@ -10,8 +10,10 @@ export { isPromise } from './asyncs/isPromise.js';
|
|
|
10
10
|
export { isClass } from './validations/isClass.js';
|
|
11
11
|
export { isDefined } from './validations/isDefined.js';
|
|
12
12
|
export { isEmptyObject } from './validations/isEmptyObject.js';
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
13
|
+
export { shallowEqual } from './langs/shallowEqual.js';
|
|
14
|
+
export { deepEqual } from './langs/deepEqual.js';
|
|
15
|
+
export { isUUID } from './validations/isUUID.js';
|
|
16
|
+
export { classOf } from './langs/classOf.js';
|
|
15
17
|
export { parseModuleId } from './modules/parseModuleId.js';
|
|
16
18
|
export { isModule } from './modules/isModule.js';
|
|
17
19
|
export { createWriteLogger } from './logging/createWriteLogger.js';
|
|
@@ -19,16 +21,19 @@ export { createNoopLogger } from './logging/createNoopLogger.js';
|
|
|
19
21
|
export { createChildLogger } from './logging/createChildLogger.js';
|
|
20
22
|
export { camelCase, pascalCase } from './strings/camelCase.js';
|
|
21
23
|
export { renderTemplate } from './strings/renderTemplate.js';
|
|
22
|
-
export {
|
|
24
|
+
export { formatBytes } from './strings/formatBytes.js';
|
|
25
|
+
export { createTranslate } from './i18n/createTranslate.js';
|
|
23
26
|
export { isBuffer } from './io/isBuffer.js';
|
|
27
|
+
export { isTransferable } from './io/isTransferable.js';
|
|
24
28
|
export { copy } from './browsers/copy.js';
|
|
25
29
|
export { download } from './browsers/download.js';
|
|
26
30
|
export { loadScripts, loadStyles } from './browsers/loaders.js';
|
|
27
31
|
export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer.js';
|
|
28
32
|
export { getGlobalThis } from './isomorphics/getGlobalThis.js';
|
|
29
|
-
export {
|
|
30
|
-
export { urljoin } from './shim/urljoin.js';
|
|
33
|
+
export { structuredClone } from './isomorphics/structuredClone.js';
|
|
31
34
|
export { randomUUID } from './crypto/randomUUID.js';
|
|
32
35
|
export { sha1, sha256, sha384, sha512 } from './crypto/hashing.js';
|
|
33
36
|
export { hex } from './crypto/hex.js';
|
|
37
|
+
export { createRandom } from './maths/random.js';
|
|
38
|
+
export { urljoin } from './shim/urljoin.js';
|
|
34
39
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function isTransferable(v) {
|
|
2
|
+
_ctors ||= ctors();
|
|
3
|
+
return _ctors.some((ctor) => v instanceof ctor);
|
|
4
|
+
}
|
|
5
|
+
let _ctors;
|
|
6
|
+
function ctors() {
|
|
7
|
+
const o = globalThis.window || globalThis || global;
|
|
8
|
+
return [
|
|
9
|
+
o.ArrayBuffer,
|
|
10
|
+
o.MessagePort,
|
|
11
|
+
o.ReadableStream,
|
|
12
|
+
o.WritableStream,
|
|
13
|
+
o.TransformStream,
|
|
14
|
+
o.AudioData,
|
|
15
|
+
o.ImageBitmap,
|
|
16
|
+
o.VideoFrame,
|
|
17
|
+
o.OffscreenCanvas,
|
|
18
|
+
o.RTCDataChannel
|
|
19
|
+
].filter(Boolean);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { isTransferable };
|
|
23
|
+
//# sourceMappingURL=isTransferable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isTransferable.js","sources":["../../src/io/isTransferable.ts"],"sourcesContent":["/**\n * transferable object pass between workers, can work with structuredClone\n *\n * - Chrome 87, FF 103, Safari X, NodeJS X\n *\n * {@link https://developer.mozilla.org/en-US/docs/Glossary/Transferable_objects | Transferable objects}\n */\nexport function isTransferable(v: any): v is TransferableObject {\n _ctors ||= ctors();\n return _ctors.some((ctor) => v instanceof ctor);\n}\n\nlet _ctors: any[];\n\nfunction ctors() {\n const o: any = globalThis.window || globalThis || global;\n return [\n o.ArrayBuffer,\n o.MessagePort,\n o.ReadableStream,\n o.WritableStream,\n o.TransformStream,\n o.AudioData,\n o.ImageBitmap,\n o.VideoFrame,\n o.OffscreenCanvas,\n o.RTCDataChannel,\n ].filter(Boolean);\n}\n\nexport type TransferableObject =\n | Transferable\n | ArrayBuffer\n | MessagePort\n | ReadableStream\n | WritableStream\n | TransformStream\n | AudioData\n | ImageBitmap\n | VideoFrame\n | OffscreenCanvas\n | RTCDataChannel;\n\ndeclare global {\n interface OffscreenCanvas {}\n\n interface VideoFrame {}\n\n interface AudioData {}\n}\n"],"names":[],"mappings":"AAOO,SAAS,eAAe,CAAiC,EAAA;AAC9D,EAAA,MAAA,KAAW,KAAM,EAAA,CAAA;AACjB,EAAA,OAAO,MAAO,CAAA,IAAA,CAAK,CAAC,IAAA,KAAS,aAAa,IAAI,CAAA,CAAA;AAChD,CAAA;AAEA,IAAI,MAAA,CAAA;AAEJ,SAAS,KAAQ,GAAA;AACf,EAAM,MAAA,CAAA,GAAS,UAAW,CAAA,MAAA,IAAU,UAAc,IAAA,MAAA,CAAA;AAClD,EAAO,OAAA;AAAA,IACL,CAAE,CAAA,WAAA;AAAA,IACF,CAAE,CAAA,WAAA;AAAA,IACF,CAAE,CAAA,cAAA;AAAA,IACF,CAAE,CAAA,cAAA;AAAA,IACF,CAAE,CAAA,eAAA;AAAA,IACF,CAAE,CAAA,SAAA;AAAA,IACF,CAAE,CAAA,WAAA;AAAA,IACF,CAAE,CAAA,UAAA;AAAA,IACF,CAAE,CAAA,eAAA;AAAA,IACF,CAAE,CAAA,cAAA;AAAA,GACJ,CAAE,OAAO,OAAO,CAAA,CAAA;AAClB;;;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { classOf } from '../langs/classOf.js';
|
|
2
|
+
|
|
3
|
+
const structuredClone = globalThis.structuredClone || _clone;
|
|
4
|
+
function set(obj, key, val) {
|
|
5
|
+
if (typeof val.value === "object")
|
|
6
|
+
val.value = _clone(val.value);
|
|
7
|
+
if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") {
|
|
8
|
+
Object.defineProperty(obj, key, val);
|
|
9
|
+
} else
|
|
10
|
+
obj[key] = val.value;
|
|
11
|
+
}
|
|
12
|
+
function _clone(x) {
|
|
13
|
+
if (typeof x !== "object")
|
|
14
|
+
return x;
|
|
15
|
+
let i = 0;
|
|
16
|
+
let k;
|
|
17
|
+
let list;
|
|
18
|
+
let tmp;
|
|
19
|
+
const str = classOf(x);
|
|
20
|
+
switch (str) {
|
|
21
|
+
case "Array":
|
|
22
|
+
tmp = Array(x.length);
|
|
23
|
+
break;
|
|
24
|
+
case "Object":
|
|
25
|
+
tmp = Object.create(x.__proto__ || null);
|
|
26
|
+
break;
|
|
27
|
+
case "Set":
|
|
28
|
+
tmp = /* @__PURE__ */ new Set();
|
|
29
|
+
x.forEach(function(val) {
|
|
30
|
+
tmp.add(_clone(val));
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
case "Map":
|
|
34
|
+
tmp = /* @__PURE__ */ new Map();
|
|
35
|
+
x.forEach(function(val, key) {
|
|
36
|
+
tmp.set(_clone(key), _clone(val));
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
case "Date":
|
|
40
|
+
tmp = new Date(+x);
|
|
41
|
+
break;
|
|
42
|
+
case "RegExp":
|
|
43
|
+
tmp = new RegExp(x.source, x.flags);
|
|
44
|
+
break;
|
|
45
|
+
case "DataView":
|
|
46
|
+
tmp = new x.constructor(_clone(x.buffer));
|
|
47
|
+
break;
|
|
48
|
+
case "ArrayBuffer":
|
|
49
|
+
tmp = x.slice(0);
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
if (str.endsWith("Array")) {
|
|
53
|
+
tmp = new x.constructor(x);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (tmp) {
|
|
57
|
+
for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {
|
|
58
|
+
set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
|
|
59
|
+
}
|
|
60
|
+
for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
|
|
61
|
+
if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k])
|
|
62
|
+
continue;
|
|
63
|
+
set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return tmp || x;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { _clone, structuredClone };
|
|
70
|
+
//# sourceMappingURL=structuredClone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structuredClone.js","sources":["../../src/isomorphics/structuredClone.ts"],"sourcesContent":["/**\n * Chrome 98, Safari 15.4\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/structuredClone structuredClone}\n * {@link https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.structured-clone.js core-js}\n */\nimport { classOf } from '../langs/classOf';\n\nexport const structuredClone: <T>(value: T, options?: StructuredSerializeOptions) => T =\n globalThis.structuredClone || _clone;\n\nfunction set(obj: any, key: any, val: any) {\n if (typeof val.value === 'object') val.value = _clone(val.value);\n if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {\n Object.defineProperty(obj, key, val);\n } else obj[key] = val.value;\n}\n\n/**\n * {@link https://github.com/lukeed/klona/blob/master/src/full.js klona}\n */\nexport function _clone(x: any): any {\n // too complex\n // https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.structured-clone.js\n\n if (typeof x !== 'object') return x;\n\n let i = 0;\n let k;\n let list;\n let tmp: any;\n const str = classOf(x);\n switch (str) {\n case 'Array':\n tmp = Array(x.length);\n break;\n case 'Object':\n tmp = Object.create(x.__proto__ || null);\n break;\n case 'Set':\n tmp = new Set();\n x.forEach(function (val: any) {\n tmp.add(_clone(val));\n });\n break;\n case 'Map':\n tmp = new Map();\n x.forEach(function (val: any, key: any) {\n tmp.set(_clone(key), _clone(val));\n });\n break;\n case 'Date':\n tmp = new Date(+x);\n break;\n case 'RegExp':\n tmp = new RegExp(x.source, x.flags);\n break;\n case 'DataView':\n tmp = new x.constructor(_clone(x.buffer));\n break;\n case 'ArrayBuffer':\n tmp = x.slice(0);\n break;\n default:\n // typed arrays\n if (str.endsWith('Array')) {\n // ArrayBuffer.isView(x)\n // ~> `new` bcuz `Buffer.slice` => ref\n tmp = new x.constructor(x);\n }\n }\n\n if (tmp) {\n for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {\n set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));\n }\n\n for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {\n if (Object.hasOwnProperty.call(tmp, (k = list[i])) && tmp[k] === x[k]) continue;\n set(tmp, k, Object.getOwnPropertyDescriptor(x, k));\n }\n }\n\n return tmp || x;\n}\n"],"names":[],"mappings":";;AAQa,MAAA,eAAA,GACX,WAAW,eAAmB,IAAA,OAAA;AAEhC,SAAS,GAAA,CAAI,GAAU,EAAA,GAAA,EAAU,GAAU,EAAA;AACzC,EAAI,IAAA,OAAO,IAAI,KAAU,KAAA,QAAA;AAAU,IAAI,GAAA,CAAA,KAAA,GAAQ,MAAO,CAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AAC/D,EAAA,IAAI,CAAC,GAAA,CAAI,UAAc,IAAA,GAAA,CAAI,OAAO,GAAI,CAAA,GAAA,IAAO,CAAC,GAAA,CAAI,YAAgB,IAAA,CAAC,GAAI,CAAA,QAAA,IAAY,QAAQ,WAAa,EAAA;AACtG,IAAO,MAAA,CAAA,cAAA,CAAe,GAAK,EAAA,GAAA,EAAK,GAAG,CAAA,CAAA;AAAA,GACrC;AAAO,IAAA,GAAA,CAAI,OAAO,GAAI,CAAA,KAAA,CAAA;AACxB,CAAA;AAKO,SAAS,OAAO,CAAa,EAAA;AAIlC,EAAA,IAAI,OAAO,CAAM,KAAA,QAAA;AAAU,IAAO,OAAA,CAAA,CAAA;AAElC,EAAA,IAAI,CAAI,GAAA,CAAA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.prototype.toString.call(o).slice(8, -1);\n}\n"],"names":[],"mappings":"AAAO,SAAS,QAAQ,CAAQ,EAAA;AAC9B,EAAO,OAAA,MAAA,CAAO,UAAU,QAAS,CAAA,IAAA,CAAK,CAAC,CAAE,CAAA,KAAA,CAAM,GAAG,CAAE,CAAA,CAAA,CAAA;AACtD;;;;"}
|
|
@@ -2,11 +2,11 @@ const has = Object.prototype.hasOwnProperty;
|
|
|
2
2
|
const hasElementType = typeof Element !== "undefined";
|
|
3
3
|
function find(iter, tar, key) {
|
|
4
4
|
for (key of iter.keys()) {
|
|
5
|
-
if (
|
|
5
|
+
if (deepEqual(key, tar))
|
|
6
6
|
return key;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function deepEqual(foo, bar) {
|
|
10
10
|
let ctor, len, tmp;
|
|
11
11
|
if (foo === bar)
|
|
12
12
|
return true;
|
|
@@ -17,7 +17,7 @@ function dequal(foo, bar) {
|
|
|
17
17
|
return foo.toString() === bar.toString();
|
|
18
18
|
if (ctor === Array) {
|
|
19
19
|
if ((len = foo.length) === bar.length) {
|
|
20
|
-
while (len-- &&
|
|
20
|
+
while (len-- && deepEqual(foo[len], bar[len]))
|
|
21
21
|
;
|
|
22
22
|
}
|
|
23
23
|
return len === -1;
|
|
@@ -49,7 +49,7 @@ function dequal(foo, bar) {
|
|
|
49
49
|
if (!tmp)
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
|
-
if (!
|
|
52
|
+
if (!deepEqual(len[1], bar.get(tmp))) {
|
|
53
53
|
return false;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -82,7 +82,7 @@ function dequal(foo, bar) {
|
|
|
82
82
|
}
|
|
83
83
|
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
|
|
84
84
|
return false;
|
|
85
|
-
if (!(ctor in bar) || !
|
|
85
|
+
if (!(ctor in bar) || !deepEqual(foo[ctor], bar[ctor]))
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
88
|
return Object.keys(bar).length === len;
|
|
@@ -91,5 +91,5 @@ function dequal(foo, bar) {
|
|
|
91
91
|
return foo !== foo && bar !== bar;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
export {
|
|
95
|
-
//# sourceMappingURL=
|
|
94
|
+
export { deepEqual };
|
|
95
|
+
//# sourceMappingURL=deepEqual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepEqual.js","sources":["../../src/langs/deepEqual.ts"],"sourcesContent":["const has = Object.prototype.hasOwnProperty;\nconst hasElementType = typeof Element !== 'undefined';\n\nfunction find(iter: any, tar: any, key?: any) {\n for (key of iter.keys()) {\n if (deepEqual(key, tar)) return key;\n }\n}\n\n/**\n * deep equal - support react, dom, Date, RegExp, Array, ArrayBuffer, Set, Map, Object\n * @see {@link https://github.com/lukeed/dequal/blob/master/src/lite.js dequal/src/lite.js}\n * @see {@link https://github.com/FormidableLabs/react-fast-compare/blob/master/index.js react-fast-compare/index.js}\n */\nexport function deepEqual(foo: any, bar: any) {\n let ctor, len, tmp;\n if (foo === bar) return true;\n\n if (foo && bar && (ctor = foo.constructor) === bar.constructor) {\n if (ctor === Date) return foo.getTime() === bar.getTime();\n if (ctor === RegExp) return foo.toString() === bar.toString();\n\n if (ctor === Array) {\n if ((len = foo.length) === bar.length) {\n while (len-- && deepEqual(foo[len], bar[len]));\n }\n return len === -1;\n }\n\n if (ctor === Set) {\n if (foo.size !== bar.size) {\n return false;\n }\n for (len of foo) {\n tmp = len;\n if (tmp && typeof tmp === 'object') {\n tmp = find(bar, tmp);\n if (!tmp) return false;\n }\n if (!bar.has(tmp)) return false;\n }\n return true;\n }\n\n if (ctor === Map) {\n if (foo.size !== bar.size) {\n return false;\n }\n for (len of foo) {\n tmp = len[0];\n if (tmp && typeof tmp === 'object') {\n tmp = find(bar, tmp);\n if (!tmp) return false;\n }\n if (!deepEqual(len[1], bar.get(tmp))) {\n return false;\n }\n }\n return true;\n }\n\n if (ctor === ArrayBuffer) {\n foo = new Uint8Array(foo);\n bar = new Uint8Array(bar);\n } else if (ctor === DataView) {\n if ((len = foo.byteLength) === bar.byteLength) {\n while (len-- && foo.getInt8(len) === bar.getInt8(len));\n }\n return len === -1;\n }\n\n if (ArrayBuffer.isView(foo)) {\n if ((len = foo.byteLength) === bar.byteLength) {\n while (len-- && (foo as any)[len] === bar[len]);\n }\n return len === -1;\n }\n\n // react & dom\n if (hasElementType && foo instanceof Element) return false;\n\n if (!ctor || typeof foo === 'object') {\n len = 0;\n for (ctor in foo) {\n if ((ctor === '_owner' || ctor === '__v' || ctor === '__o') && foo.$$typeof) {\n // React-specific: avoid traversing React elements' _owner\n // Preact-specific: avoid traversing Preact elements' __v and __o\n // __v = $_original / $_vnode\n // __o = $_owner\n // These properties contain circular references and are not needed when\n // comparing the actual elements (and not their owners)\n // .$$typeof and ._store on just reasonable markers of elements\n\n continue;\n }\n\n if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;\n if (!(ctor in bar) || !deepEqual(foo[ctor], bar[ctor])) return false;\n }\n return Object.keys(bar).length === len;\n }\n }\n\n return foo !== foo && bar !== bar;\n}\n"],"names":[],"mappings":"AAAA,MAAM,GAAA,GAAM,OAAO,SAAU,CAAA,cAAA,CAAA;AAC7B,MAAM,cAAA,GAAiB,OAAO,OAAY,KAAA,WAAA,CAAA;AAE1C,SAAS,IAAA,CAAK,IAAW,EAAA,GAAA,EAAU,GAAW,EAAA;AAC5C,EAAK,KAAA,GAAA,IAAO,IAAK,CAAA,IAAA,EAAQ,EAAA;AACvB,IAAI,IAAA,SAAA,CAAU,KAAK,GAAG,CAAA;AAAG,MAAO,OAAA,GAAA,CAAA;AAAA,GAClC;AACF,CAAA;AAOgB,SAAA,SAAA,CAAU,KAAU,GAAU,EAAA;AAC5C,EAAA,IAAI,MAAM,GAAK,EAAA,GAAA,CAAA;AACf,EAAA,IAAI,GAAQ,KAAA,GAAA;AAAK,IAAO,OAAA,IAAA,CAAA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-
export {
|
|
21
|
-
//# sourceMappingURL=
|
|
20
|
+
export { shallowEqual };
|
|
21
|
+
//# sourceMappingURL=shallowEqual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shallowEqual.js","sources":["../../src/langs/shallowEqual.ts"],"sourcesContent":["/**\n * shallow compare - support object, array\n *\n * @see {@link https://github.com/pmndrs/zustand/blob/main/src/shallow.ts zustand/src/shallow.ts}\n */\nexport function shallowEqual<T, U>(objA: T, objB: U) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n return false;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof U])\n ) {\n return false;\n }\n }\n return true;\n}\n"],"names":[],"mappings":"AAKgB,SAAA,YAAA,CAAmB,MAAS,IAAS,EAAA;AACnD,EAAA,IAAI,MAAO,CAAA,EAAA,CAAG,IAAM,EAAA,IAAI,CAAG,EAAA;AACzB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACA,EAAI,IAAA,OAAO,SAAS,QAAY,IAAA,IAAA,KAAS,QAAQ,OAAO,IAAA,KAAS,QAAY,IAAA,IAAA,KAAS,IAAM,EAAA;AAC1F,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAC9B,EAAA,IAAI,MAAM,MAAW,KAAA,MAAA,CAAO,IAAK,CAAA,IAAI,EAAE,MAAQ,EAAA;AAC7C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,CAAM,QAAQ,CAAK,EAAA,EAAA;AACrC,IAAA,IACE,CAAC,MAAO,CAAA,SAAA,CAAU,eAAe,IAAK,CAAA,IAAA,EAAM,MAAM,CAAY,CAAA,CAAA,IAC9D,CAAC,MAAA,CAAO,GAAG,IAAK,CAAA,KAAA,CAAM,KAAgB,IAAK,CAAA,KAAA,CAAM,GAAc,CAC/D,EAAA;AACA,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACF;AACA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { polyfillCrypto } from './polyfillCrypto.js';
|
|
2
|
+
import { polyfillFetch } from './polyfillFetch.js';
|
|
3
|
+
import { polyfillJsDom } from './polyfillJsDom.js';
|
|
4
|
+
|
|
5
|
+
async function polyfillBrowser() {
|
|
6
|
+
await polyfillCrypto();
|
|
7
|
+
await polyfillFetch();
|
|
8
|
+
await polyfillJsDom();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { polyfillBrowser };
|
|
12
|
+
//# sourceMappingURL=polyfillBrowser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfillBrowser.js","sources":["../../src/server/polyfillBrowser.ts"],"sourcesContent":["import { polyfillCrypto } from './polyfillCrypto';\nimport { polyfillFetch } from './polyfillFetch';\nimport { polyfillJsDom } from './polyfillJsDom';\n\nexport async function polyfillBrowser() {\n await polyfillCrypto();\n await polyfillFetch();\n await polyfillJsDom();\n}\n"],"names":[],"mappings":";;;;AAIA,eAAsB,eAAkB,GAAA;AACtC,EAAA,MAAM,cAAe,EAAA,CAAA;AACrB,EAAA,MAAM,aAAc,EAAA,CAAA;AACpB,EAAA,MAAM,aAAc,EAAA,CAAA;AACtB;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfillCrypto.js","sources":["../../src/server/polyfillCrypto.ts"],"sourcesContent":["export async function polyfillCrypto() {\n if ('crypto' in globalThis) {\n return false;\n }\n globalThis.crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n"],"names":[],"mappings":"AAAA,eAAsB,cAAiB,GAAA;AACrC,EAAA,IAAI,YAAY,UAAY,EAAA;AAC1B,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAW,UAAA,CAAA,MAAA,GAAA,CAAU,MAAM,OAAO,aAAgB,CAAA,EAAA,SAAA,CAAA;AAClD,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
async function polyfillFetch() {
|
|
2
|
+
if ("fetch" in globalThis) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const {
|
|
6
|
+
default: fetch,
|
|
7
|
+
Response,
|
|
8
|
+
Headers,
|
|
9
|
+
Request,
|
|
10
|
+
AbortError,
|
|
11
|
+
FetchError,
|
|
12
|
+
FormData,
|
|
13
|
+
Blob,
|
|
14
|
+
File
|
|
15
|
+
} = await import('node-fetch');
|
|
16
|
+
Object.assign(globalThis, {
|
|
17
|
+
fetch,
|
|
18
|
+
Response,
|
|
19
|
+
Headers,
|
|
20
|
+
Request,
|
|
21
|
+
AbortError,
|
|
22
|
+
FetchError,
|
|
23
|
+
FormData,
|
|
24
|
+
Blob,
|
|
25
|
+
File
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { polyfillFetch };
|
|
31
|
+
//# sourceMappingURL=polyfillFetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfillFetch.js","sources":["../../src/server/polyfillFetch.ts"],"sourcesContent":["export async function polyfillFetch() {\n if ('fetch' in globalThis) {\n return false;\n }\n const {\n default: fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n // @ts-ignore\n } = await import('node-fetch');\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n return true;\n}\n"],"names":[],"mappings":"AAAA,eAAsB,aAAgB,GAAA;AACpC,EAAA,IAAI,WAAW,UAAY,EAAA;AACzB,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAM,MAAA;AAAA,IACJ,OAAS,EAAA,KAAA;AAAA,IACT,QAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,IAAA;AAAA,GAEF,GAAI,MAAM,OAAO,YAAA,CAAA,CAAA;AACjB,EAAA,MAAA,CAAO,OAAO,UAAY,EAAA;AAAA,IACxB,KAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,IAAA;AAAA,GACD,CAAA,CAAA;AACD,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
async function polyfillJsDom() {
|
|
2
|
+
if (typeof window !== "undefined") {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const { ResourceLoader, JSDOM } = await import('jsdom');
|
|
6
|
+
class Window {
|
|
7
|
+
constructor(opts = {}) {
|
|
8
|
+
const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;
|
|
9
|
+
const resources = new ResourceLoader({
|
|
10
|
+
proxy,
|
|
11
|
+
strictSSL,
|
|
12
|
+
userAgent
|
|
13
|
+
});
|
|
14
|
+
return new JSDOM(
|
|
15
|
+
"",
|
|
16
|
+
Object.assign(jsdomOpts, {
|
|
17
|
+
resources
|
|
18
|
+
})
|
|
19
|
+
).window;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const defaultJsdomConfig = {};
|
|
23
|
+
const protectedProperties = (() => Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(
|
|
24
|
+
(prop) => typeof globalThis[prop] !== "undefined"
|
|
25
|
+
))();
|
|
26
|
+
function installEnv(...args) {
|
|
27
|
+
const properties = args.filter((arg) => Array.isArray(arg))[0];
|
|
28
|
+
const userJsdomConfig = args.filter((arg) => !Array.isArray(arg))[0];
|
|
29
|
+
const window2 = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));
|
|
30
|
+
Object.getOwnPropertyNames(window2).filter((prop) => protectedProperties.indexOf(prop) === -1).filter((prop) => !(properties && properties.indexOf(prop) === -1)).filter((prop) => {
|
|
31
|
+
switch (prop) {
|
|
32
|
+
case "undefined":
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}).forEach((prop) => {
|
|
37
|
+
Object.defineProperty(globalThis, prop, {
|
|
38
|
+
configurable: true,
|
|
39
|
+
get: () => window2[prop]
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return window2;
|
|
43
|
+
}
|
|
44
|
+
installEnv({ url: "http://localhost" });
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { polyfillJsDom };
|
|
49
|
+
//# sourceMappingURL=polyfillJsDom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfillJsDom.js","sources":["../../src/server/polyfillJsDom.ts"],"sourcesContent":["import { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => protectedProperties.indexOf(prop) === -1)\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n"],"names":["window"],"mappings":"AAEA,eAAsB,aAAgB,GAAA;AACpC,EAAI,IAAA,OAAO,WAAW,WAAa,EAAA;AACjC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,EAAE,cAAA,EAAgB,KAAM,EAAA,GAAI,MAAM,OAAO,OAAA,CAAA,CAAA;AAG/C,EAAA,MAAM,MAAO,CAAA;AAAA,IACX,WAAA,CAAY,IAA8D,GAAA,EAAI,EAAA;AAC5E,MAAA,MAAM,EAAE,KAAA,EAAO,SAAW,EAAA,SAAA,EAAA,GAAc,WAAc,GAAA,IAAA,CAAA;AACtD,M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AA,CAAA,CAAA,CACjE,MAAO,CAAA,CAAC,IAAS,KAAA;AAChB,MAAA,QAAQ,IAAM;AAAA,QACZ,KAAK,WAAA;AACH,UAAO,OAAA,KAAA,CAAA;AAAA,OACX;AACA,MAAO,OAAA,IAAA,CAAA;AAAA,KACR,CAAA,CAGA,OAAQ,CAAA,CAAC,IAAS,KAAA;AAEjB,MAAO,MAAA,CAAA,cAAA,CAAe,YAAY,IAAM,EAAA;AAAA,QACtC,YAAc,EAAA,IAAA;AAAA,QACd,GAAA,EAAK,MAAMA,OAAO,CAAA,IAAA,CAAA;AAAA,OACnB,CAAA,CAAA;AAAA,KACF,CAAA,CAAA;AAEH,IAAOA,OAAAA,OAAAA,CAAAA;AAAA,GACT;AAEA,EAAW,UAAA,CAAA,EAAE,GAAK,EAAA,kBAAA,EAAoB,CAAA,CAAA;AACtC,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|
package/lib/server.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { polyfillCrypto } from './server/polyfillCrypto.js';
|
|
2
|
+
export { polyfillFetch } from './server/polyfillFetch.js';
|
|
3
|
+
export { polyfillJsDom } from './server/polyfillJsDom.js';
|
|
4
|
+
export { polyfillBrowser } from './server/polyfillBrowser.js';
|
|
2
5
|
//# sourceMappingURL=server.js.map
|
package/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatBytes.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"formatBytes.js","sources":["../../src/strings/formatBytes.ts"],"sourcesContent":["/**\n * Format bytes as human-readable text.\n *\n * @param bytes Number of bytes.\n * @param si True to use metric (SI) units, aka powers of 1000. False to use\n * binary (IEC), aka powers of 1024.\n * @param dp Number of decimal places to display.\n *\n * @return Formatted string.\n */\nexport function formatBytes(bytes: number, si = false, dp = 1) {\n const thresh = si ? 1000 : 1024;\n\n if (Math.abs(bytes) < thresh) {\n return bytes + ' B';\n }\n\n const units = si\n ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\n : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];\n let u = -1;\n const r = 10 ** dp;\n\n do {\n bytes /= thresh;\n ++u;\n } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);\n\n return bytes.toFixed(dp) + ' ' + units[u];\n}\n"],"names":[],"mappings":"AAUO,SAAS,WAAY,CAAA,KAAA,EAAe,EAAK,GAAA,KAAA,EAAO,KAAK,CAAG,EAAA;AAC7D,EAAM,MAAA,MAAA,GAAS,KAAK,GAAO,GAAA,IAAA,CAAA;AAE3B,EAAA,IAAI,IAAK,CAAA,GAAA,CAAI,KAAK,CAAA,GAAI,MAAQ,EAAA;AAC5B,IAAA,OAAO,KAAQ,GAAA,IAAA,CAAA;AAAA,GACjB;AAEA,EAAM,MAAA,KAAA,GAAQ,KACV,CAAC,IAAA,EAAM,MAAM,IAAM,EAAA,IAAA,EAAM,MAAM,IAAM,EAAA,IAAA,EAAM,IAAI,CAC/C,GAAA,CAAC,OAAO,KAAO,EAAA,KAAA,EAAO,OAAO,KAAO,EAAA,KAAA,EAAO,OAAO,KAAK,CAAA,CAAA;AAC3D,EAAA,IAAI,CAAI,GAAA,CAAA,CAAA,CAAA;AACR,EAAA,MAAM,IAAI,EAAM,IAAA,EAAA,CAAA;AAEhB,EAAG,GAAA;AACD,IAAS,KAAA,IAAA,MAAA,CAAA;AACT,IAAE,EAAA,CAAA,CAAA;AAAA,GACK,QAAA,IAAA,CAAK,KAAM,CAAA,IAAA,CAAK,GAAI,CAAA,KAAK,CAAI,GAAA,CAAC,CAAI,GAAA,CAAA,IAAK,MAAU,IAAA,CAAA,GAAI,MAAM,MAAS,GAAA,CAAA,EAAA;AAE7E,EAAA,OAAO,KAAM,CAAA,OAAA,CAAQ,EAAE,CAAA,GAAI,MAAM,KAAM,CAAA,CAAA,CAAA,CAAA;AACzC;;;;"}
|
|
@@ -2,7 +2,9 @@ import { get } from '../objects/get.js';
|
|
|
2
2
|
|
|
3
3
|
function renderTemplate(template, data, match = "js") {
|
|
4
4
|
let getter;
|
|
5
|
-
if (
|
|
5
|
+
if (!data) {
|
|
6
|
+
getter = () => "";
|
|
7
|
+
} else if (typeof data === "function") {
|
|
6
8
|
getter = data;
|
|
7
9
|
} else {
|
|
8
10
|
getter = (v) => get(data, v);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderTemplate.js","sources":["../../src/strings/renderTemplate.ts"],"sourcesContent":["import { get } from '../objects/get';\n\n/**\n * 替换类似于 JS 的模板字符串\n *\n * templateString('My name is ${name}',{name:'wener'}) // => 'My name is wener'\n *\n */\nexport function renderTemplate(\n template: string,\n data: ((v: string) => any) | object,\n match: 'js' | 'common' | RegExp = 'js',\n) {\n let getter: Function;\n if (typeof data === 'function') {\n getter = data;\n } else {\n getter = (v: string) => get(data, v);\n }\n if (typeof match === 'string') {\n match = Matches[match] || Matches['js'];\n }\n return template.replace(match, (_, g) => {\n return getter(g.trim());\n });\n}\n\nconst Matches = {\n js: /\\${(.*?)}/g,\n common: /{{(.*?)}}/g,\n};\n"],"names":[],"mappings":";;AAQO,SAAS,cACd,CAAA,QAAA,EACA,IACA,EAAA,KAAA,GAAkC,IAClC,EAAA;AACA,EAAI,IAAA,MAAA,CAAA;AACJ,
|
|
1
|
+
{"version":3,"file":"renderTemplate.js","sources":["../../src/strings/renderTemplate.ts"],"sourcesContent":["import { get } from '../objects/get';\n\n/**\n * 替换类似于 JS 的模板字符串\n *\n * templateString('My name is ${name}',{name:'wener'}) // => 'My name is wener'\n *\n */\nexport function renderTemplate(\n template: string,\n data: ((v: string) => any) | object,\n match: 'js' | 'common' | RegExp = 'js',\n) {\n let getter: Function;\n if (!data) {\n // todo warning in dev\n getter = () => '';\n } else if (typeof data === 'function') {\n getter = data;\n } else {\n getter = (v: string) => get(data, v);\n }\n if (typeof match === 'string') {\n match = Matches[match] || Matches['js'];\n }\n return template.replace(match, (_, g) => {\n return getter(g.trim());\n });\n}\n\nconst Matches = {\n js: /\\${(.*?)}/g,\n common: /{{(.*?)}}/g,\n};\n"],"names":[],"mappings":";;AAQO,SAAS,cACd,CAAA,QAAA,EACA,IACA,EAAA,KAAA,GAAkC,IAClC,EAAA;AACA,EAAI,IAAA,MAAA,CAAA;AACJ,EAAA,IAAI,CAAC,IAAM,EAAA;AAET,IAAA,MAAA,GAAS,MAAM,EAAA,CAAA;AAAA,GACjB,MAAA,IAAW,OAAO,IAAA,KAAS,UAAY,EAAA;AACrC,IAAS,MAAA,GAAA,IAAA,CAAA;AAAA,GACJ,MAAA;AACL,IAAA,MAAA,GAAS,CAAC,CAAA,KAAc,GAAI,CAAA,IAAA,EAAM,CAAC,CAAA,CAAA;AAAA,GACrC;AACA,EAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC7B,IAAQ,KAAA,GAAA,OAAA,CAAQ,UAAU,OAAQ,CAAA,IAAA,CAAA,CAAA;AAAA,GACpC;AACA,EAAA,OAAO,QAAS,CAAA,OAAA,CAAQ,KAAO,EAAA,CAAC,GAAG,CAAM,KAAA;AACvC,IAAO,OAAA,MAAA,CAAO,CAAE,CAAA,IAAA,EAAM,CAAA,CAAA;AAAA,GACvB,CAAA,CAAA;AACH,CAAA;AAEA,MAAM,OAAU,GAAA;AAAA,EACd,EAAI,EAAA,YAAA;AAAA,EACJ,MAAQ,EAAA,YAAA;AACV,CAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isUUID.js","sources":["../../src/validations/isUUID.ts"],"sourcesContent":["export function isUUID(str: string) {\n return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);\n}\n"],"names":[],"mappings":"AAAO,SAAS,OAAO,GAAa,EAAA;AAClC,EAAO,OAAA,wEAAA,CAAyE,KAAK,GAAG,CAAA,CAAA;AAC1F;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wener/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utils for daily use",
|
|
6
6
|
"repository": {
|
|
@@ -81,6 +81,10 @@
|
|
|
81
81
|
"input": [
|
|
82
82
|
"./src/index.ts",
|
|
83
83
|
"./src/server.ts"
|
|
84
|
+
],
|
|
85
|
+
"external": [
|
|
86
|
+
"jsdom",
|
|
87
|
+
"node-fetch"
|
|
84
88
|
]
|
|
85
89
|
},
|
|
86
90
|
"scripts": {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { createLazyPromise } from './createLazyPromise';
|
|
3
|
+
import { sleep } from './sleep';
|
|
4
|
+
|
|
5
|
+
test('basic', async (t) => {
|
|
6
|
+
let promise = createLazyPromise();
|
|
7
|
+
let r = 0;
|
|
8
|
+
promise.then((v) => (r = v));
|
|
9
|
+
t.is(r, 0);
|
|
10
|
+
const { resolve, reject } = promise;
|
|
11
|
+
t.truthy(resolve);
|
|
12
|
+
t.truthy(reject);
|
|
13
|
+
resolve(1);
|
|
14
|
+
t.is(r, 0);
|
|
15
|
+
await promise;
|
|
16
|
+
t.is(r, 1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('manual resolve skip exec', async (t) => {
|
|
20
|
+
let promise = createLazyPromise(() => {
|
|
21
|
+
t.fail();
|
|
22
|
+
});
|
|
23
|
+
promise.resolve(-1);
|
|
24
|
+
t.is(await promise, -1);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('exec', async (t) => {
|
|
28
|
+
let r = 0;
|
|
29
|
+
let promise = createLazyPromise((resolve) => {
|
|
30
|
+
r++;
|
|
31
|
+
resolve(10);
|
|
32
|
+
});
|
|
33
|
+
await sleep(10);
|
|
34
|
+
t.is(r, 0);
|
|
35
|
+
t.is(await promise, 10);
|
|
36
|
+
t.is(r, 1);
|
|
37
|
+
promise.resolve(20);
|
|
38
|
+
t.is(await promise, 10);
|
|
39
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type LazyPromise<T> = Promise<T> & {
|
|
2
|
+
reject(reason?: any): void;
|
|
3
|
+
resolve(v?: T | PromiseLike<T>): void;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* createLazyPromise return a promise that can be resolved or rejected manually.
|
|
8
|
+
* if you pass a function to it, it will be executed when the promise try to resolve.
|
|
9
|
+
*/
|
|
10
|
+
export function createLazyPromise<T = any>(
|
|
11
|
+
executor?: (resolve: LazyPromise<T>['resolve'], reject: LazyPromise<T>['reject']) => void,
|
|
12
|
+
): LazyPromise<T> {
|
|
13
|
+
const holder = {
|
|
14
|
+
resolve(_: any): void {
|
|
15
|
+
throw new Error('pending resolve');
|
|
16
|
+
},
|
|
17
|
+
reject(_: any): void {
|
|
18
|
+
throw new Error('pending reject');
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
let future = Object.assign(
|
|
22
|
+
new Promise<T>((resolve, reject) => {
|
|
23
|
+
holder.reject = reject;
|
|
24
|
+
holder.resolve = resolve;
|
|
25
|
+
}),
|
|
26
|
+
{
|
|
27
|
+
resolve(v: any) {
|
|
28
|
+
holder.resolve(v);
|
|
29
|
+
},
|
|
30
|
+
reject(v: any) {
|
|
31
|
+
holder.resolve(v);
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
if (executor) {
|
|
36
|
+
const r = holder.resolve;
|
|
37
|
+
let shouldExec = true;
|
|
38
|
+
holder.resolve = (v: any) => {
|
|
39
|
+
shouldExec = false;
|
|
40
|
+
r(v);
|
|
41
|
+
};
|
|
42
|
+
const then = future.then.bind(future);
|
|
43
|
+
future.then = (...args) => {
|
|
44
|
+
if (shouldExec) {
|
|
45
|
+
shouldExec = false;
|
|
46
|
+
executor(holder.resolve, holder.reject);
|
|
47
|
+
}
|
|
48
|
+
return then(...args);
|
|
49
|
+
};
|
|
50
|
+
const like = holder as LazyPromise<T>;
|
|
51
|
+
like.then = future.then;
|
|
52
|
+
like.catch = future.catch.bind(future);
|
|
53
|
+
if (future.finally) like.finally = future.finally;
|
|
54
|
+
|
|
55
|
+
Object.defineProperty(like, Symbol.species, {
|
|
56
|
+
get() {
|
|
57
|
+
return Promise;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return like;
|
|
61
|
+
}
|
|
62
|
+
return future;
|
|
63
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
|
+
import { polyfillCrypto } from '../server/polyfillCrypto';
|
|
3
|
+
import { isUUID } from '../validations/isUUID';
|
|
2
4
|
import { sha1, sha256, sha384, sha512 } from './hashing';
|
|
3
5
|
import { hex } from './hex';
|
|
4
|
-
import {
|
|
6
|
+
import { _randomUUID } from './randomUUID';
|
|
5
7
|
|
|
6
|
-
test.before(async (
|
|
7
|
-
|
|
8
|
-
(globalThis as any).crypto = (await import('node:crypto')).webcrypto;
|
|
9
|
-
t.log(`load node:crypto`);
|
|
10
|
-
}
|
|
8
|
+
test.before(async () => {
|
|
9
|
+
await polyfillCrypto();
|
|
11
10
|
});
|
|
12
11
|
|
|
13
12
|
test('sha', async (t) => {
|
|
@@ -22,5 +21,10 @@ test('sha', async (t) => {
|
|
|
22
21
|
hex(await sha512('')),
|
|
23
22
|
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e',
|
|
24
23
|
);
|
|
25
|
-
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('randomUUID', (t) => {
|
|
27
|
+
for (let i = 0; i < 20; i++) {
|
|
28
|
+
t.true(isUUID(_randomUUID()));
|
|
29
|
+
}
|
|
26
30
|
});
|
package/src/crypto/randomUUID.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* generate random UUIDv4
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
4
|
+
export const randomUUID: () => string = globalThis.crypto?.randomUUID || _randomUUID;
|
|
5
|
+
|
|
6
|
+
export function _randomUUID() {
|
|
8
7
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
9
8
|
const r = (Math.random() * 16) | 0;
|
|
10
9
|
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|