@wener/utils 1.1.2 → 1.1.3

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.
Files changed (139) hide show
  1. package/dist/cjs/index.js +1 -578
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/server.js +2 -0
  4. package/dist/cjs/server.js.map +1 -0
  5. package/dist/esm/index.js +2 -0
  6. package/dist/esm/index.js.map +1 -0
  7. package/dist/esm/server.js +2 -0
  8. package/dist/esm/server.js.map +1 -0
  9. package/dist/system/index.js +2 -0
  10. package/dist/system/index.js.map +1 -0
  11. package/dist/system/server.js +2 -0
  12. package/dist/system/server.js.map +1 -0
  13. package/index.ts +1 -0
  14. package/lib/arrays/MaybeArray.js +30 -0
  15. package/lib/arrays/MaybeArray.js.map +1 -0
  16. package/lib/asyncs/AsyncInterval.js +15 -0
  17. package/lib/asyncs/AsyncInterval.js.map +1 -0
  18. package/lib/asyncs/LazyPromise.js +27 -0
  19. package/lib/asyncs/LazyPromise.js.map +1 -0
  20. package/lib/asyncs/isPromise.js +6 -0
  21. package/lib/asyncs/isPromise.js.map +1 -0
  22. package/lib/{esm/asyncs/sleep.mjs → asyncs/sleep.js} +1 -1
  23. package/lib/asyncs/sleep.js.map +1 -0
  24. package/lib/asyncs/timeout.js +27 -0
  25. package/lib/asyncs/timeout.js.map +1 -0
  26. package/lib/browsers/copy.js +51 -0
  27. package/lib/browsers/copy.js.map +1 -0
  28. package/lib/browsers/download.js +28 -0
  29. package/lib/browsers/download.js.map +1 -0
  30. package/lib/browsers/getFileFromDataTransfer.js +31 -0
  31. package/lib/browsers/getFileFromDataTransfer.js.map +1 -0
  32. package/lib/browsers/loaders.js +50 -0
  33. package/lib/browsers/loaders.js.map +1 -0
  34. package/lib/crypto/hashing.js +24 -0
  35. package/lib/crypto/hashing.js.map +1 -0
  36. package/lib/crypto/hex.js +6 -0
  37. package/lib/crypto/hex.js.map +1 -0
  38. package/lib/crypto/randomUUID.js +13 -0
  39. package/lib/crypto/randomUUID.js.map +1 -0
  40. package/lib/formats/formatBytes.js +17 -0
  41. package/lib/formats/formatBytes.js.map +1 -0
  42. package/lib/index.js +27 -0
  43. package/lib/index.js.map +1 -0
  44. package/lib/io/isBuffer.js +6 -0
  45. package/lib/io/isBuffer.js.map +1 -0
  46. package/lib/isomorphics/getGlobalThis.js +14 -0
  47. package/lib/isomorphics/getGlobalThis.js.map +1 -0
  48. package/lib/maths/random.js +17 -0
  49. package/lib/maths/random.js.map +1 -0
  50. package/lib/modules/parseModuleId.js +31 -0
  51. package/lib/modules/parseModuleId.js.map +1 -0
  52. package/lib/server/polyfill.js +8 -0
  53. package/lib/server/polyfill.js.map +1 -0
  54. package/lib/server.js +2 -0
  55. package/lib/server.js.map +1 -0
  56. package/lib/shim/urljoin.js +51 -0
  57. package/lib/shim/urljoin.js.map +1 -0
  58. package/lib/strings/camelCase.js +56 -0
  59. package/lib/strings/camelCase.js.map +1 -0
  60. package/lib/strings/templates.js +8 -0
  61. package/lib/strings/templates.js.map +1 -0
  62. package/lib/validations/dequal.js +95 -0
  63. package/lib/validations/dequal.js.map +1 -0
  64. package/lib/validations/isClass.js +6 -0
  65. package/lib/validations/isClass.js.map +1 -0
  66. package/lib/validations/isDefined.js +6 -0
  67. package/lib/validations/isDefined.js.map +1 -0
  68. package/lib/validations/isEmptyObject.js +9 -0
  69. package/lib/validations/isEmptyObject.js.map +1 -0
  70. package/lib/validations/shallow.js +21 -0
  71. package/lib/validations/shallow.js.map +1 -0
  72. package/package.json +37 -35
  73. package/server.ts +1 -0
  74. package/src/arrays/MaybeArray.ts +8 -4
  75. package/src/crypto/randomUUID.ts +3 -0
  76. package/src/index.ts +13 -1
  77. package/src/modules/parseModuleId.test.ts +68 -0
  78. package/src/modules/parseModuleId.ts +46 -0
  79. package/src/server/polyfill.ts +5 -0
  80. package/src/server.ts +1 -0
  81. package/src/shim/urljoin.test.ts +1 -1
  82. package/src/validations/dequal.test.ts +17 -0
  83. package/src/validations/dequal.ts +105 -0
  84. package/src/validations/shallow.ts +26 -0
  85. package/dist/esm/index.development.js +0 -545
  86. package/dist/esm/index.development.js.map +0 -1
  87. package/dist/esm/index.min.js +0 -2
  88. package/dist/esm/index.min.js.map +0 -1
  89. package/dist/system/index.development.js +0 -585
  90. package/dist/system/index.development.js.map +0 -1
  91. package/dist/system/index.min.js +0 -2
  92. package/dist/system/index.min.js.map +0 -1
  93. package/lib/esm/arrays/MaybeArray.mjs +0 -30
  94. package/lib/esm/arrays/MaybeArray.mjs.map +0 -1
  95. package/lib/esm/asyncs/AsyncInterval.mjs +0 -15
  96. package/lib/esm/asyncs/AsyncInterval.mjs.map +0 -1
  97. package/lib/esm/asyncs/LazyPromise.mjs +0 -24
  98. package/lib/esm/asyncs/LazyPromise.mjs.map +0 -1
  99. package/lib/esm/asyncs/isPromise.mjs +0 -6
  100. package/lib/esm/asyncs/isPromise.mjs.map +0 -1
  101. package/lib/esm/asyncs/sleep.mjs.map +0 -1
  102. package/lib/esm/asyncs/timeout.mjs +0 -24
  103. package/lib/esm/asyncs/timeout.mjs.map +0 -1
  104. package/lib/esm/browsers/copy.mjs +0 -57
  105. package/lib/esm/browsers/copy.mjs.map +0 -1
  106. package/lib/esm/browsers/download.mjs +0 -40
  107. package/lib/esm/browsers/download.mjs.map +0 -1
  108. package/lib/esm/browsers/getFileFromDataTransfer.mjs +0 -39
  109. package/lib/esm/browsers/getFileFromDataTransfer.mjs.map +0 -1
  110. package/lib/esm/browsers/loaders.mjs +0 -52
  111. package/lib/esm/browsers/loaders.mjs.map +0 -1
  112. package/lib/esm/crypto/hashing.mjs +0 -25
  113. package/lib/esm/crypto/hashing.mjs.map +0 -1
  114. package/lib/esm/crypto/hex.mjs +0 -8
  115. package/lib/esm/crypto/hex.mjs.map +0 -1
  116. package/lib/esm/crypto/randomUUID.mjs +0 -13
  117. package/lib/esm/crypto/randomUUID.mjs.map +0 -1
  118. package/lib/esm/formats/formatBytes.mjs +0 -29
  119. package/lib/esm/formats/formatBytes.mjs.map +0 -1
  120. package/lib/esm/index.mjs +0 -24
  121. package/lib/esm/index.mjs.map +0 -1
  122. package/lib/esm/io/isBuffer.mjs +0 -10
  123. package/lib/esm/io/isBuffer.mjs.map +0 -1
  124. package/lib/esm/isomorphics/getGlobalThis.mjs +0 -23
  125. package/lib/esm/isomorphics/getGlobalThis.mjs.map +0 -1
  126. package/lib/esm/maths/random.mjs +0 -18
  127. package/lib/esm/maths/random.mjs.map +0 -1
  128. package/lib/esm/shim/urljoin.mjs +0 -65
  129. package/lib/esm/shim/urljoin.mjs.map +0 -1
  130. package/lib/esm/strings/camelCase.mjs +0 -70
  131. package/lib/esm/strings/camelCase.mjs.map +0 -1
  132. package/lib/esm/strings/templates.mjs +0 -16
  133. package/lib/esm/strings/templates.mjs.map +0 -1
  134. package/lib/esm/validations/isClass.mjs +0 -6
  135. package/lib/esm/validations/isClass.mjs.map +0 -1
  136. package/lib/esm/validations/isDefined.mjs +0 -6
  137. package/lib/esm/validations/isDefined.mjs.map +0 -1
  138. package/lib/esm/validations/isEmptyObject.mjs +0 -9
  139. package/lib/esm/validations/isEmptyObject.mjs.map +0 -1
