@wener/utils 1.1.0 → 1.1.1

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 (231) hide show
  1. package/README.md +5 -3
  2. package/lib/cjs/arrays/MaybeArray.js +44 -27
  3. package/lib/cjs/arrays/index.js +17 -5
  4. package/lib/cjs/asyncs/AsyncInterval.js +31 -14
  5. package/lib/cjs/asyncs/LazyPromise.js +41 -24
  6. package/lib/cjs/asyncs/MaybePromise.js +15 -3
  7. package/lib/cjs/asyncs/generatorOfStream.js +32 -15
  8. package/lib/cjs/asyncs/index.js +23 -11
  9. package/lib/cjs/asyncs/isPromise.js +23 -6
  10. package/lib/cjs/asyncs/promiseOfCallback.js +34 -19
  11. package/lib/cjs/asyncs/sleep.js +22 -5
  12. package/lib/cjs/asyncs/timeout.js +40 -23
  13. package/lib/cjs/browsers/copy.js +65 -49
  14. package/lib/cjs/browsers/download.js +44 -32
  15. package/lib/cjs/browsers/getFileFromDataTransfer.js +44 -37
  16. package/lib/cjs/browsers/index.js +20 -8
  17. package/lib/cjs/browsers/loaders.js +48 -32
  18. package/lib/cjs/formats/formatBytes.js +34 -29
  19. package/lib/cjs/index.js +35 -15
  20. package/lib/cjs/io/index.js +17 -5
  21. package/lib/cjs/io/isBuffer.js +23 -10
  22. package/lib/cjs/isomorphics/getGlobalThis.js +31 -23
  23. package/lib/cjs/maths/index.js +17 -5
  24. package/lib/cjs/maths/random.js +33 -17
  25. package/lib/cjs/shim/urljoin.js +70 -0
  26. package/lib/cjs/shim/urljoin.test.js +4 -0
  27. package/lib/cjs/strings/camelCase.js +68 -65
  28. package/lib/cjs/strings/index.js +18 -7
  29. package/lib/cjs/strings/templates.js +25 -16
  30. package/lib/cjs/validations/asserts.js +25 -14
  31. package/lib/cjs/validations/index.js +20 -8
  32. package/lib/cjs/validations/isClass.js +23 -6
  33. package/lib/cjs/validations/isDefined.js +23 -6
  34. package/lib/cjs/validations/isEmptyObject.js +26 -9
  35. package/lib/esm/index.d.ts +2 -1
  36. package/lib/esm/index.js +5 -2
  37. package/lib/esm/shim/urljoin.d.ts +2 -0
  38. package/lib/esm/{strings → shim}/urljoin.js +3 -5
  39. package/lib/{cjs/strings → esm/shim}/urljoin.test.d.ts +0 -0
  40. package/lib/esm/{strings → shim}/urljoin.test.js +0 -0
  41. package/lib/esm/strings/index.d.ts +0 -1
  42. package/lib/esm/strings/index.js +0 -1
  43. package/package.json +3 -3
  44. package/src/index.ts +2 -1
  45. package/src/{strings → shim}/urljoin.test.ts +0 -0
  46. package/src/{strings → shim}/urljoin.ts +6 -10
  47. package/src/strings/index.ts +0 -1
  48. package/tsconfig.json +1 -1
  49. package/dist/utils.cjs +0 -497
  50. package/dist/utils.cjs.map +0 -7
  51. package/dist/utils.js +0 -445
  52. package/dist/utils.js.map +0 -7
  53. package/dist/utils.mjs +0 -475
  54. package/dist/utils.mjs.map +0 -7
  55. package/lib/cjs/arrays/MaybeArray.d.ts +0 -5
  56. package/lib/cjs/arrays/MaybeArray.js.map +0 -1
  57. package/lib/cjs/arrays/index.d.ts +0 -1
  58. package/lib/cjs/arrays/index.js.map +0 -1
  59. package/lib/cjs/asyncs/AsyncInterval.d.ts +0 -3
  60. package/lib/cjs/asyncs/AsyncInterval.js.map +0 -1
  61. package/lib/cjs/asyncs/LazyPromise.d.ts +0 -5
  62. package/lib/cjs/asyncs/LazyPromise.js.map +0 -1
  63. package/lib/cjs/asyncs/MaybePromise.d.ts +0 -1
  64. package/lib/cjs/asyncs/MaybePromise.js.map +0 -1
  65. package/lib/cjs/asyncs/generatorOfStream.d.ts +0 -1
  66. package/lib/cjs/asyncs/generatorOfStream.js.map +0 -1
  67. package/lib/cjs/asyncs/index.d.ts +0 -7
  68. package/lib/cjs/asyncs/index.js.map +0 -1
  69. package/lib/cjs/asyncs/isPromise.d.ts +0 -1
  70. package/lib/cjs/asyncs/isPromise.js.map +0 -1
  71. package/lib/cjs/asyncs/promiseOfCallback.d.ts +0 -1
  72. package/lib/cjs/asyncs/promiseOfCallback.js.map +0 -1
  73. package/lib/cjs/asyncs/sleep.d.ts +0 -1
  74. package/lib/cjs/asyncs/sleep.js.map +0 -1
  75. package/lib/cjs/asyncs/timeout.d.ts +0 -4
  76. package/lib/cjs/asyncs/timeout.js.map +0 -1
  77. package/lib/cjs/browsers/copy.d.ts +0 -1
  78. package/lib/cjs/browsers/copy.js.map +0 -1
  79. package/lib/cjs/browsers/download.d.ts +0 -4
  80. package/lib/cjs/browsers/download.js.map +0 -1
  81. package/lib/cjs/browsers/getFileFromDataTransfer.d.ts +0 -4
  82. package/lib/cjs/browsers/getFileFromDataTransfer.js.map +0 -1
  83. package/lib/cjs/browsers/index.d.ts +0 -4
  84. package/lib/cjs/browsers/index.js.map +0 -1
  85. package/lib/cjs/browsers/loaders.d.ts +0 -6
  86. package/lib/cjs/browsers/loaders.js.map +0 -1
  87. package/lib/cjs/formats/formatBytes.d.ts +0 -11
  88. package/lib/cjs/formats/formatBytes.js.map +0 -1
  89. package/lib/cjs/index.d.ts +0 -9
  90. package/lib/cjs/index.js.map +0 -1
  91. package/lib/cjs/io/index.d.ts +0 -1
  92. package/lib/cjs/io/index.js.map +0 -1
  93. package/lib/cjs/io/isBuffer.d.ts +0 -2
  94. package/lib/cjs/io/isBuffer.js.map +0 -1
  95. package/lib/cjs/isomorphics/getGlobalThis.d.ts +0 -9
  96. package/lib/cjs/isomorphics/getGlobalThis.js.map +0 -1
  97. package/lib/cjs/isomorphics/index.d.ts +0 -1
  98. package/lib/cjs/isomorphics/index.js +0 -5
  99. package/lib/cjs/isomorphics/index.js.map +0 -1
  100. package/lib/cjs/maths/index.d.ts +0 -1
  101. package/lib/cjs/maths/index.js.map +0 -1
  102. package/lib/cjs/maths/random.d.ts +0 -3
  103. package/lib/cjs/maths/random.js.map +0 -1
  104. package/lib/cjs/strings/camelCase.d.ts +0 -4
  105. package/lib/cjs/strings/camelCase.js.map +0 -1
  106. package/lib/cjs/strings/index.d.ts +0 -3
  107. package/lib/cjs/strings/index.js.map +0 -1
  108. package/lib/cjs/strings/templates.d.ts +0 -7
  109. package/lib/cjs/strings/templates.js.map +0 -1
  110. package/lib/cjs/strings/urljoin.d.ts +0 -2
  111. package/lib/cjs/strings/urljoin.js +0 -69
  112. package/lib/cjs/strings/urljoin.js.map +0 -1
  113. package/lib/cjs/strings/urljoin.test.js +0 -7
  114. package/lib/cjs/strings/urljoin.test.js.map +0 -1
  115. package/lib/cjs/validations/asserts.d.ts +0 -2
  116. package/lib/cjs/validations/asserts.js.map +0 -1
  117. package/lib/cjs/validations/index.d.ts +0 -4
  118. package/lib/cjs/validations/index.js.map +0 -1
  119. package/lib/cjs/validations/isClass.d.ts +0 -1
  120. package/lib/cjs/validations/isClass.js.map +0 -1
  121. package/lib/cjs/validations/isDefined.d.ts +0 -1
  122. package/lib/cjs/validations/isDefined.js.map +0 -1
  123. package/lib/cjs/validations/isEmptyObject.d.ts +0 -1
  124. package/lib/cjs/validations/isEmptyObject.js.map +0 -1
  125. package/lib/esm/isomorphics/index.d.ts +0 -1
  126. package/lib/esm/isomorphics/index.js +0 -1
  127. package/lib/esm/strings/urljoin.d.ts +0 -2
  128. package/lib/esm/strings/urljoin.test.d.ts +0 -1
  129. package/lib/esnext/arrays/MaybeArray.d.ts +0 -5
  130. package/lib/esnext/arrays/MaybeArray.js +0 -28
  131. package/lib/esnext/arrays/MaybeArray.js.map +0 -1
  132. package/lib/esnext/arrays/index.d.ts +0 -1
  133. package/lib/esnext/arrays/index.js +0 -2
  134. package/lib/esnext/arrays/index.js.map +0 -1
  135. package/lib/esnext/asyncs/AsyncInterval.d.ts +0 -3
  136. package/lib/esnext/asyncs/AsyncInterval.js +0 -13
  137. package/lib/esnext/asyncs/AsyncInterval.js.map +0 -1
  138. package/lib/esnext/asyncs/LazyPromise.d.ts +0 -5
  139. package/lib/esnext/asyncs/LazyPromise.js +0 -22
  140. package/lib/esnext/asyncs/LazyPromise.js.map +0 -1
  141. package/lib/esnext/asyncs/MaybePromise.d.ts +0 -1
  142. package/lib/esnext/asyncs/MaybePromise.js +0 -2
  143. package/lib/esnext/asyncs/MaybePromise.js.map +0 -1
  144. package/lib/esnext/asyncs/generatorOfStream.d.ts +0 -1
  145. package/lib/esnext/asyncs/generatorOfStream.js +0 -14
  146. package/lib/esnext/asyncs/generatorOfStream.js.map +0 -1
  147. package/lib/esnext/asyncs/index.d.ts +0 -7
  148. package/lib/esnext/asyncs/index.js +0 -8
  149. package/lib/esnext/asyncs/index.js.map +0 -1
  150. package/lib/esnext/asyncs/isPromise.d.ts +0 -1
  151. package/lib/esnext/asyncs/isPromise.js +0 -4
  152. package/lib/esnext/asyncs/isPromise.js.map +0 -1
  153. package/lib/esnext/asyncs/promiseOfCallback.d.ts +0 -1
  154. package/lib/esnext/asyncs/promiseOfCallback.js +0 -18
  155. package/lib/esnext/asyncs/promiseOfCallback.js.map +0 -1
  156. package/lib/esnext/asyncs/sleep.d.ts +0 -1
  157. package/lib/esnext/asyncs/sleep.js +0 -2
  158. package/lib/esnext/asyncs/sleep.js.map +0 -1
  159. package/lib/esnext/asyncs/timeout.d.ts +0 -4
  160. package/lib/esnext/asyncs/timeout.js +0 -22
  161. package/lib/esnext/asyncs/timeout.js.map +0 -1
  162. package/lib/esnext/browsers/copy.d.ts +0 -1
  163. package/lib/esnext/browsers/copy.js +0 -51
  164. package/lib/esnext/browsers/copy.js.map +0 -1
  165. package/lib/esnext/browsers/download.d.ts +0 -4
  166. package/lib/esnext/browsers/download.js +0 -31
  167. package/lib/esnext/browsers/download.js.map +0 -1
  168. package/lib/esnext/browsers/getFileFromDataTransfer.d.ts +0 -4
  169. package/lib/esnext/browsers/getFileFromDataTransfer.js +0 -37
  170. package/lib/esnext/browsers/getFileFromDataTransfer.js.map +0 -1
  171. package/lib/esnext/browsers/index.d.ts +0 -4
  172. package/lib/esnext/browsers/index.js +0 -5
  173. package/lib/esnext/browsers/index.js.map +0 -1
  174. package/lib/esnext/browsers/loaders.d.ts +0 -6
  175. package/lib/esnext/browsers/loaders.js +0 -33
  176. package/lib/esnext/browsers/loaders.js.map +0 -1
  177. package/lib/esnext/formats/formatBytes.d.ts +0 -11
  178. package/lib/esnext/formats/formatBytes.js +0 -27
  179. package/lib/esnext/formats/formatBytes.js.map +0 -1
  180. package/lib/esnext/index.d.ts +0 -9
  181. package/lib/esnext/index.js +0 -10
  182. package/lib/esnext/index.js.map +0 -1
  183. package/lib/esnext/io/index.d.ts +0 -1
  184. package/lib/esnext/io/index.js +0 -2
  185. package/lib/esnext/io/index.js.map +0 -1
  186. package/lib/esnext/io/isBuffer.d.ts +0 -2
  187. package/lib/esnext/io/isBuffer.js +0 -8
  188. package/lib/esnext/io/isBuffer.js.map +0 -1
  189. package/lib/esnext/isomorphics/getGlobalThis.d.ts +0 -9
  190. package/lib/esnext/isomorphics/getGlobalThis.js +0 -21
  191. package/lib/esnext/isomorphics/getGlobalThis.js.map +0 -1
  192. package/lib/esnext/isomorphics/index.d.ts +0 -1
  193. package/lib/esnext/isomorphics/index.js +0 -2
  194. package/lib/esnext/isomorphics/index.js.map +0 -1
  195. package/lib/esnext/maths/index.d.ts +0 -1
  196. package/lib/esnext/maths/index.js +0 -2
  197. package/lib/esnext/maths/index.js.map +0 -1
  198. package/lib/esnext/maths/random.d.ts +0 -3
  199. package/lib/esnext/maths/random.js +0 -16
  200. package/lib/esnext/maths/random.js.map +0 -1
  201. package/lib/esnext/strings/camelCase.d.ts +0 -4
  202. package/lib/esnext/strings/camelCase.js +0 -68
  203. package/lib/esnext/strings/camelCase.js.map +0 -1
  204. package/lib/esnext/strings/index.d.ts +0 -3
  205. package/lib/esnext/strings/index.js +0 -4
  206. package/lib/esnext/strings/index.js.map +0 -1
  207. package/lib/esnext/strings/templates.d.ts +0 -7
  208. package/lib/esnext/strings/templates.js +0 -14
  209. package/lib/esnext/strings/templates.js.map +0 -1
  210. package/lib/esnext/strings/urljoin.d.ts +0 -2
  211. package/lib/esnext/strings/urljoin.js +0 -65
  212. package/lib/esnext/strings/urljoin.js.map +0 -1
  213. package/lib/esnext/strings/urljoin.test.d.ts +0 -1
  214. package/lib/esnext/strings/urljoin.test.js +0 -5
  215. package/lib/esnext/strings/urljoin.test.js.map +0 -1
  216. package/lib/esnext/validations/asserts.d.ts +0 -2
  217. package/lib/esnext/validations/asserts.js +0 -13
  218. package/lib/esnext/validations/asserts.js.map +0 -1
  219. package/lib/esnext/validations/index.d.ts +0 -4
  220. package/lib/esnext/validations/index.js +0 -5
  221. package/lib/esnext/validations/index.js.map +0 -1
  222. package/lib/esnext/validations/isClass.d.ts +0 -1
  223. package/lib/esnext/validations/isClass.js +0 -4
  224. package/lib/esnext/validations/isClass.js.map +0 -1
  225. package/lib/esnext/validations/isDefined.d.ts +0 -1
  226. package/lib/esnext/validations/isDefined.js +0 -4
  227. package/lib/esnext/validations/isDefined.js.map +0 -1
  228. package/lib/esnext/validations/isEmptyObject.d.ts +0 -1
  229. package/lib/esnext/validations/isEmptyObject.js +0 -7
  230. package/lib/esnext/validations/isEmptyObject.js.map +0 -1
  231. package/src/isomorphics/index.ts +0 -1
