@wener/utils 1.1.1 → 1.1.2

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 (178) hide show
  1. package/dist/cjs/index.js +579 -0
  2. package/dist/cjs/index.js.map +1 -0
  3. package/dist/esm/index.development.js +545 -0
  4. package/dist/esm/index.development.js.map +1 -0
  5. package/dist/esm/index.min.js +2 -0
  6. package/dist/esm/index.min.js.map +1 -0
  7. package/dist/system/index.development.js +585 -0
  8. package/dist/system/index.development.js.map +1 -0
  9. package/dist/system/index.min.js +2 -0
  10. package/dist/system/index.min.js.map +1 -0
  11. package/lib/esm/arrays/MaybeArray.mjs +30 -0
  12. package/lib/esm/arrays/MaybeArray.mjs.map +1 -0
  13. package/lib/esm/asyncs/AsyncInterval.mjs +15 -0
  14. package/lib/esm/asyncs/AsyncInterval.mjs.map +1 -0
  15. package/lib/esm/asyncs/LazyPromise.mjs +24 -0
  16. package/lib/esm/asyncs/LazyPromise.mjs.map +1 -0
  17. package/lib/esm/asyncs/isPromise.mjs +6 -0
  18. package/lib/esm/asyncs/isPromise.mjs.map +1 -0
  19. package/lib/esm/asyncs/{sleep.js → sleep.mjs} +3 -3
  20. package/lib/esm/asyncs/sleep.mjs.map +1 -0
  21. package/lib/esm/asyncs/timeout.mjs +24 -0
  22. package/lib/esm/asyncs/timeout.mjs.map +1 -0
  23. package/lib/esm/browsers/copy.mjs +57 -0
  24. package/lib/esm/browsers/copy.mjs.map +1 -0
  25. package/lib/esm/browsers/download.mjs +40 -0
  26. package/lib/esm/browsers/download.mjs.map +1 -0
  27. package/lib/esm/browsers/getFileFromDataTransfer.mjs +39 -0
  28. package/lib/esm/browsers/getFileFromDataTransfer.mjs.map +1 -0
  29. package/lib/esm/browsers/loaders.mjs +52 -0
  30. package/lib/esm/browsers/loaders.mjs.map +1 -0
  31. package/lib/esm/crypto/hashing.mjs +25 -0
  32. package/lib/esm/crypto/hashing.mjs.map +1 -0
  33. package/lib/esm/crypto/hex.mjs +8 -0
  34. package/lib/esm/crypto/hex.mjs.map +1 -0
  35. package/lib/esm/crypto/randomUUID.mjs +13 -0
  36. package/lib/esm/crypto/randomUUID.mjs.map +1 -0
  37. package/lib/esm/formats/formatBytes.mjs +29 -0
  38. package/lib/esm/formats/formatBytes.mjs.map +1 -0
  39. package/lib/esm/index.mjs +24 -0
  40. package/lib/esm/index.mjs.map +1 -0
  41. package/lib/esm/io/isBuffer.mjs +10 -0
  42. package/lib/esm/io/isBuffer.mjs.map +1 -0
  43. package/lib/esm/isomorphics/getGlobalThis.mjs +23 -0
  44. package/lib/esm/isomorphics/getGlobalThis.mjs.map +1 -0
  45. package/lib/esm/maths/random.mjs +18 -0
  46. package/lib/esm/maths/random.mjs.map +1 -0
  47. package/lib/esm/shim/urljoin.mjs +65 -0
  48. package/lib/esm/shim/urljoin.mjs.map +1 -0
  49. package/lib/esm/strings/camelCase.mjs +70 -0
  50. package/lib/esm/strings/camelCase.mjs.map +1 -0
  51. package/lib/esm/strings/templates.mjs +16 -0
  52. package/lib/esm/strings/templates.mjs.map +1 -0
  53. package/lib/esm/validations/isClass.mjs +6 -0
  54. package/lib/esm/validations/isClass.mjs.map +1 -0
  55. package/lib/esm/validations/isDefined.mjs +6 -0
  56. package/lib/esm/validations/isDefined.mjs.map +1 -0
  57. package/lib/esm/validations/isEmptyObject.mjs +9 -0
  58. package/lib/esm/validations/isEmptyObject.mjs.map +1 -0
  59. package/package.json +35 -22
  60. package/src/browsers/copy.ts +7 -3
  61. package/src/browsers/download.ts +7 -0
  62. package/src/browsers/loaders.ts +32 -7
  63. package/src/crypto/hashing.test.ts +26 -0
  64. package/src/crypto/hashing.ts +27 -0
  65. package/src/crypto/hex.ts +5 -0
  66. package/src/crypto/randomUUID.ts +10 -0
  67. package/src/index.ts +34 -7
  68. package/src/shim/urljoin.test.ts +3 -2
  69. package/src/types.d.ts +7 -0
  70. package/tsconfig.json +5 -9
  71. package/jest.config.js +0 -18
  72. package/jest.setup.js +0 -1
  73. package/lib/cjs/arrays/MaybeArray.js +0 -52
  74. package/lib/cjs/arrays/index.js +0 -17
  75. package/lib/cjs/asyncs/AsyncInterval.js +0 -35
  76. package/lib/cjs/asyncs/LazyPromise.js +0 -43
  77. package/lib/cjs/asyncs/MaybePromise.js +0 -15
  78. package/lib/cjs/asyncs/generatorOfStream.js +0 -35
  79. package/lib/cjs/asyncs/index.js +0 -23
  80. package/lib/cjs/asyncs/isPromise.js +0 -25
  81. package/lib/cjs/asyncs/promiseOfCallback.js +0 -37
  82. package/lib/cjs/asyncs/sleep.js +0 -23
  83. package/lib/cjs/asyncs/timeout.js +0 -44
  84. package/lib/cjs/browsers/copy.js +0 -71
  85. package/lib/cjs/browsers/download.js +0 -47
  86. package/lib/cjs/browsers/getFileFromDataTransfer.js +0 -48
  87. package/lib/cjs/browsers/index.js +0 -20
  88. package/lib/cjs/browsers/loaders.js +0 -54
  89. package/lib/cjs/formats/formatBytes.js +0 -36
  90. package/lib/cjs/index.js +0 -35
  91. package/lib/cjs/io/index.js +0 -17
  92. package/lib/cjs/io/isBuffer.js +0 -25
  93. package/lib/cjs/isomorphics/getGlobalThis.js +0 -33
  94. package/lib/cjs/maths/index.js +0 -17
  95. package/lib/cjs/maths/random.js +0 -36
  96. package/lib/cjs/shim/urljoin.js +0 -70
  97. package/lib/cjs/shim/urljoin.test.js +0 -4
  98. package/lib/cjs/strings/camelCase.js +0 -76
  99. package/lib/cjs/strings/index.js +0 -18
  100. package/lib/cjs/strings/templates.js +0 -27
  101. package/lib/cjs/validations/asserts.js +0 -29
  102. package/lib/cjs/validations/index.js +0 -20
  103. package/lib/cjs/validations/isClass.js +0 -25
  104. package/lib/cjs/validations/isDefined.js +0 -25
  105. package/lib/cjs/validations/isEmptyObject.js +0 -28
  106. package/lib/esm/arrays/MaybeArray.d.ts +0 -5
  107. package/lib/esm/arrays/MaybeArray.js +0 -33
  108. package/lib/esm/arrays/index.d.ts +0 -1
  109. package/lib/esm/arrays/index.js +0 -1
  110. package/lib/esm/asyncs/AsyncInterval.d.ts +0 -3
  111. package/lib/esm/asyncs/AsyncInterval.js +0 -16
  112. package/lib/esm/asyncs/LazyPromise.d.ts +0 -5
  113. package/lib/esm/asyncs/LazyPromise.js +0 -24
  114. package/lib/esm/asyncs/MaybePromise.d.ts +0 -1
  115. package/lib/esm/asyncs/MaybePromise.js +0 -0
  116. package/lib/esm/asyncs/generatorOfStream.d.ts +0 -1
  117. package/lib/esm/asyncs/generatorOfStream.js +0 -16
  118. package/lib/esm/asyncs/index.d.ts +0 -7
  119. package/lib/esm/asyncs/index.js +0 -7
  120. package/lib/esm/asyncs/isPromise.d.ts +0 -1
  121. package/lib/esm/asyncs/isPromise.js +0 -6
  122. package/lib/esm/asyncs/promiseOfCallback.d.ts +0 -1
  123. package/lib/esm/asyncs/promiseOfCallback.js +0 -18
  124. package/lib/esm/asyncs/sleep.d.ts +0 -1
  125. package/lib/esm/asyncs/timeout.d.ts +0 -4
  126. package/lib/esm/asyncs/timeout.js +0 -25
  127. package/lib/esm/browsers/copy.d.ts +0 -1
  128. package/lib/esm/browsers/copy.js +0 -52
  129. package/lib/esm/browsers/download.d.ts +0 -4
  130. package/lib/esm/browsers/download.js +0 -28
  131. package/lib/esm/browsers/getFileFromDataTransfer.d.ts +0 -4
  132. package/lib/esm/browsers/getFileFromDataTransfer.js +0 -29
  133. package/lib/esm/browsers/index.d.ts +0 -4
  134. package/lib/esm/browsers/index.js +0 -4
  135. package/lib/esm/browsers/loaders.d.ts +0 -6
  136. package/lib/esm/browsers/loaders.js +0 -35
  137. package/lib/esm/formats/formatBytes.d.ts +0 -11
  138. package/lib/esm/formats/formatBytes.js +0 -17
  139. package/lib/esm/index.d.ts +0 -10
  140. package/lib/esm/index.js +0 -15
  141. package/lib/esm/io/index.d.ts +0 -1
  142. package/lib/esm/io/index.js +0 -1
  143. package/lib/esm/io/isBuffer.d.ts +0 -2
  144. package/lib/esm/io/isBuffer.js +0 -6
  145. package/lib/esm/isomorphics/getGlobalThis.d.ts +0 -9
  146. package/lib/esm/isomorphics/getGlobalThis.js +0 -14
  147. package/lib/esm/maths/index.d.ts +0 -1
  148. package/lib/esm/maths/index.js +0 -1
  149. package/lib/esm/maths/random.d.ts +0 -3
  150. package/lib/esm/maths/random.js +0 -17
  151. package/lib/esm/shim/urljoin.d.ts +0 -2
  152. package/lib/esm/shim/urljoin.js +0 -51
  153. package/lib/esm/shim/urljoin.test.d.ts +0 -1
  154. package/lib/esm/shim/urljoin.test.js +0 -4
  155. package/lib/esm/strings/camelCase.d.ts +0 -4
  156. package/lib/esm/strings/camelCase.js +0 -57
  157. package/lib/esm/strings/index.d.ts +0 -2
  158. package/lib/esm/strings/index.js +0 -2
  159. package/lib/esm/strings/templates.d.ts +0 -7
  160. package/lib/esm/strings/templates.js +0 -8
  161. package/lib/esm/validations/asserts.d.ts +0 -2
  162. package/lib/esm/validations/asserts.js +0 -10
  163. package/lib/esm/validations/index.d.ts +0 -4
  164. package/lib/esm/validations/index.js +0 -4
  165. package/lib/esm/validations/isClass.d.ts +0 -1
  166. package/lib/esm/validations/isClass.js +0 -6
  167. package/lib/esm/validations/isDefined.d.ts +0 -1
  168. package/lib/esm/validations/isDefined.js +0 -6
  169. package/lib/esm/validations/isEmptyObject.d.ts +0 -1
  170. package/lib/esm/validations/isEmptyObject.js +0 -9
  171. package/src/arrays/index.ts +0 -1
  172. package/src/asyncs/index.ts +0 -8
  173. package/src/browsers/index.ts +0 -4
  174. package/src/io/index.ts +0 -1
  175. package/src/maths/index.ts +0 -1
  176. package/src/strings/index.ts +0 -2
  177. package/src/validations/index.ts +0 -4
  178. package/tsconfig.jest.json +0 -7
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @see {@link https://github.com/jfromaniello/url-join}
3
+ */
4
+ function urljoin(...args) {
5
+ if (Array.isArray(args[0])) {
6
+ return normalize(args[0]);
7
+ }
8
+ else {
9
+ return normalize(args);
10
+ }
11
+ }
12
+ function normalize(strArray) {
13
+ const resultArray = [];
14
+ if (strArray.length === 0) {
15
+ return '';
16
+ }
17
+ if (typeof strArray[0] !== 'string') {
18
+ throw new TypeError('Url must be a string. Received ' + strArray[0]);
19
+ }
20
+ // If the first part is a plain protocol, we combine it with the next part.
21
+ if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
22
+ const first = strArray.shift();
23
+ strArray[0] = first + strArray[0];
24
+ }
25
+ // There must be two or three slashes in the file protocol, two slashes in anything else.
26
+ if (strArray[0].match(/^file:\/\/\//)) {
27
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1:///');
28
+ }
29
+ else {
30
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1://');
31
+ }
32
+ for (let i = 0; i < strArray.length; i++) {
33
+ let component = strArray[i];
34
+ if (typeof component !== 'string') {
35
+ throw new TypeError('Url must be a string. Received ' + component);
36
+ }
37
+ if (component === '') {
38
+ continue;
39
+ }
40
+ if (i > 0) {
41
+ // Removing the starting slashes for each component but the first.
42
+ component = component.replace(/^[\/]+/, '');
43
+ }
44
+ if (i < strArray.length - 1) {
45
+ // Removing the ending slashes for each component but the last.
46
+ component = component.replace(/[\/]+$/, '');
47
+ }
48
+ else {
49
+ // For the last component we will combine multiple slashes to a single one.
50
+ component = component.replace(/[\/]+$/, '/');
51
+ }
52
+ resultArray.push(component);
53
+ }
54
+ let str = resultArray.join('/');
55
+ // Each input component is now separated by a single slash except the possible first plain protocol part.
56
+ // remove trailing slash before parameters or hash
57
+ str = str.replace(/\/(\?|&|#[^!])/g, '$1');
58
+ // replace ? in parameters with &
59
+ const parts = str.split('?');
60
+ str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
61
+ return str;
62
+ }
63
+
64
+ export { urljoin };
65
+ //# sourceMappingURL=urljoin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urljoin.mjs","sources":["../../../src/shim/urljoin.ts"],"sourcesContent":[null],"names":[],"mappings":"AAGA;;AAEG;AACa,SAAA,OAAO,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us/camelcase/blob/master/index.js
2
+ function preserveCamelCase(string) {
3
+ let isLastCharLower = false;
4
+ let isLastCharUpper = false;
5
+ let isLastLastCharUpper = false;
6
+ for (let i = 0; i < string.length; i++) {
7
+ const character = string[i];
8
+ if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {
9
+ string = string.slice(0, i) + '-' + string.slice(i);
10
+ isLastCharLower = false;
11
+ isLastLastCharUpper = isLastCharUpper;
12
+ isLastCharUpper = true;
13
+ i++;
14
+ }
15
+ else if (isLastCharUpper &&
16
+ isLastLastCharUpper &&
17
+ /[a-zA-Z]/.test(character) &&
18
+ character.toLowerCase() === character) {
19
+ string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
20
+ isLastLastCharUpper = isLastCharUpper;
21
+ isLastCharUpper = false;
22
+ isLastCharLower = true;
23
+ }
24
+ else {
25
+ isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
26
+ isLastLastCharUpper = isLastCharUpper;
27
+ isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
28
+ }
29
+ }
30
+ return string;
31
+ }
32
+ function pascalCase(input) {
33
+ return camelCase(input, { pascalCase: true });
34
+ }
35
+ function camelCase(input, options = {
36
+ pascalCase: false,
37
+ }) {
38
+ if (!(typeof input === 'string' || Array.isArray(input))) {
39
+ throw new TypeError('Expected the input to be `string | string[]`');
40
+ }
41
+ const postProcess = (x) => (options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x);
42
+ if (Array.isArray(input)) {
43
+ input = input
44
+ .map((x) => x.trim())
45
+ .filter((x) => x.length)
46
+ .join('-');
47
+ }
48
+ else {
49
+ input = input.trim();
50
+ }
51
+ if (input.length === 0) {
52
+ return '';
53
+ }
54
+ if (input.length === 1) {
55
+ return options.pascalCase ? input.toUpperCase() : input.toLowerCase();
56
+ }
57
+ const hasUpperCase = input !== input.toLowerCase();
58
+ if (hasUpperCase) {
59
+ input = preserveCamelCase(input);
60
+ }
61
+ input = input
62
+ .replace(/^[_.\- ]+/, '')
63
+ .toLowerCase()
64
+ .replace(/[_.\- ]+(\w|$)/g, (_, p1) => p1.toUpperCase())
65
+ .replace(/\d+(\w|$)/g, (m) => m.toUpperCase());
66
+ return postProcess(input);
67
+ }
68
+
69
+ export { camelCase, pascalCase };
70
+ //# sourceMappingURL=camelCase.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camelCase.mjs","sources":["../../../src/strings/camelCase.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AAEA,SAAS,iBAAiB,CAAC,MAAc,EAAA;IACvC,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACtC,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAE5B,QAAA,IAAI,eAAe,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,WAAW,EAAE,KAAK,SAAS,EAAE;AAC1F,YAAA,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACpD,eAAe,GAAG,KAAK,CAAC;YACxB,mBAAmB,GAAG,eAAe,CAAC;YACtC,eAAe,GAAG,IAAI,CAAC;AACvB,YAAA,CAAC,EAAE,CAAC;AACL,SAAA;AAAM,aAAA,IACL,eAAe;YACf,mBAAmB;AACnB,YAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;AAC1B,YAAA,SAAS,CAAC,WAAW,EAAE,KAAK,SAAS,EACrC;YACA,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAA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AI,EAAE,CAAC;aACpB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;aACvB,IAAI,CAAC,GAAG,CAAC,CAAC;AACd,KAAA;AAAM,SAAA;AACL,QAAA,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;AACtB,KAAA;AAED,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;AACtB,QAAA,OAAO,EAAE,CAAC;AACX,KAAA;AAED,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;AACtB,QAAA,OAAO,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;AACvE,KAAA;IAED,MAAM,YAAY,GAAG,KAAK,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC;AAEnD,IAAA,IAAI,YAAY,EAAE;AAChB,QAAA,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAClC,KAAA;AAED,IAAA,KAAK,GAAG,KAAK;AACV,SAAA,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AACxB,SAAA,WAAW,EAAE;AACb,SAAA,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC;AACvD,SAAA,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAEjD,IAAA,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B;;;;"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 替换类似于 JS 的模板字符串
3
+ *
4
+ * @example
5
+ * templateString('My name is ${name}',{name:'wener'})
6
+ */
7
+ function templateString(template, getter) {
8
+ return template.replace(/\${(.*?)}/g, (_, g) => {
9
+ // variables[g.trim()]
10
+ // 支持路径 - 例如 a.b[0]
11
+ return getter(g.trim());
12
+ });
13
+ }
14
+
15
+ export { templateString };
16
+ //# sourceMappingURL=templates.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.mjs","sources":["../../../src/strings/templates.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;AAKG;AACa,SAAA,cAAc,CAAC,QAAgB,EAAE,MAA0B,EAAA;IACzE,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,KAAI;;;AAG7C,QAAA,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC1B,KAAC,CAAC,CAAC;AACL;;;;"}
@@ -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.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isClass.mjs","sources":["../../../src/validations/isClass.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAM,SAAU,OAAO,CAAC,IAAS,EAAA;IAC/B,OAAO,OAAO,IAAI,KAAK,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/F;;;;"}
@@ -0,0 +1,6 @@
1
+ function isDefined(v) {
2
+ return v !== null && v !== undefined;
3
+ }
4
+
5
+ export { isDefined };
6
+ //# sourceMappingURL=isDefined.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isDefined.mjs","sources":["../../../src/validations/isDefined.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAM,SAAU,SAAS,CAAU,CAAI,EAAA;AACrC,IAAA,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,CAAC;AACvC;;;;"}
@@ -0,0 +1,9 @@
1
+ function isEmptyObject(o) {
2
+ if (o === null || o === undefined) {
3
+ return true;
4
+ }
5
+ return o.constructor === Object && Object.keys(o).length === 0;
6
+ }
7
+
8
+ export { isEmptyObject };
9
+ //# sourceMappingURL=isEmptyObject.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isEmptyObject.mjs","sources":["../../../src/validations/isEmptyObject.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAM,SAAU,aAAa,CAAC,CAAM,EAAA;AAClC,IAAA,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,EAAE;AACjC,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;AACD,IAAA,OAAO,CAAC,CAAC,WAAW,KAAK,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AACjE;;;;"}
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Utils for daily use",
5
+ "type": "module",
6
+ "sideEffects": false,
5
7
  "keywords": [
6
8
  "utils",
7
9
  "core library",
@@ -13,20 +15,25 @@
13
15
  },
14
16
  "license": "MIT",
15
17
  "author": "wener",
16
- "main": "lib/cjs/index.js",
17
- "module": "lib/esm/index.js",
18
- "types": "src/index.ts",
19
- "esnext": "lib/esnext/index.js",
20
- "umd:main": "dist/utils.js",
21
- "unpkg": "dist/utils.js",
22
- "jsdelivr": "dist/utils.js",
23
- "jsnext:main": "dist/utils.esm.js",
24
18
  "exports": {
25
19
  ".": {
26
- "import": "./lib/esm/index.js",
27
- "require": "./lib/cjs/index.js"
28
- }
20
+ "types": "./src/index.ts",
21
+ "import": "./lib/esm/index.mjs",
22
+ "system": {
23
+ "development": "./dist/system/index.development.js",
24
+ "default": "./dist/system/index.min.js"
25
+ },
26
+ "require": "./dist/cjs/index.js"
27
+ },
28
+ "./types": {
29
+ "types": "./src/types.d.ts"
30
+ },
31
+ "./src/*": "./src/*",
32
+ "./package.json": "./package.json"
29
33
  },
34
+ "main": "dist/cjs/index.js",
35
+ "import": "lib/esm/index.mjs",
36
+ "types": "src/index.ts",
30
37
  "homepage": "https://github.com/wenerme/wode#readme",
31
38
  "files": [
32
39
  "index.js",
@@ -42,21 +49,13 @@
42
49
  "tsconfig.jest.json",
43
50
  "tsconfig.json"
44
51
  ],
45
- "scripts": {
46
- "build": "make prepublish",
47
- "clean": "make clean",
48
- "dev": "make dev",
49
- "test": "jest"
50
- },
51
52
  "devDependencies": {
52
- "@types/jest": "^28",
53
53
  "@types/lodash": "^4",
54
54
  "@types/node": "^16",
55
+ "ava": "^4.3.3",
55
56
  "dotenv": "^16",
56
57
  "esbuild": "^0.14",
57
- "jest": "^28",
58
58
  "lodash": "^4",
59
- "ts-jest": "^28",
60
59
  "tslib": "^2",
61
60
  "typescript": "^4"
62
61
  },
@@ -66,5 +65,19 @@
66
65
  "engines": {
67
66
  "node": "16",
68
67
  "npm": "8"
68
+ },
69
+ "ava": {
70
+ "extensions": {
71
+ "ts": "module"
72
+ },
73
+ "nodeArguments": [
74
+ "--loader=tsx"
75
+ ]
76
+ },
77
+ "scripts": {
78
+ "build": "make prepublish",
79
+ "clean": "make clean",
80
+ "dev": "make dev",
81
+ "test": "make test"
69
82
  }
70
- }
83
+ }
@@ -45,13 +45,17 @@ function initCopy() {
45
45
  };
