@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
@@ -1,52 +0,0 @@
1
- let _copy;
2
- function initCopy() {
3
- let textArea;
4
- function isIOS() {
5
- return navigator.userAgent.match(/ipad|iphone/i);
6
- }
7
- function createTextArea(text) {
8
- textArea = document.createElement("textArea");
9
- textArea.value = text;
10
- document.body.appendChild(textArea);
11
- }
12
- function selectText() {
13
- let range, selection;
14
- if (isIOS()) {
15
- range = document.createRange();
16
- range.selectNodeContents(textArea);
17
- selection = window.getSelection();
18
- if (selection === null) {
19
- console.error(`no selection`);
20
- return;
21
- }
22
- selection.removeAllRanges();
23
- selection.addRange(range);
24
- textArea.setSelectionRange(0, 999999);
25
- } else {
26
- textArea.select();
27
- }
28
- }
29
- function copyToClipboard() {
30
- document.execCommand("copy");
31
- document.body.removeChild(textArea);
32
- }
33
- _copy = (text) => {
34
- createTextArea(text);
35
- selectText();
36
- copyToClipboard();
37
- };
38
- }
39
- function copy(text) {
40
- var _a, _b;
41
- if ((_b = (_a = window.navigator) == null ? void 0 : _a.clipboard) == null ? void 0 : _b.writeText) {
42
- window.navigator.clipboard.writeText(text);
43
- return;
44
- }
45
- if (!_copy) {
46
- initCopy();
47
- }
48
- _copy(text);
49
- }
50
- export {
51
- copy
52
- };
@@ -1,4 +0,0 @@
1
- export declare function download(filename: string, data: any, { type, raw }?: {
2
- type?: string | undefined;
3
- raw?: boolean | undefined;
4
- }): void;
@@ -1,28 +0,0 @@
1
- function download(filename, data, { type = "application/octet-stream", raw = false } = {}) {
2
- const a = document.createElement("a");
3
- let closer = () => null;
4
- try {
5
- a.download = filename;
6
- if (typeof data === "string" && /^(https?:|data:)/.test(data) && !raw) {
7
- a.href = data;
8
- } else if (typeof data === "string") {
9
- data = new TextEncoder().encode(data);
10
- }
11
- if (data instanceof Uint8Array) {
12
- data = new Blob([data], { type });
13
- }
14
- if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
15
- a.href = URL.createObjectURL(data);
16
- closer = () => URL.revokeObjectURL(a.href);
17
- } else {
18
- console.error(`invalid download data`, data);
19
- throw new Error(`can not download ${Object.getPrototypeOf(data)}`);
20
- }
21
- a.click();
22
- } finally {
23
- closer();
24
- }
25
- }
26
- export {
27
- download
28
- };
@@ -1,4 +0,0 @@
1
- export declare function getFileFromDataTransfer(dataTransfer?: DataTransfer | null): {
2
- file?: File;
3
- name?: string;
4
- };
@@ -1,29 +0,0 @@
1
- function getFileFromDataTransfer(dataTransfer) {
2
- var _a;
3
- if (!dataTransfer) {
4
- return {};
5
- }
6
- const items = dataTransfer.items ?? [];
7
- if (items.length >= 2 && items[0].kind === "string" && items[1].kind === "file") {
8
- const text = dataTransfer.getData("text");
9
- const file = items[1].getAsFile() ?? ((_a = dataTransfer.files) == null ? void 0 : _a.item(0));
10
- if (!file) {
11
- console.error(`no file ${text}`, items[1]);
12
- return {};
13
- }
14
- return { file, name: text };
15
- } else if (items[0].kind === "file") {
16
- const file = items[0].getAsFile();
17
- if (!file) {
18
- console.error(`no file`, items[0]);
19
- return {};
20
- }
21
- return { file, name: file.name };
22
- } else {
23
- console.debug(`file item not match`, Array.from(items).map((v) => ({ type: v.type, kind: v.kind })));
24
- }
25
- return {};
26
- }
27
- export {
28
- getFileFromDataTransfer
29
- };
@@ -1,4 +0,0 @@
1
- export * from './copy';
2
- export * from './download';
3
- export * from './loaders';
4
- export * from './getFileFromDataTransfer';
@@ -1,4 +0,0 @@
1
- export * from "./copy";
2
- export * from "./download";
3
- export * from "./loaders";
4
- export * from "./getFileFromDataTransfer";
@@ -1,6 +0,0 @@
1
- export declare function loadScripts(src: string, options?: {
2
- attributes: Record<string, string>;
3
- }): Promise<unknown>;
4
- export declare function loadStyles(href: string, options?: {
5
- attributes: Record<string, string>;
6
- }): Promise<unknown>;
@@ -1,35 +0,0 @@
1
- function load(el, resolve, reject, options) {
2
- el.onload = resolve;
3
- el.onerror = (e) => {
4
- el.remove();
5
- reject(e);
6
- };
7
- const { attributes = {} } = options || {};
8
- Object.entries(attributes).forEach(([k, v]) => el.setAttribute(k, v));
9
- document.head.appendChild(el);
10
- }
11
- function loadScripts(src, options) {
12
- if (document.querySelector(`script[src="${src}"]`)) {
13
- return Promise.resolve();
14
- }
15
- return new Promise((resolve, reject) => {
16
- const el = document.createElement("script");
17
- el.src = src;
18
- load(el, resolve, reject, options);
19
- });
20
- }
21
- function loadStyles(href, options) {
22
- if (document.querySelector(`link[href="${href}"]`)) {
23
- return Promise.resolve();
24
- }
25
- return new Promise((resolve, reject) => {
26
- const el = document.createElement("link");
27
- el.rel = "stylesheet";
28
- el.href = href;
29
- load(el, resolve, reject, options);
30
- });
31
- }
32
- export {
33
- loadScripts,
34
- loadStyles
35
- };
@@ -1,11 +0,0 @@
1
- /**
2
- * Format bytes as human-readable text.
3
- *
4
- * @param bytes Number of bytes.
5
- * @param si True to use metric (SI) units, aka powers of 1000. False to use
6
- * binary (IEC), aka powers of 1024.
7
- * @param dp Number of decimal places to display.
8
- *
9
- * @return Formatted string.
10
- */
11
- export declare function formatBytes(bytes: number, si?: boolean, dp?: number): string;
@@ -1,17 +0,0 @@
1
- function formatBytes(bytes, si = false, dp = 1) {
2
- const thresh = si ? 1e3 : 1024;
3
- if (Math.abs(bytes) < thresh) {
4
- return bytes + " B";
5
- }
6
- const units = si ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
7
- let u = -1;
8
- const r = 10 ** dp;
9
- do {
10
- bytes /= thresh;
11
- ++u;
12
- } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
13
- return bytes.toFixed(dp) + " " + units[u];
14
- }
15
- export {
16
- formatBytes
17
- };
@@ -1,10 +0,0 @@
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';
8
- export { getGlobalThis } from './isomorphics/getGlobalThis';
9
- export { formatBytes } from './formats/formatBytes';
10
- export { urljoin } from './shim/urljoin';
package/lib/esm/index.js DELETED
@@ -1,15 +0,0 @@
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";
8
- import { getGlobalThis } from "./isomorphics/getGlobalThis";
9
- import { formatBytes } from "./formats/formatBytes";
10
- import { urljoin } from "./shim/urljoin";
11
- export {
12
- formatBytes,
13
- getGlobalThis,
14
- urljoin
15
- };
@@ -1 +0,0 @@
1
- export * from './isBuffer';
@@ -1 +0,0 @@
1
- export * from "./isBuffer";
@@ -1,2 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function isBuffer(obj: any): obj is Buffer;
@@ -1,6 +0,0 @@
1
- function isBuffer(obj) {
2
- return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
3
- }
4
- export {
5
- isBuffer
6
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * isomorphic globalThis
3
- *
4
- * globalThis supported by ff 65, Chrome 71, Node 12, babel
5
- *
6
- * @see https://caniuse.com/#search=globalThis
7
- * @see https://v8.dev/features/globalthis
8
- */
9
- export declare const getGlobalThis: () => typeof globalThis;
@@ -1,14 +0,0 @@
1
- const getGlobalThis = () => {
2
- if (typeof globalThis !== "undefined")
3
- return globalThis;
4
- if (typeof self !== "undefined")
5
- return self;
6
- if (typeof window !== "undefined")
7
- return window;
8
- if (typeof global !== "undefined")
9
- return global;
10
- throw new Error("Unable to locate global `this`");
11
- };
12
- export {
13
- getGlobalThis
14
- };
@@ -1 +0,0 @@
1
- export * from './random';
@@ -1 +0,0 @@
1
- export * from "./random";
@@ -1,3 +0,0 @@
1
- export declare function createRandom(o?: {
2
- seed?: string | number;
3
- }): () => number;
@@ -1,17 +0,0 @@
1
- function createRandom(o = {}) {
2
- let seed = typeof o.seed === "string" ? 0 : o.seed ?? 0;
3
- if (typeof o.seed === "string") {
4
- let sum = 0;
5
- for (let i = 0; i < o.seed.length; i++) {
6
- sum += o.seed.charCodeAt(i);
7
- }
8
- seed = sum;
9
- }
10
- return () => {
11
- const x = Math.sin(seed++) * 1e4;
12
- return x - Math.floor(x);
13
- };
14
- }
15
- export {
16
- createRandom
17
- };
@@ -1,2 +0,0 @@
1
- export declare function urljoin(...strArray: string[]): string;
2
- export declare function urljoin(strArray: string[]): string;
@@ -1,51 +0,0 @@
1
- function urljoin(...args) {
2
- if (Array.isArray(args[0])) {
3
- return normalize(args[0]);
4
- } else {
5
- return normalize(args);
6
- }
7
- }
8
- function normalize(strArray) {
9
- const resultArray = [];
10
- if (strArray.length === 0) {
11
- return "";
12
- }
13
- if (typeof strArray[0] !== "string") {
14
- throw new TypeError("Url must be a string. Received " + strArray[0]);
15
- }
16
- if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
17
- const first = strArray.shift();
18
- strArray[0] = first + strArray[0];
19
- }
20
- if (strArray[0].match(/^file:\/\/\//)) {
21
- strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
22
- } else {
23
- strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
24
- }
25
- for (let i = 0; i < strArray.length; i++) {
26
- let component = strArray[i];
27
- if (typeof component !== "string") {
28
- throw new TypeError("Url must be a string. Received " + component);
29
- }
30
- if (component === "") {
31
- continue;
32
- }
33
- if (i > 0) {
34
- component = component.replace(/^[\/]+/, "");
35
- }
36
- if (i < strArray.length - 1) {
37
- component = component.replace(/[\/]+$/, "");
38
- } else {
39
- component = component.replace(/[\/]+$/, "/");
40
- }
41
- resultArray.push(component);
42
- }
43
- let str = resultArray.join("/");
44
- str = str.replace(/\/(\?|&|#[^!])/g, "$1");
45
- const parts = str.split("?");
46
- str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&");
47
- return str;
48
- }
49
- export {
50
- urljoin
51
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import { urljoin } from "./urljoin";
2
- test("join ext", () => {
3
- expect(urljoin("http://wener.me/sub/", "/a/", "/hello.js")).toBe("http://wener.me/sub/a/hello.js");
4
- });
@@ -1,4 +0,0 @@
1
- export declare function pascalCase(input: string | string[]): string;
2
- export declare function camelCase(input: string | string[], options?: {
3
- pascalCase: boolean;
4
- }): string;
@@ -1,57 +0,0 @@
1
- function preserveCamelCase(string) {
2
- let isLastCharLower = false;
3
- let isLastCharUpper = false;
4
- let isLastLastCharUpper = false;
5
- for (let i = 0; i < string.length; i++) {
6
- const character = string[i];
7
- if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {
8
- string = string.slice(0, i) + "-" + string.slice(i);
9
- isLastCharLower = false;
10
- isLastLastCharUpper = isLastCharUpper;
11
- isLastCharUpper = true;
12
- i++;
13
- } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(character) && character.toLowerCase() === character) {
14
- string = string.slice(0, i - 1) + "-" + string.slice(i - 1);
15
- isLastLastCharUpper = isLastCharUpper;
16
- isLastCharUpper = false;
17
- isLastCharLower = true;
18
- } else {
19
- isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
20
- isLastLastCharUpper = isLastCharUpper;
21
- isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
22
- }
23
- }
24
- return string;
25
- }
26
- function pascalCase(input) {
27
- return camelCase(input, { pascalCase: true });
28
- }
29
- function camelCase(input, options = {
30
- pascalCase: false
31
- }) {
32
- if (!(typeof input === "string" || Array.isArray(input))) {
33
- throw new TypeError("Expected the input to be `string | string[]`");
34
- }
35
- const postProcess = (x) => options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x;
36
- if (Array.isArray(input)) {
37
- input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
38
- } else {
39
- input = input.trim();
40
- }
41
- if (input.length === 0) {
42
- return "";
43
- }
44
- if (input.length === 1) {
45
- return options.pascalCase ? input.toUpperCase() : input.toLowerCase();
46
- }
47
- const hasUpperCase = input !== input.toLowerCase();
48
- if (hasUpperCase) {
49
- input = preserveCamelCase(input);
50
- }
51
- input = input.replace(/^[_.\- ]+/, "").toLowerCase().replace(/[_.\- ]+(\w|$)/g, (_, p1) => p1.toUpperCase()).replace(/\d+(\w|$)/g, (m) => m.toUpperCase());
52
- return postProcess(input);
53
- }
54
- export {
55
- camelCase,
56
- pascalCase
57
- };
@@ -1,2 +0,0 @@
1
- export * from './camelCase';
2
- export * from './templates';
@@ -1,2 +0,0 @@
1
- export * from "./camelCase";
2
- export * from "./templates";
@@ -1,7 +0,0 @@
1
- /**
2
- * 替换类似于 JS 的模板字符串
3
- *
4
- * @example
5
- * templateString('My name is ${name}',{name:'wener'})
6
- */
7
- export declare function templateString(template: string, getter: (v: string) => any): string;
@@ -1,8 +0,0 @@
1
- function templateString(template, getter) {
2
- return template.replace(/\${(.*?)}/g, (_, g) => {
3
- return getter(g.trim());
4
- });
5
- }
6
- export {
7
- templateString
8
- };
@@ -1,2 +0,0 @@
1
- export declare function assert(condition: any, msg?: string): asserts condition;
2
- export declare function assertIsDefined<T>(val: T): asserts val is NonNullable<T>;
@@ -1,10 +0,0 @@
1
- function assert(condition, msg) {
2
- console.assert(!condition, msg);
3
- }
4
- function assertIsDefined(val) {
5
- console.assert(val === void 0 || val === null, "Expected defined");
6
- }
7
- export {
8
- assert,
9
- assertIsDefined
10
- };
@@ -1,4 +0,0 @@
1
- export * from './asserts';
2
- export * from './isDefined';
3
- export * from './isEmptyObject';
4
- export * from './isClass';
@@ -1,4 +0,0 @@
1
- export * from "./asserts";
2
- export * from "./isDefined";
3
- export * from "./isEmptyObject";
4
- export * from "./isClass";
@@ -1 +0,0 @@
1
- export declare function isClass(func: any): boolean;
@@ -1,6 +0,0 @@
1
- function isClass(func) {
2
- return typeof func === "function" && /^class\s/.test(Function.prototype.toString.call(func));
3
- }
4
- export {
5
- isClass
6
- };
@@ -1 +0,0 @@
1
- export declare function isDefined<T = any>(v: T): v is NonNullable<T>;
@@ -1,6 +0,0 @@
1
- function isDefined(v) {
2
- return v !== null && v !== void 0;
3
- }
4
- export {
5
- isDefined
6
- };
@@ -1 +0,0 @@
1
- export declare function isEmptyObject(o: any): boolean;
@@ -1,9 +0,0 @@
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
- export {
8
- isEmptyObject
9
- };
@@ -1 +0,0 @@
1
- export * from './MaybeArray';
@@ -1,8 +0,0 @@
1
- export * from './LazyPromise';
2
- export * from './AsyncInterval';
3
- export * from './MaybePromise';
4
-
5
- export * from './sleep';
6
- export * from './timeout';
7
- export * from './isPromise';
8
- export * from './promiseOfCallback';
@@ -1,4 +0,0 @@
1
- export * from './copy';
2
- export * from './download';
3
- export * from './loaders';
4
- export * from './getFileFromDataTransfer';
package/src/io/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './isBuffer';
@@ -1 +0,0 @@
1
- export * from './random';
@@ -1,2 +0,0 @@
1
- export * from './camelCase';
2
- export * from './templates';
@@ -1,4 +0,0 @@
1
- export * from './asserts';
2
- export * from './isDefined';
3
- export * from './isEmptyObject';
4
- export * from './isClass';
@@ -1,7 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "sourceMap": true,
4
- "jsx": "react"
5
- },
6
- "extends": "./tsconfig.json"
7
- }