@@ -0,0 +1,95 @@
1
+ const has = Object.prototype.hasOwnProperty;
2
+ const hasElementType = typeof Element !== "undefined";
3
+ function find(iter, tar, key) {
4
+ for (key of iter.keys()) {
5
+ if (dequal(key, tar))
6
+ return key;
7
+ }
8
+ }
9
+ function dequal(foo, bar) {
10
+ let ctor, len, tmp;
11
+ if (foo === bar)
12
+ return true;
13
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
14
+ if (ctor === Date)
15
+ return foo.getTime() === bar.getTime();
16
+ if (ctor === RegExp)
17
+ return foo.toString() === bar.toString();
18
+ if (ctor === Array) {
19
+ if ((len = foo.length) === bar.length) {
20
+ while (len-- && dequal(foo[len], bar[len]))
21
+ ;
22
+ }
23
+ return len === -1;
24
+ }
25
+ if (ctor === Set) {
26
+ if (foo.size !== bar.size) {
27
+ return false;
28
+ }
29
+ for (len of foo) {
30
+ tmp = len;
31
+ if (tmp && typeof tmp === "object") {
32
+ tmp = find(bar, tmp);
33
+ if (!tmp)
34
+ return false;
35
+ }
36
+ if (!bar.has(tmp))
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+ if (ctor === Map) {
42
+ if (foo.size !== bar.size) {
43
+ return false;
44
+ }
45
+ for (len of foo) {
46
+ tmp = len[0];
47
+ if (tmp && typeof tmp === "object") {
48
+ tmp = find(bar, tmp);
49
+ if (!tmp)
50
+ return false;
51
+ }
52
+ if (!dequal(len[1], bar.get(tmp))) {
53
+ return false;
54
+ }
55
+ }
56
+ return true;
57
+ }
58
+ if (ctor === ArrayBuffer) {
59
+ foo = new Uint8Array(foo);
60
+ bar = new Uint8Array(bar);
61
+ } else if (ctor === DataView) {
62
+ if ((len = foo.byteLength) === bar.byteLength) {
63
+ while (len-- && foo.getInt8(len) === bar.getInt8(len))
64
+ ;
65
+ }
66
+ return len === -1;
67
+ }
68
+ if (ArrayBuffer.isView(foo)) {
69
+ if ((len = foo.byteLength) === bar.byteLength) {
70
+ while (len-- && foo[len] === bar[len])
71
+ ;
72
+ }
73
+ return len === -1;
74
+ }
75
+ if (hasElementType && foo instanceof Element)
76
+ return false;
77
+ if (!ctor || typeof foo === "object") {
78
+ len = 0;
79
+ for (ctor in foo) {
80
+ if ((ctor === "_owner" || ctor === "__v" || ctor === "__o") && foo.$$typeof) {
81
+ continue;
82
+ }
83
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
84
+ return false;
85
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
86
+ return false;
87
+ }
88
+ return Object.keys(bar).length === len;
89
+ }
90
+ }
91
+ return foo !== foo && bar !== bar;
92
+ }
93
+
94
+ export { dequal };
95
+ //# sourceMappingURL=dequal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dequal.js","sources":["../../src/validations/dequal.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 (dequal(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 dequal(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-- && dequal(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 (!dequal(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) || !dequal(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,MAAA,CAAO,KAAK,GAAG,CAAA;AAAG,MAAO,OAAA,GAAA,CAAA;AAAA,GAC/B;AACF,CAAA;AAOgB,SAAA,MAAA,CAAO,KAAU,GAAU,EAAA;AACzC,EAAA,IAAI,MAAM,GAAK,EAAA,GAAA,CAAA;AACf,EAAA,IAAI,GAAQ,KAAA,GAAA;AAAK,IAAO,OAAA,IAAA,CAAA;AAExB,EAAA,IAAI,OAAO,GAAQ,IAAA,CAAA,IAAA,GAAO,GAAI,CAAA,WAAA,MAAiB,IAAI,WAAa,EAAA;AAC9D,IAAA,IAAI,IAAS,KAAA,IAAA;AAAM,MAAA,OAAO,GAAI,CAAA,OAAA,EAAc,KAAA,GAAA,CAAI,OAAQ,EAAA,CAAA;AACxD,IAAA,IAAI,IAAS,KAAA,MAAA;AAAQ,MAAA,OAAO,GAAI,CAAA,QAAA,EAAe,KAAA,GAAA,CAAI,QAAS,EAAA,CAAA;AAE5D,IAAA,IAAI,SAAS,KAAO,EAAA;A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AA,CAAK,SAAS,QAAY,IAAA,IAAA,KAAS,SAAS,IAAS,KAAA,KAAA,KAAU,IAAI,QAAU,EAAA;AAS3E,UAAA,SAAA;AAAA,SACF;AAEA,QAAI,IAAA,GAAA,CAAI,IAAK,CAAA,GAAA,EAAK,IAAI,CAAA,IAAK,EAAE,GAAA,IAAO,CAAC,GAAA,CAAI,IAAK,CAAA,GAAA,EAAK,IAAI,CAAA;AAAG,UAAO,OAAA,KAAA,CAAA;AACjE,QAAI,IAAA,EAAE,QAAQ,GAAQ,CAAA,IAAA,CAAC,OAAO,GAAI,CAAA,IAAA,CAAA,EAAO,IAAI,IAAK,CAAA,CAAA;AAAG,UAAO,OAAA,KAAA,CAAA;AAAA,OAC9D;AACA,MAAA,OAAO,MAAO,CAAA,IAAA,CAAK,GAAG,CAAA,CAAE,MAAW,KAAA,GAAA,CAAA;AAAA,KACrC;AAAA,GACF;AAEA,EAAO,OAAA,GAAA,KAAQ,OAAO,GAAQ,KAAA,GAAA,CAAA;AAChC;;;;"}
@@ -0,0 +1,6 @@
1
+ function isClass(func) {
2
+ return typeof func === "function" && /^class\s/.test(Function.prototype.toString.call(func));
3
+ }
4
+
5
+ export { isClass };
6
+ //# sourceMappingURL=isClass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isClass.js","sources":["../../src/validations/isClass.ts"],"sourcesContent":["export function isClass(func: any) {\n return typeof func === 'function' && /^class\\s/.test(Function.prototype.toString.call(func));\n}\n"],"names":[],"mappings":"AAAO,SAAS,QAAQ,IAAW,EAAA;AACjC,EAAO,OAAA,OAAO,IAAS,KAAA,UAAA,IAAc,UAAW,CAAA,IAAA,CAAK,SAAS,SAAU,CAAA,QAAA,CAAS,IAAK,CAAA,IAAI,CAAC,CAAA,CAAA;AAC7F;;;;"}
@@ -0,0 +1,6 @@
1
+ function isDefined(v) {
2
+ return v !== null && v !== void 0;
3
+ }
4
+
5
+ export { isDefined };
6
+ //# sourceMappingURL=isDefined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isDefined.js","sources":["../../src/validations/isDefined.ts"],"sourcesContent":["export function isDefined<T = any>(v: T): v is NonNullable<T> {\n return v !== null && v !== undefined;\n}\n"],"names":[],"mappings":"AAAO,SAAS,UAAmB,CAA2B,EAAA;AAC5D,EAAO,OAAA,CAAA,KAAM,QAAQ,CAAM,KAAA,KAAA,CAAA,CAAA;AAC7B;;;;"}
@@ -0,0 +1,9 @@
1
+ function isEmptyObject(o) {
2
+ if (o === null || o === void 0) {
3
+ return true;
4
+ }
5
+ return o.constructor === Object && Object.keys(o).length === 0;
6
+ }
7
+
8
+ export { isEmptyObject };
9
+ //# sourceMappingURL=isEmptyObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isEmptyObject.js","sources":["../../src/validations/isEmptyObject.ts"],"sourcesContent":["export function isEmptyObject(o: any) {\n if (o === null || o === undefined) {\n return true;\n }\n return o.constructor === Object && Object.keys(o).length === 0;\n}\n"],"names":[],"mappings":"AAAO,SAAS,cAAc,CAAQ,EAAA;AACpC,EAAI,IAAA,CAAA,KAAM,IAAQ,IAAA,CAAA,KAAM,KAAW,CAAA,EAAA;AACjC,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACA,EAAA,OAAO,EAAE,WAAgB,KAAA,MAAA,IAAU,OAAO,IAAK,CAAA,CAAC,EAAE,MAAW,KAAA,CAAA,CAAA;AAC/D;;;;"}
@@ -0,0 +1,21 @@
1
+ function shallow(objA, objB) {
2
+ if (Object.is(objA, objB)) {
3
+ return true;
4
+ }
5
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
6
+ return false;
7
+ }
8
+ const keysA = Object.keys(objA);
9
+ if (keysA.length !== Object.keys(objB).length) {
10
+ return false;
11
+ }
12
+ for (let i = 0; i < keysA.length; i++) {
13
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
14
+ return false;
15
+ }
16
+ }
17
+ return true;
18
+ }
19
+
20
+ export { shallow };
21
+ //# sourceMappingURL=shallow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shallow.js","sources":["../../src/validations/shallow.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 shallow<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,OAAA,CAAc,MAAS,IAAS,EAAA;AAC9C,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;;;;"}
package/package.json CHANGED
@@ -1,71 +1,66 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.2",
4
- "description": "Utils for daily use",
3
+ "version": "1.1.3",
5
4
  "type": "module",