46
46
  }
47
47
 
48
- export function copy(text: string) {
48
+ /**
49
+ * Write text to clipboard
50
+ * @param content content
51
+ */
52
+ export function copy(content: string) {
49
53
  if (window.navigator?.clipboard?.writeText) {
50
- window.navigator.clipboard.writeText(text);
54
+ window.navigator.clipboard.writeText(content);
51
55
  return;
52
56
  }
53
57
  if (!_copy) {
54
58
  initCopy();
55
59
  }
56
- _copy(text);
60
+ _copy(content);
57
61
  }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Trigger browser download
3
+ * @param filename download as filename
4
+ * @param data data or url to download
5
+ * @param type content type
6
+ * @param raw if true, data is treated as raw data, not url
7
+ */
1
8
  export function download(filename: string, data: any, { type = 'application/octet-stream', raw = false } = {}) {
2
9
  const a = document.createElement('a');
3
10
  let closer: () => void = () => null;
@@ -4,7 +4,7 @@ function load(
4
4
  reject: (v: any) => void,
5
5
  options: { attributes: Record<string, string> } | undefined,
6
6
  ) {
7
- el.onload = resolve;
7
+ el.onload = () => resolve(el);
8
8
  el.onerror = (e) => {
9
9
  el.remove();
10
10
  reject(e);
@@ -15,10 +15,34 @@ function load(
15
15
  document.head.appendChild(el);
16
16
  }
17
17
 
18
- export function loadScripts(src: string, options?: { attributes: Record<string, string> }) {
18
+ export function loadScripts(
19
+ src: string[],
20
+ options?: { attributes: Record<string, string> },
21
+ ): Promise<HTMLScriptElement[]>;
22
+ export function loadScripts(src: string, options?: { attributes: Record<string, string> }): Promise<HTMLScriptElement>;
23
+
24
+ export function loadScripts(
25
+ src: string | string[],
26
+ options?: { attributes: Record<string, string> },
27
+ ): Promise<HTMLScriptElement | HTMLScriptElement[]> {
28
+ if (Array.isArray(src)) {
29
+ return new Promise(async (resolve, reject) => {
30
+ const all = [];
31
+ try {
32
+ for (let s of src) {
33
+ all.push(await loadScripts(s));
34
+ }
35
+ } catch (e) {
36
+ reject(e);
37
+ return;
38
+ }
39
+ resolve(all);
40
+ });
41
+ }
19
42
  // todo quote ?
20
- if (document.querySelector(`script[src="${src}"]`)) {
21
- return Promise.resolve();
43
+ let $ele = document.querySelector(`script[src="${src}"]`) as HTMLScriptElement;
44
+ if ($ele) {
45
+ return Promise.resolve($ele);
22
46
  }
23
47
  return new Promise((resolve, reject) => {
24
48
  const el = document.createElement('script');
@@ -27,9 +51,10 @@ export function loadScripts(src: string, options?: { attributes: Record<string,
27
51
  });
28
52
  }
29
53
 
30
- export function loadStyles(href: string, options?: { attributes: Record<string, string> }) {
31
- if (document.querySelector(`link[href="${href}"]`)) {
32
- return Promise.resolve();
54
+ export function loadStyles(href: string, options?: { attributes: Record<string, string> }): Promise<HTMLLinkElement> {
55
+ let $ele = document.querySelector(`link[href="${href}"]`) as HTMLLinkElement;
56
+ if ($ele) {
57
+ return Promise.resolve($ele);
33
58
  }
34
59
 
35
60
  return new Promise((resolve, reject) => {
@@ -0,0 +1,26 @@
1
+ import test from 'ava';
2
+ import { sha1, sha256, sha384, sha512 } from './hashing';
3
+ import { hex } from './hex';
4
+ import { randomUUID } from './randomUUID';
5
+
6
+ test.before(async (t) => {
7
+ if (!('crypto' in globalThis)) {
8
+ (globalThis as any).crypto = (await import('node:crypto')).webcrypto;
9
+ t.log(`load node:crypto`);
10
+ }
11
+ });
12
+
13
+ test('sha', async (t) => {
14
+ t.is(hex(await sha1('')), 'da39a3ee5e6b4b0d3255bfef95601890afd80709');
15
+ t.is(hex(await sha1('abc')), 'a9993e364706816aba3e25717850c26c9cd0d89d');
16
+ t.is(hex(await sha256('')), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
17
+ t.is(
18
+ hex(await sha384('')),
19
+ '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b',
20
+ );
21
+ t.is(
22
+ hex(await sha512('')),
23
+ 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e',
24
+ );
25
+ t.regex(randomUUID(), /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
26
+ });
@@ -0,0 +1,27 @@
1
+ export async function sha1(s: string | BufferSource) {
2
+ return digestOf('SHA-1', s);
3
+ }
4
+
5
+ export async function sha256(s: string | BufferSource) {
6
+ return digestOf('SHA-256', s);
7
+ }
8
+
9
+ export async function sha384(s: string | BufferSource) {
10
+ return digestOf('SHA-384', s);
11
+ }
12
+
13
+ export async function sha512(s: string | BufferSource) {
14
+ return digestOf('SHA-512', s);
15
+ }
16
+
17
+ function digestOf(a: string, s: string | BufferSource) {
18
+ return crypto.subtle.digest(a, bufferOf(s));
19
+ }
20
+
21
+ function bufferOf(s: string | BufferSource) {
22
+ // ArrayBuffer, TypedArray, DataView
23
+ if (typeof s === 'string') {
24
+ return new TextEncoder().encode(s);
25
+ }
26
+ return s;
27
+ }
@@ -0,0 +1,5 @@
1
+ export function hex(s: Uint8Array | ArrayBuffer) {
2
+ return Array.from(new Uint8Array(s))
3
+ .map((v) => v.toString(16).padStart(2, '0'))
4
+ .join('');
5
+ }
@@ -0,0 +1,10 @@
1
+ export function randomUUID() {
2
+ if ('randomUUID' in crypto) {
3
+ return crypto.randomUUID();
4
+ }
5
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
6
+ const r = (Math.random() * 16) | 0;
7
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
8
+ return v.toString(16);
9
+ });
10
+ }
package/src/index.ts CHANGED
@@ -1,11 +1,38 @@
1
- export * from './arrays/index';
2
- export * from './asyncs';
3
- export * from './validations';
4
- export * from './strings';
5
- export * from './maths';
6
- export * from './io';
7
- export * from './browsers';
1
+ export {
2
+ firstOfMaybeArray,
3
+ lastOfMaybeArray,
4
+ arrayOfMaybeArray,
5
+ objectOfMaybeArray,
6
+ type MaybeArray,
7
+ } from './arrays/MaybeArray';
8
+
9
+ export { createLazyPromise, type LazyPromise } from './asyncs/LazyPromise';
10
+ export { setAsyncInterval, clearAsyncInterval } from './asyncs/AsyncInterval';
11
+ export { type MaybePromise } from './asyncs/MaybePromise';
12
+
13
+ export { sleep } from './asyncs/sleep';
14
+ export { timeout, TimeoutError } from './asyncs/timeout';
15
+ export { isPromise } from './asyncs/isPromise';
16
+ // export * from './async/promiseOfCallback';
17
+
18
+ // asserts.ts
19
+ export { isClass } from './validations/isClass';
20
+ export { isDefined } from './validations/isDefined';
21
+ export { isEmptyObject } from './validations/isEmptyObject';
22
+
23
+ export { pascalCase, camelCase } from './strings/camelCase';
24
+ export { templateString } from './strings/templates';
25
+ export { createRandom } from './maths/random';
26
+ export { isBuffer } from './io/isBuffer';
27
+ export { copy } from './browsers/copy';
28
+ export { download } from './browsers/download';
29
+ export { loadScripts, loadStyles } from './browsers/loaders';
30
+ export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
8
31
 
9
32
  export { getGlobalThis } from './isomorphics/getGlobalThis';
10
33
  export { formatBytes } from './formats/formatBytes';
11
34
  export { urljoin } from './shim/urljoin';
35
+
36
+ export { randomUUID } from './crypto/randomUUID';
37
+ export { sha1, sha256, sha384, sha512 } from './crypto/hashing';
38
+ export { hex } from './crypto/hex';
@@ -1,5 +1,6 @@
1
1
  import { urljoin } from './urljoin';
2
+ import test from 'ava';
2
3
 
3
- test('join ext', () => {
4
- expect(urljoin('http://wener.me/sub/', '/a/', '/hello.js')).toBe('http://wener.me/sub/a/hello.js');
4
+ test('join ext', (t) => {
5
+ t.is(urljoin('http://wener.me/sub/', '/a/', '/hello.js'), 'http://wener.me/sub/a/hello.js');
5
6
  });
package/src/types.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ declare var __DEV__: boolean;
2
+
3
+ namespace NodeJS {
4
+ interface ProcessEnv {
5
+ readonly NODE_ENV: 'development' | 'production' | 'test';
6
+ }
7
+ }
package/tsconfig.json CHANGED
@@ -1,20 +1,17 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "moduleResolution": "node",
4
- "target": "esnext",
5
- "module": "esnext",
4
+ "target": "ESNext",
5
+ "module": "ESNext",
6
6
  "lib": [
7
7
  "dom",
8
8
  "dom.iterable",
9
- "es5",
10
- "es2015.collection",
11
- "es2015.iterable",
12
- "esnext"
9
+ "ES2018"
13
10
  ],
14
11
  "strict": true,
15
12
  "sourceMap": true,
16
13
  "skipLibCheck": true,
17
- "declaration": true,
14
+ "declaration": false,
18
15
  "esModuleInterop": true,
19
16
  "importHelpers": true,
20
17
  "allowSyntheticDefaultImports": true,
@@ -29,8 +26,7 @@
29
26
  "stripInternal": true
30
27
  },
31
28
  "exclude": [
32
- "node_modules",
33
- "**/__tests__/*"
29
+ "node_modules"
34
30
  ],
35
31
  "include": [
36
32
  "src"
package/jest.config.js DELETED
@@ -1,18 +0,0 @@
1
- // const { pathsToModuleNameMapper } = require('ts-jest/utils');
2
- // const { compilerOptions } = require('./tsconfig');
3
-
4
- module.exports = {
5
- setupFiles: ['<rootDir>/jest.setup.js'],
6
- transform: {
7
- '^.+\\.(ts|tsx)$': 'ts-jest',
8
- },
9
- globals: {
10
- 'ts-jest': {
11
- tsConfig: 'tsconfig.jest.json',
12
- // tsConfig: 'tsconfig.json',
13
- },
14
- },
15
- // roots: ['<rootDir>/src/', '<rootDir>/tests/'],
16
- testMatch: ['<rootDir>/src/**/?(*.)+(spec|test).[jt]s?(x)'],
17
- // moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' })
18
- };
package/jest.setup.js DELETED
@@ -1 +0,0 @@
1
- require('dotenv').config();
@@ -1,52 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var MaybeArray_exports = {};
19
- __export(MaybeArray_exports, {
20
- arrayOfMaybeArray: () => arrayOfMaybeArray,
21
- firstOfMaybeArray: () => firstOfMaybeArray,
22
- lastOfMaybeArray: () => lastOfMaybeArray,
23
- objectOfMaybeArray: () => objectOfMaybeArray
24
- });
25
- module.exports = __toCommonJS(MaybeArray_exports);
26
- function objectOfMaybeArray(o, keys = null, picker = firstOfMaybeArray) {
27
- if (keys === null) {
28
- return Object.fromEntries(Object.entries(o).map(([k, v]) => [k, picker(v)]));
29
- }
30
- return Object.fromEntries(keys.map((v) => [v, picker(v)]));
31
- }
32
- function firstOfMaybeArray(v) {
33
- if (Array.isArray(v)) {
34
- return v[0];
35
- }
36
- return v;
37
- }
38
- function lastOfMaybeArray(v) {
39
- if (Array.isArray(v)) {
40
- return v[v.length - 1];
41
- }
42
- return v;
43
- }
44
- function arrayOfMaybeArray(v) {
45
- if (Array.isArray(v)) {
46
- return v;
47
- }
48
- if (v === null || v === void 0) {
49
- return [];
50
- }
51
- return [v];
52
- }