@@ -1,5 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./random"), exports);
5
- //# sourceMappingURL=index.js.map
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var maths_exports = {};
16
+ module.exports = __toCommonJS(maths_exports);
17
+ __reExport(maths_exports, require("./random"), module.exports);
@@ -1,20 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRandom = void 0;
4
- /// javascript pseudo random
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 random_exports = {};
19
+ __export(random_exports, {
20
+ createRandom: () => createRandom
21
+ });
22
+ module.exports = __toCommonJS(random_exports);
5
23
  function createRandom(o = {}) {
6
- let seed = typeof o.seed === 'string' ? 0 : o.seed ?? 0;
7
- if (typeof o.seed === 'string') {
8
- let sum = 0;
9
- for (let i = 0; i < o.seed.length; i++) {
10
- sum += o.seed.charCodeAt(i);
11
- }
12
- seed = sum;
24
+ let seed = typeof o.seed === "string" ? 0 : o.seed ?? 0;
25
+ if (typeof o.seed === "string") {
26
+ let sum = 0;
27
+ for (let i = 0; i < o.seed.length; i++) {
28
+ sum += o.seed.charCodeAt(i);
13
29
  }
14
- return () => {
15
- const x = Math.sin(seed++) * 10000;
16
- return x - Math.floor(x);
17
- };
30
+ seed = sum;
31
+ }
32
+ return () => {
33
+ const x = Math.sin(seed++) * 1e4;
34
+ return x - Math.floor(x);
35
+ };
18
36
  }
19
- exports.createRandom = createRandom;
20
- //# sourceMappingURL=random.js.map
@@ -0,0 +1,70 @@
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 urljoin_exports = {};
19
+ __export(urljoin_exports, {
20
+ urljoin: () => urljoin
21
+ });
22
+ module.exports = __toCommonJS(urljoin_exports);
23
+ function urljoin(...args) {
24
+ if (Array.isArray(args[0])) {
25
+ return normalize(args[0]);
26
+ } else {
27
+ return normalize(args);
28
+ }
29
+ }
30
+ function normalize(strArray) {
31
+ const resultArray = [];
32
+ if (strArray.length === 0) {
33
+ return "";
34
+ }
35
+ if (typeof strArray[0] !== "string") {
36
+ throw new TypeError("Url must be a string. Received " + strArray[0]);
37
+ }
38
+ if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
39
+ const first = strArray.shift();
40
+ strArray[0] = first + strArray[0];
41
+ }
42
+ if (strArray[0].match(/^file:\/\/\//)) {
43
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
44
+ } else {
45
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
46
+ }
47
+ for (let i = 0; i < strArray.length; i++) {
48
+ let component = strArray[i];
49
+ if (typeof component !== "string") {
50
+ throw new TypeError("Url must be a string. Received " + component);
51
+ }
52
+ if (component === "") {
53
+ continue;
54
+ }
55
+ if (i > 0) {
56
+ component = component.replace(/^[\/]+/, "");
57
+ }
58
+ if (i < strArray.length - 1) {
59
+ component = component.replace(/[\/]+$/, "");
60
+ } else {
61
+ component = component.replace(/[\/]+$/, "/");
62
+ }
63
+ resultArray.push(component);
64
+ }
65
+ let str = resultArray.join("/");
66
+ str = str.replace(/\/(\?|&|#[^!])/g, "$1");
67
+ const parts = str.split("?");
68
+ str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&");
69
+ return str;
70
+ }
@@ -0,0 +1,4 @@
1
+ var import_urljoin = require("./urljoin");
2
+ test("join ext", () => {
3
+ expect((0, import_urljoin.urljoin)("http://wener.me/sub/", "/a/", "/hello.js")).toBe("http://wener.me/sub/a/hello.js");
4
+ });
@@ -1,73 +1,76 @@
1
- "use strict";
2
- // https://github.com/sindresorhus/camelcase/blob/master/index.js
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.camelCase = exports.pascalCase = void 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 camelCase_exports = {};
19
+ __export(camelCase_exports, {
20
+ camelCase: () => camelCase,
21
+ pascalCase: () => pascalCase
22
+ });
23
+ module.exports = __toCommonJS(camelCase_exports);
5
24
  function preserveCamelCase(string) {
6
- let isLastCharLower = false;
7
- let isLastCharUpper = false;
8
- let isLastLastCharUpper = false;
9
- for (let i = 0; i < string.length; i++) {
10
- const character = string[i];
11
- if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {
12
- string = string.slice(0, i) + '-' + string.slice(i);
13
- isLastCharLower = false;
14
- isLastLastCharUpper = isLastCharUpper;
15
- isLastCharUpper = true;
16
- i++;
17
- }
18
- else if (isLastCharUpper &&
19
- isLastLastCharUpper &&
20
- /[a-zA-Z]/.test(character) &&
21
- character.toLowerCase() === character) {
22
- string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
23
- isLastLastCharUpper = isLastCharUpper;
24
- isLastCharUpper = false;
25
- isLastCharLower = true;
26
- }
27
- else {
28
- isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
29
- isLastLastCharUpper = isLastCharUpper;
30
- isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
31
- }
25
+ let isLastCharLower = false;
26
+ let isLastCharUpper = false;
27
+ let isLastLastCharUpper = false;
28
+ for (let i = 0; i < string.length; i++) {
29
+ const character = string[i];
30
+ if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {
31
+ string = string.slice(0, i) + "-" + string.slice(i);
32
+ isLastCharLower = false;
33
+ isLastLastCharUpper = isLastCharUpper;
34
+ isLastCharUpper = true;
35
+ i++;
36
+ } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(character) && character.toLowerCase() === character) {
37
+ string = string.slice(0, i - 1) + "-" + string.slice(i - 1);
38
+ isLastLastCharUpper = isLastCharUpper;
39
+ isLastCharUpper = false;
40
+ isLastCharLower = true;
41
+ } else {
42
+ isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
43
+ isLastLastCharUpper = isLastCharUpper;
44
+ isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
32
45
  }
33
- return string;
46
+ }
47
+ return string;
34
48
  }
35
49
  function pascalCase(input) {
36
- return camelCase(input, { pascalCase: true });
50
+ return camelCase(input, { pascalCase: true });
37
51
  }
38
- exports.pascalCase = pascalCase;
39
52
  function camelCase(input, options = {
40
- pascalCase: false,
53
+ pascalCase: false
41
54
  }) {
42
- if (!(typeof input === 'string' || Array.isArray(input))) {
43
- throw new TypeError('Expected the input to be `string | string[]`');
44
- }
45
- const postProcess = (x) => (options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x);
46
- if (Array.isArray(input)) {
47
- input = input
48
- .map((x) => x.trim())
49
- .filter((x) => x.length)
50
- .join('-');
51
- }
52
- else {
53
- input = input.trim();
54
- }
55
- if (input.length === 0) {
56
- return '';
57
- }
58
- if (input.length === 1) {
59
- return options.pascalCase ? input.toUpperCase() : input.toLowerCase();
60
- }
61
- const hasUpperCase = input !== input.toLowerCase();
62
- if (hasUpperCase) {
63
- input = preserveCamelCase(input);
64
- }
65
- input = input
66
- .replace(/^[_.\- ]+/, '')
67
- .toLowerCase()
68
- .replace(/[_.\- ]+(\w|$)/g, (_, p1) => p1.toUpperCase())
69
- .replace(/\d+(\w|$)/g, (m) => m.toUpperCase());
70
- return postProcess(input);
55
+ if (!(typeof input === "string" || Array.isArray(input))) {
56
+ throw new TypeError("Expected the input to be `string | string[]`");
57
+ }
58
+ const postProcess = (x) => options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x;
59
+ if (Array.isArray(input)) {
60
+ input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
61
+ } else {
62
+ input = input.trim();
63
+ }
64
+ if (input.length === 0) {
65
+ return "";
66
+ }
67
+ if (input.length === 1) {
68
+ return options.pascalCase ? input.toUpperCase() : input.toLowerCase();
69
+ }
70
+ const hasUpperCase = input !== input.toLowerCase();
71
+ if (hasUpperCase) {
72
+ input = preserveCamelCase(input);
73
+ }
74
+ input = input.replace(/^[_.\- ]+/, "").toLowerCase().replace(/[_.\- ]+(\w|$)/g, (_, p1) => p1.toUpperCase()).replace(/\d+(\w|$)/g, (m) => m.toUpperCase());
75
+ return postProcess(input);
71
76
  }
72
- exports.camelCase = camelCase;
73
- //# sourceMappingURL=camelCase.js.map
@@ -1,7 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./camelCase"), exports);
5
- tslib_1.__exportStar(require("./templates"), exports);
6
- tslib_1.__exportStar(require("./urljoin"), exports);
7
- //# sourceMappingURL=index.js.map
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var strings_exports = {};
16
+ module.exports = __toCommonJS(strings_exports);
17
+ __reExport(strings_exports, require("./camelCase"), module.exports);
18
+ __reExport(strings_exports, require("./templates"), module.exports);
@@ -1,18 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.templateString = void 0;
4
- /**
5
- * 替换类似于 JS 的模板字符串
6
- *
7
- * @example
8
- * templateString('My name is ${name}',{name:'wener'})
9
- */
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 templates_exports = {};
19
+ __export(templates_exports, {
20
+ templateString: () => templateString
21
+ });
22
+ module.exports = __toCommonJS(templates_exports);
10
23
  function templateString(template, getter) {
11
- return template.replace(/\${(.*?)}/g, (_, g) => {
12
- // variables[g.trim()]
13
- // 支持路径 - 例如 a.b[0]
14
- return getter(g.trim());
15
- });
24
+ return template.replace(/\${(.*?)}/g, (_, g) => {
25
+ return getter(g.trim());
26
+ });
16
27
  }
17
- exports.templateString = templateString;
18
- //# sourceMappingURL=templates.js.map
@@ -1,18 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertIsDefined = exports.assert = void 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 asserts_exports = {};
19
+ __export(asserts_exports, {
20
+ assert: () => assert,
21
+ assertIsDefined: () => assertIsDefined
22
+ });
23
+ module.exports = __toCommonJS(asserts_exports);
4
24
  function assert(condition, msg) {
5
- // if (!condition) {
6
- // throw new AssertionError(msg);
7
- // }
8
- console.assert(!condition, msg);
25
+ console.assert(!condition, msg);
9
26
  }
10
- exports.assert = assert;
11
27
  function assertIsDefined(val) {
12
- // if (val === undefined || val === null) {
13
- // throw new AssertionError(`Expected 'val' to be defined, but received ${val}`);
14
- // }
15
- console.assert(val === undefined || val === null, 'Expected defined');
28
+ console.assert(val === void 0 || val === null, "Expected defined");
16
29
  }
17
- exports.assertIsDefined = assertIsDefined;
18
- //# sourceMappingURL=asserts.js.map
@@ -1,8 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./asserts"), exports);
5
- tslib_1.__exportStar(require("./isDefined"), exports);
6
- tslib_1.__exportStar(require("./isEmptyObject"), exports);
7
- tslib_1.__exportStar(require("./isClass"), exports);
8
- //# sourceMappingURL=index.js.map
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var validations_exports = {};
16
+ module.exports = __toCommonJS(validations_exports);
17
+ __reExport(validations_exports, require("./asserts"), module.exports);
18
+ __reExport(validations_exports, require("./isDefined"), module.exports);
19
+ __reExport(validations_exports, require("./isEmptyObject"), module.exports);
20
+ __reExport(validations_exports, require("./isClass"), module.exports);
@@ -1,8 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isClass = void 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 isClass_exports = {};
19
+ __export(isClass_exports, {
20
+ isClass: () => isClass
21
+ });
22
+ module.exports = __toCommonJS(isClass_exports);
4
23
  function isClass(func) {
5
- return typeof func === 'function' && /^class\s/.test(Function.prototype.toString.call(func));
24
+ return typeof func === "function" && /^class\s/.test(Function.prototype.toString.call(func));
6
25
  }
7
- exports.isClass = isClass;
8
- //# sourceMappingURL=isClass.js.map
@@ -1,8 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDefined = void 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 isDefined_exports = {};
19
+ __export(isDefined_exports, {
20
+ isDefined: () => isDefined
21
+ });
22
+ module.exports = __toCommonJS(isDefined_exports);
4
23
  function isDefined(v) {
5
- return v !== null && v !== undefined;
24
+ return v !== null && v !== void 0;
6
25
  }
7
- exports.isDefined = isDefined;
8
- //# sourceMappingURL=isDefined.js.map
@@ -1,11 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEmptyObject = void 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 isEmptyObject_exports = {};
19
+ __export(isEmptyObject_exports, {
20
+ isEmptyObject: () => isEmptyObject
21
+ });
22
+ module.exports = __toCommonJS(isEmptyObject_exports);
4
23
  function isEmptyObject(o) {
5
- if (o === null || o === undefined) {
6
- return true;
7
- }
8
- return o.constructor === Object && Object.keys(o).length === 0;
24
+ if (o === null || o === void 0) {
25
+ return true;
26
+ }
27
+ return o.constructor === Object && Object.keys(o).length === 0;
9
28
  }
10
- exports.isEmptyObject = isEmptyObject;
11
- //# sourceMappingURL=isEmptyObject.js.map
@@ -5,5 +5,6 @@ export * from './strings';
5
5
  export * from './maths';
6
6
  export * from './io';
7
7
  export * from './browsers';
8
- export * from './isomorphics';
8
+ export { getGlobalThis } from './isomorphics/getGlobalThis';
9
9
  export { formatBytes } from './formats/formatBytes';
10
+ export { urljoin } from './shim/urljoin';
package/lib/esm/index.js CHANGED
@@ -5,8 +5,11 @@ export * from "./strings";
5
5
  export * from "./maths";
6
6
  export * from "./io";
7
7
  export * from "./browsers";
8
- export * from "./isomorphics";
8
+ import { getGlobalThis } from "./isomorphics/getGlobalThis";
9
9
  import { formatBytes } from "./formats/formatBytes";
10
+ import { urljoin } from "./shim/urljoin";
10
11
  export {
11
- formatBytes
12
+ formatBytes,
13
+ getGlobalThis,
14
+ urljoin
12
15
  };
@@ -0,0 +1,2 @@
1
+ export declare function urljoin(...strArray: string[]): string;
2
+ export declare function urljoin(strArray: string[]): string;
@@ -1,11 +1,9 @@
1
1
  function urljoin(...args) {
2
- let input;
3
- if (typeof args[0] === "object") {
4
- input = args[0];
2
+ if (Array.isArray(args[0])) {
3
+ return normalize(args[0]);
5
4
  } else {
6
- input = args;
5
+ return normalize(args);
7
6
  }
8
- return normalize(input);
9
7
  }
10
8
  function normalize(strArray) {
11
9
  const resultArray = [];
File without changes
File without changes
@@ -1,3 +1,2 @@
1
1
  export * from './camelCase';
2
2
  export * from './templates';
3
- export * from './urljoin';
@@ -1,3 +1,2 @@
1
1
  export * from "./camelCase";
2
2
  export * from "./templates";
3
- export * from "./urljoin";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Utils for daily use",
5
5
  "keywords": [
6
6
  "utils",
@@ -43,13 +43,13 @@
43
43
  "tsconfig.json"
44
44
  ],
45
45
  "scripts": {
46
- "build": "make build",
46
+ "build": "make prepublish",
47
47
  "clean": "make clean",
48
48
  "dev": "make dev",
49
49
  "test": "jest"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/jest": "^27",
52
+ "@types/jest": "^28",
53
53
  "@types/lodash": "^4",
54
54
  "@types/node": "^16",
55
55
  "dotenv": "^16",
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from './strings';
5
5
  export * from './maths';
6
6
  export * from './io';
7
7
  export * from './browsers';
8
- export * from './isomorphics';
9
8
 
9
+ export { getGlobalThis } from './isomorphics/getGlobalThis';
10
10
  export { formatBytes } from './formats/formatBytes';
11
+ export { urljoin } from './shim/urljoin';
File without changes