6
- "sideEffects": false,
7
- "keywords": [
8
- "utils",
9
- "core library",
10
- "helper"
11
- ],
5
+ "description": "Utils for daily use",
12
6
  "repository": {
13
7
  "type": "git",
14
8
  "url": "git+https://github.com/wener/wode.git"
15
9
  },
16
- "license": "MIT",
10
+ "homepage": "https://github.com/wenerme/wode#readme",
17
11
  "author": "wener",
12
+ "license": "MIT",
13
+ "engines": {
14
+ "node": "16",
15
+ "npm": "8"
16
+ },
17
+ "main": "dist/cjs/index.js",
18
18
  "exports": {
19
19
  ".": {
20
20
  "types": "./src/index.ts",
21
- "import": "./lib/esm/index.mjs",
21
+ "import": "./lib/index.js",
22
22
  "system": {
23
- "development": "./dist/system/index.development.js",
24
- "default": "./dist/system/index.min.js"
23
+ "default": "./dist/system/index.js"
25
24
  },
26
25
  "require": "./dist/cjs/index.js"
27
26
  },
28
27
  "./types": {
29
28
  "types": "./src/types.d.ts"
30
29
  },
31
- "./src/*": "./src/*",
30
+ "./server": {
31
+ "types": "./src/server.ts",
32
+ "import": "./lib/server.js",
33
+ "system": {
34
+ "default": "./dist/system/server.js"
35
+ },
36
+ "require": "./dist/cjs/server.js"
37
+ },
38
+ "./src/*": "./src/",
32
39
  "./package.json": "./package.json"
33
40
  },
34
- "main": "dist/cjs/index.js",
35
- "import": "lib/esm/index.mjs",
36
41
  "types": "src/index.ts",
37
- "homepage": "https://github.com/wenerme/wode#readme",
38
42
  "files": [
39
- "index.js",
40
- "index.d.ts",
41
- "lib",
42
43
  "dist",
44
+ "index.ts",
45
+ "lib",
46
+ "server.ts",
43
47
  "src",
44
- "README.md",
45
- "rollup.config.ts",
46
- "jest.config.js",
47
- "jest.setup.js",
48
- "tsconfig.rollup.json",
49
- "tsconfig.jest.json",
50
48
  "tsconfig.json"
51
49
  ],
50
+ "keywords": [
51
+ "utils",
52
+ "core library",
53
+ "helper"
54
+ ],
52
55
  "devDependencies": {
53
56
  "@types/lodash": "^4",
54
- "@types/node": "^16",
55
57
  "ava": "^4.3.3",
56
- "dotenv": "^16",
57
- "esbuild": "^0.14",
58
- "lodash": "^4",
59
- "tslib": "^2",
60
- "typescript": "^4"
58
+ "lodash": "^4"
61
59
  },
62
60
  "publishConfig": {
63
61
  "access": "public"
64
62
  },
65
- "engines": {
66
- "node": "16",
67
- "npm": "8"
68
- },
63
+ "sideEffects": false,
69
64
  "ava": {
70
65
  "extensions": {
71
66
  "ts": "module"
@@ -74,6 +69,13 @@
74
69
  "--loader=tsx"
75
70
  ]
76
71
  },
72
+ "import": "lib/index.js",
73
+ "rollup": {
74
+ "input": [
75
+ "./src/index.ts",
76
+ "./src/server.ts"
77
+ ]
78
+ },
77
79
  "scripts": {
78
80
  "build": "make prepublish",
79
81
  "clean": "make clean",
package/server.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/server';
@@ -1,14 +1,18 @@
1
+ /**
2
+ * Array or element of an array
3
+ */
1
4
  export type MaybeArray<T> = T | T[];
2
5
 
6
+ /**
7
+ * convert to single value object
8
+ */
3
9
  export function objectOfMaybeArray<T = any>(
4
10
  o: Record<string, MaybeArray<T>>,
5
11
  keys: string[] | null = null,
6
- picker = firstOfMaybeArray
12
+ picker = firstOfMaybeArray,
7
13
  ): Record<string, T> {
8
14
  if (keys === null) {
9
- return Object.fromEntries(
10
- Object.entries(o).map(([k, v]) => [k, picker(v)])
11
- );
15
+ return Object.fromEntries(Object.entries(o).map(([k, v]) => [k, picker(v)]));
12
16
  }
13
17
  return Object.fromEntries(keys.map((v) => [v, picker(v)])) as any;
14
18
  }
@@ -1,3 +1,6 @@
1
+ /**
2
+ * generate random UUIDv4
3
+ */
1
4
  export function randomUUID() {
2
5
  if ('randomUUID' in crypto) {
3
6
  return crypto.randomUUID();
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // arrays
1
2
  export {
2
3
  firstOfMaybeArray,
3
4
  lastOfMaybeArray,
@@ -6,6 +7,7 @@ export {
6
7
  type MaybeArray,
7
8
  } from './arrays/MaybeArray';
8
9
 
10
+ // async
9
11
  export { createLazyPromise, type LazyPromise } from './asyncs/LazyPromise';
10
12
  export { setAsyncInterval, clearAsyncInterval } from './asyncs/AsyncInterval';
11
13
  export { type MaybePromise } from './asyncs/MaybePromise';
@@ -15,24 +17,34 @@ export { timeout, TimeoutError } from './asyncs/timeout';
15
17
  export { isPromise } from './asyncs/isPromise';
16
18
  // export * from './async/promiseOfCallback';
17
19
 
18
- // asserts.ts
20
+ // validations
19
21
  export { isClass } from './validations/isClass';
20
22
  export { isDefined } from './validations/isDefined';
21
23
  export { isEmptyObject } from './validations/isEmptyObject';
24
+ export { shallow } from './validations/shallow';
25
+ export { dequal } from './validations/dequal';
22
26
 
27
+ // modules
28
+ export { parseModuleId, type ParsedModuleId } from './modules/parseModuleId';
29
+
30
+ // strings
23
31
  export { pascalCase, camelCase } from './strings/camelCase';
24
32
  export { templateString } from './strings/templates';
33
+
25
34
  export { createRandom } from './maths/random';
26
35
  export { isBuffer } from './io/isBuffer';
36
+
27
37
  export { copy } from './browsers/copy';
28
38
  export { download } from './browsers/download';
29
39
  export { loadScripts, loadStyles } from './browsers/loaders';
30
40
  export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
31
41
 
32
42
  export { getGlobalThis } from './isomorphics/getGlobalThis';
43
+
33
44
  export { formatBytes } from './formats/formatBytes';
34
45
  export { urljoin } from './shim/urljoin';
35
46
 
47
+ // crypto
36
48
  export { randomUUID } from './crypto/randomUUID';
37
49
  export { sha1, sha256, sha384, sha512 } from './crypto/hashing';
38
50
  export { hex } from './crypto/hex';
@@ -0,0 +1,68 @@
1
+ import test from 'ava';
2
+ import { parseModuleId } from './parseModuleId';
3
+
4
+ test('parseModuleId', (t) => {
5
+ const tests = {
6
+ '@wener/reaction': {
7
+ id: `@wener/reaction@latest`,
8
+ name: '@wener/reaction',
9
+ range: 'latest',
10
+ scoped: true,
11
+ org: 'wener',
12
+ pkg: 'reaction',
13
+ },
14
+ reaction: {
15
+ id: `reaction@latest`,
16
+ name: 'reaction',
17
+ range: 'latest',
18
+ pkg: 'reaction',
19
+ scoped: false,
20
+ },
21
+ 'reaction@1': {
22
+ id: `reaction@1`,
23
+ name: 'reaction',
24
+ range: '1',
25
+ pkg: 'reaction',
26
+ scoped: false,
27
+ },
28
+ 'reaction@1.1.1': {
29
+ id: `reaction@1.1.1`,
30
+ name: 'reaction',
31
+ version: '1.1.1',
32
+ range: '1.1.1',
33
+ pkg: 'reaction',
34
+ scoped: false,
35
+ },
36
+ 'reaction@1.1.1-alpha': {
37
+ id: `reaction@1.1.1-alpha`,
38
+ name: 'reaction',
39
+ version: '1.1.1-alpha',
40
+ range: '1.1.1-alpha',
41
+ pkg: 'reaction',
42
+
43
+ scoped: false,
44
+ },
45
+ 'reaction@1.1.1/index.js': {
46
+ id: `reaction@1.1.1`,
47
+ name: 'reaction',
48
+ version: '1.1.1',
49
+ range: '1.1.1',
50
+ scoped: false,
51
+ pkg: 'reaction',
52
+
53
+ path: '/index.js',
54
+ },
55
+ 'reaction@1.1.1/': {
56
+ id: `reaction@1.1.1`,
57
+ name: 'reaction',
58
+ version: '1.1.1',
59
+ range: '1.1.1',
60
+ scoped: false,
61
+ pkg: 'reaction',
62
+ path: '/',
63
+ },
64
+ };
65
+ for (const [k, v] of Object.entries(tests)) {
66
+ t.deepEqual(parseModuleId(k), v);
67
+ }
68
+ });
@@ -0,0 +1,46 @@
1
+ // https://regex101.com/r/eMcXQ9/1
2
+ const regModuleId =
3
+ /^(?<n>(?:@(?<org>[a-z0-9-~][a-z0-9-._~]*)\/)?(?<pkg>[a-z0-9-~][a-z0-9-._~]*))(?:@(?<v>[-a-z0-9><=_.^~]+))?(?<p>\/[^\r\n]*)?$/;
4
+
5
+ export type ParsedModuleId = {
6
+ id: string; // name@version
7
+ name: string; // @org/pkg, pkg
8
+ version?: string; // 1.1.1
9
+ range: string; // version, tag, range
10
+ pkg: string;
11
+ path?: string;
12
+ } & (
13
+ | { scoped: false }
14
+ | {
15
+ scoped: true;
16
+ org?: string;
17
+ }
18
+ );
19
+
20
+ export function parseModuleId(s: string): ParsedModuleId | undefined {
21
+ const groups = s.match(regModuleId)?.groups;
22
+ if (!groups) {
23
+ return undefined;
24
+ }
25
+ const { n: name, v: version, p: path, org, pkg } = groups;
26
+ let scoped = Boolean(org);
27
+ const v = /^\d+\.\d+\.\d+/.test(version) ? version : undefined;
28
+ let range = version || 'latest';
29
+ const o = {
30
+ id: `${name}@${range}`,
31
+ name,
32
+ range: range,
33
+ scoped,
34
+ pkg,
35
+ } as ParsedModuleId;
36
+ if (v) {
37
+ o.version = v;
38
+ }
39
+ if (path) {
40
+ o.path = path;
41
+ }
42
+ if (o.scoped) {
43
+ o.org = org;
44
+ }
45
+ return o;
46
+ }
@@ -0,0 +1,5 @@
1
+ export async function polyfill() {
2
+ if (!('crypto' in globalThis)) {
3
+ (globalThis as any).crypto = (await import('node:crypto')).webcrypto;
4
+ }
5
+ }
package/src/server.ts ADDED
@@ -0,0 +1 @@
1
+ export { polyfill } from './server/polyfill';
@@ -1,5 +1,5 @@
1
- import { urljoin } from './urljoin';
2
1
  import test from 'ava';
2
+ import { urljoin } from './urljoin';
3
3
 
4
4
  test('join ext', (t) => {
5
5
  t.is(urljoin('http://wener.me/sub/', '/a/', '/hello.js'), 'http://wener.me/sub/a/hello.js');
@@ -0,0 +1,17 @@
1
+ import test from 'ava';
2
+ import { dequal } from './dequal';
3
+
4
+ test('deep equal', (t) => {
5
+ t.true(
6
+ dequal(
7
+ {
8
+ a: null,
9
+ b: Infinity,
10
+ },
11
+ {
12
+ a: null,
13
+ b: Infinity,
14
+ },
15
+ ),
16
+ );
17
+ });
@@ -0,0 +1,105 @@
1
+ const has = Object.prototype.hasOwnProperty;
2
+ const hasElementType = typeof Element !== 'undefined';
3
+
4
+ function find(iter: any, tar: any, key?: any) {
5
+ for (key of iter.keys()) {
6
+ if (dequal(key, tar)) return key;
7
+ }
8
+ }
9
+
10
+ /**
11
+ * deep equal - support react, dom, Date, RegExp, Array, ArrayBuffer, Set, Map, Object
12
+ * @see {@link https://github.com/lukeed/dequal/blob/master/src/lite.js dequal/src/lite.js}
13
+ * @see {@link https://github.com/FormidableLabs/react-fast-compare/blob/master/index.js react-fast-compare/index.js}
14
+ */
15
+ export function dequal(foo: any, bar: any) {
16
+ let ctor, len, tmp;
17
+ if (foo === bar) return true;
18
+
19
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
20
+ if (ctor === Date) return foo.getTime() === bar.getTime();
21
+ if (ctor === RegExp) return foo.toString() === bar.toString();
22
+
23
+ if (ctor === Array) {
24
+ if ((len = foo.length) === bar.length) {
25
+ while (len-- && dequal(foo[len], bar[len]));
26
+ }
27
+ return len === -1;
28
+ }
29
+
30
+ if (ctor === Set) {
31
+ if (foo.size !== bar.size) {
32
+ return false;
33
+ }
34
+ for (len of foo) {
35
+ tmp = len;
36
+ if (tmp && typeof tmp === 'object') {
37
+ tmp = find(bar, tmp);
38
+ if (!tmp) return false;
39
+ }
40
+ if (!bar.has(tmp)) return false;
41
+ }
42
+ return true;
43
+ }
44
+
45
+ if (ctor === Map) {
46
+ if (foo.size !== bar.size) {
47
+ return false;
48
+ }
49
+ for (len of foo) {
50
+ tmp = len[0];
51
+ if (tmp && typeof tmp === 'object') {
52
+ tmp = find(bar, tmp);
53
+ if (!tmp) return false;
54
+ }
55
+ if (!dequal(len[1], bar.get(tmp))) {
56
+ return false;
57
+ }
58
+ }
59
+ return true;
60
+ }
61
+
62
+ if (ctor === ArrayBuffer) {
63
+ foo = new Uint8Array(foo);
64
+ bar = new Uint8Array(bar);
65
+ } else if (ctor === DataView) {
66
+ if ((len = foo.byteLength) === bar.byteLength) {
67
+ while (len-- && foo.getInt8(len) === bar.getInt8(len));
68
+ }
69
+ return len === -1;
70
+ }
71
+
72
+ if (ArrayBuffer.isView(foo)) {
73
+ if ((len = foo.byteLength) === bar.byteLength) {
74
+ while (len-- && (foo as any)[len] === bar[len]);
75
+ }
76
+ return len === -1;
77
+ }
78
+
79
+ // react & dom
80
+ if (hasElementType && foo instanceof Element) return false;
81
+
82
+ if (!ctor || typeof foo === 'object') {
83
+ len = 0;
84
+ for (ctor in foo) {
85
+ if ((ctor === '_owner' || ctor === '__v' || ctor === '__o') && foo.$$typeof) {
86
+ // React-specific: avoid traversing React elements' _owner
87
+ // Preact-specific: avoid traversing Preact elements' __v and __o
88
+ // __v = $_original / $_vnode
89
+ // __o = $_owner
90
+ // These properties contain circular references and are not needed when
91
+ // comparing the actual elements (and not their owners)
92
+ // .$$typeof and ._store on just reasonable markers of elements
93
+
94
+ continue;
95
+ }
96
+
97
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
98
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
99
+ }
100
+ return Object.keys(bar).length === len;
101
+ }
102
+ }
103
+
104
+ return foo !== foo && bar !== bar;
105
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * shallow compare - support object, array
3
+ *
4
+ * @see {@link https://github.com/pmndrs/zustand/blob/main/src/shallow.ts zustand/src/shallow.ts}
5
+ */
6
+ export function shallow<T, U>(objA: T, objB: U) {
7
+ if (Object.is(objA, objB)) {
8
+ return true;
9
+ }
10
+ if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
11
+ return false;
12
+ }
13
+ const keysA = Object.keys(objA);
14
+ if (keysA.length !== Object.keys(objB).length) {
15
+ return false;
16
+ }
17
+ for (let i = 0; i < keysA.length; i++) {
18
+ if (
19
+ !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||
20
+ !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof U])
21
+ ) {
22
+ return false;
23
+ }
24
+ }
25
+ return true;
26
+ }