@wener/utils 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils.cjs +497 -0
- package/dist/utils.cjs.map +7 -0
- package/dist/utils.js +445 -0
- package/dist/utils.js.map +7 -0
- package/dist/utils.mjs +475 -0
- package/dist/utils.mjs.map +7 -0
- package/jest.config.js +7 -5
- package/lib/cjs/arrays/MaybeArray.js +3 -8
- package/lib/cjs/arrays/MaybeArray.js.map +1 -1
- package/lib/cjs/arrays/index.js +1 -1
- package/lib/cjs/asyncs/AsyncInterval.js +8 -18
- package/lib/cjs/asyncs/AsyncInterval.js.map +1 -1
- package/lib/cjs/asyncs/LazyPromise.js +6 -6
- package/lib/cjs/asyncs/LazyPromise.js.map +1 -1
- package/lib/cjs/asyncs/generatorOfStream.js +11 -23
- package/lib/cjs/asyncs/generatorOfStream.js.map +1 -1
- package/lib/cjs/asyncs/index.js +1 -1
- package/lib/cjs/asyncs/promiseOfCallback.js +2 -2
- package/lib/cjs/asyncs/promiseOfCallback.js.map +1 -1
- package/lib/cjs/asyncs/sleep.js +2 -1
- package/lib/cjs/asyncs/sleep.js.map +1 -1
- package/lib/cjs/asyncs/timeout.js +10 -13
- package/lib/cjs/asyncs/timeout.js.map +1 -1
- package/lib/cjs/browsers/{clipboard.d.ts → copy.d.ts} +0 -0
- package/lib/cjs/browsers/{clipboard.js → copy.js} +7 -8
- package/lib/cjs/browsers/copy.js.map +1 -0
- package/lib/cjs/browsers/download.js +7 -8
- package/lib/cjs/browsers/download.js.map +1 -1
- package/lib/cjs/browsers/getFileFromDataTransfer.d.ts +4 -0
- package/lib/cjs/browsers/getFileFromDataTransfer.js +41 -0
- package/lib/cjs/browsers/getFileFromDataTransfer.js.map +1 -0
- package/lib/cjs/browsers/index.d.ts +2 -2
- package/lib/cjs/browsers/index.js +3 -3
- package/lib/cjs/browsers/index.js.map +1 -1
- package/lib/cjs/browsers/loaders.js +9 -12
- package/lib/cjs/browsers/loaders.js.map +1 -1
- package/lib/cjs/formats/formatBytes.d.ts +11 -0
- package/lib/cjs/formats/formatBytes.js +31 -0
- package/lib/cjs/formats/formatBytes.js.map +1 -0
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +4 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/io/index.js +1 -1
- package/lib/cjs/isomorphics/getGlobalThis.d.ts +1 -1
- package/lib/cjs/isomorphics/getGlobalThis.js +4 -7
- package/lib/cjs/isomorphics/getGlobalThis.js.map +1 -1
- package/lib/cjs/isomorphics/index.js +1 -1
- package/lib/cjs/maths/index.js +1 -1
- package/lib/cjs/maths/random.d.ts +2 -2
- package/lib/cjs/maths/random.js +8 -9
- package/lib/cjs/maths/random.js.map +1 -1
- package/lib/cjs/strings/camelCase.js +14 -15
- package/lib/cjs/strings/camelCase.js.map +1 -1
- package/lib/cjs/strings/index.js +1 -1
- package/lib/cjs/strings/templates.js +1 -1
- package/lib/cjs/strings/templates.js.map +1 -1
- package/lib/cjs/strings/urljoin.d.ts +2 -1
- package/lib/cjs/strings/urljoin.js +23 -15
- package/lib/cjs/strings/urljoin.js.map +1 -1
- package/lib/cjs/strings/urljoin.test.js +3 -3
- package/lib/cjs/strings/urljoin.test.js.map +1 -1
- package/lib/cjs/validations/index.js +1 -1
- package/lib/esm/arrays/MaybeArray.js +29 -29
- package/lib/esm/arrays/index.js +1 -2
- package/lib/esm/asyncs/AsyncInterval.js +14 -21
- package/lib/esm/asyncs/LazyPromise.js +23 -21
- package/lib/esm/asyncs/MaybePromise.js +0 -1
- package/lib/esm/asyncs/generatorOfStream.js +14 -24
- package/lib/esm/asyncs/index.js +7 -8
- package/lib/esm/asyncs/isPromise.js +5 -3
- package/lib/esm/asyncs/promiseOfCallback.js +16 -16
- package/lib/esm/asyncs/sleep.js +4 -2
- package/lib/esm/asyncs/timeout.js +24 -25
- package/lib/esm/browsers/{clipboard.d.ts → copy.d.ts} +0 -0
- package/lib/esm/browsers/copy.js +52 -0
- package/lib/esm/browsers/download.js +25 -29
- package/lib/esm/browsers/getFileFromDataTransfer.d.ts +4 -0
- package/lib/esm/browsers/getFileFromDataTransfer.js +29 -0
- package/lib/esm/browsers/index.d.ts +2 -2
- package/lib/esm/browsers/index.js +4 -5
- package/lib/esm/browsers/loaders.js +31 -32
- package/lib/esm/formats/formatBytes.d.ts +11 -0
- package/lib/esm/formats/formatBytes.js +17 -0
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +12 -10
- package/lib/esm/io/index.js +1 -2
- package/lib/esm/io/isBuffer.js +5 -7
- package/lib/esm/isomorphics/getGlobalThis.d.ts +1 -1
- package/lib/esm/isomorphics/getGlobalThis.js +13 -24
- package/lib/esm/isomorphics/index.js +1 -2
- package/lib/esm/maths/index.js +1 -2
- package/lib/esm/maths/random.d.ts +2 -2
- package/lib/esm/maths/random.js +15 -15
- package/lib/esm/strings/camelCase.js +52 -64
- package/lib/esm/strings/index.js +3 -4
- package/lib/esm/strings/templates.js +7 -13
- package/lib/esm/strings/urljoin.d.ts +2 -1
- package/lib/esm/strings/urljoin.js +48 -52
- package/lib/esm/strings/urljoin.test.js +3 -4
- package/lib/esm/validations/asserts.js +8 -11
- package/lib/esm/validations/index.js +4 -5
- package/lib/esm/validations/isClass.js +5 -3
- package/lib/esm/validations/isDefined.js +5 -3
- package/lib/esm/validations/isEmptyObject.js +8 -6
- package/lib/esnext/arrays/MaybeArray.js +3 -8
- package/lib/esnext/arrays/MaybeArray.js.map +1 -1
- package/lib/esnext/asyncs/AsyncInterval.js +8 -18
- package/lib/esnext/asyncs/AsyncInterval.js.map +1 -1
- package/lib/esnext/asyncs/LazyPromise.js +6 -6
- package/lib/esnext/asyncs/LazyPromise.js.map +1 -1
- package/lib/esnext/asyncs/MaybePromise.js +1 -0
- package/lib/esnext/asyncs/generatorOfStream.js +11 -23
- package/lib/esnext/asyncs/generatorOfStream.js.map +1 -1
- package/lib/esnext/asyncs/promiseOfCallback.js +2 -2
- package/lib/esnext/asyncs/promiseOfCallback.js.map +1 -1
- package/lib/esnext/asyncs/sleep.js +1 -1
- package/lib/esnext/asyncs/sleep.js.map +1 -1
- package/lib/esnext/asyncs/timeout.js +10 -14
- package/lib/esnext/asyncs/timeout.js.map +1 -1
- package/lib/esnext/browsers/{clipboard.d.ts → copy.d.ts} +0 -0
- package/lib/esnext/browsers/{clipboard.js → copy.js} +7 -8
- package/lib/esnext/browsers/copy.js.map +1 -0
- package/lib/esnext/browsers/download.js +7 -8
- package/lib/esnext/browsers/download.js.map +1 -1
- package/lib/esnext/browsers/getFileFromDataTransfer.d.ts +4 -0
- package/lib/esnext/browsers/getFileFromDataTransfer.js +37 -0
- package/lib/esnext/browsers/getFileFromDataTransfer.js.map +1 -0
- package/lib/esnext/browsers/index.d.ts +2 -2
- package/lib/esnext/browsers/index.js +2 -2
- package/lib/esnext/browsers/index.js.map +1 -1
- package/lib/esnext/browsers/loaders.js +9 -12
- package/lib/esnext/browsers/loaders.js.map +1 -1
- package/lib/esnext/formats/formatBytes.d.ts +11 -0
- package/lib/esnext/formats/formatBytes.js +27 -0
- package/lib/esnext/formats/formatBytes.js.map +1 -0
- package/lib/esnext/index.d.ts +1 -1
- package/lib/esnext/index.js +1 -1
- package/lib/esnext/index.js.map +1 -1
- package/lib/esnext/isomorphics/getGlobalThis.d.ts +1 -1
- package/lib/esnext/isomorphics/getGlobalThis.js +3 -7
- package/lib/esnext/isomorphics/getGlobalThis.js.map +1 -1
- package/lib/esnext/maths/random.d.ts +2 -2
- package/lib/esnext/maths/random.js +8 -9
- package/lib/esnext/maths/random.js.map +1 -1
- package/lib/esnext/strings/camelCase.js +14 -15
- package/lib/esnext/strings/camelCase.js.map +1 -1
- package/lib/esnext/strings/templates.js +1 -1
- package/lib/esnext/strings/templates.js.map +1 -1
- package/lib/esnext/strings/urljoin.d.ts +2 -1
- package/lib/esnext/strings/urljoin.js +22 -14
- package/lib/esnext/strings/urljoin.js.map +1 -1
- package/lib/esnext/strings/urljoin.test.js +2 -2
- package/lib/esnext/strings/urljoin.test.js.map +1 -1
- package/package.json +22 -27
- package/src/arrays/MaybeArray.ts +5 -2
- package/src/asyncs/timeout.ts +1 -1
- package/src/browsers/{clipboard.ts → copy.ts} +0 -0
- package/src/browsers/{transfers.ts → getFileFromDataTransfer.ts} +12 -7
- package/src/browsers/index.ts +2 -2
- package/src/formats/formatBytes.ts +30 -0
- package/src/index.ts +2 -1
- package/src/isomorphics/getGlobalThis.ts +2 -4
- package/src/maths/random.ts +5 -5
- package/src/strings/urljoin.test.ts +1 -1
- package/src/strings/urljoin.ts +22 -5
- package/tsconfig.json +14 -3
- package/dist/wener-utils.cjs +0 -879
- package/dist/wener-utils.cjs.map +0 -1
- package/dist/wener-utils.esm.js +0 -846
- package/dist/wener-utils.esm.js.map +0 -1
- package/dist/wener-utils.system.js +0 -882
- package/dist/wener-utils.system.js.map +0 -1
- package/dist/wener-utils.umd.js +0 -885
- package/dist/wener-utils.umd.js.map +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -10
- package/lib/cjs/browsers/clipboard.js.map +0 -1
- package/lib/cjs/browsers/transfers.d.ts +0 -4
- package/lib/cjs/browsers/transfers.js +0 -38
- package/lib/cjs/browsers/transfers.js.map +0 -1
- package/lib/cjs/envs/index.d.ts +0 -1
- package/lib/cjs/envs/index.js +0 -5
- package/lib/cjs/envs/index.js.map +0 -1
- package/lib/cjs/envs/isDev.d.ts +0 -1
- package/lib/cjs/envs/isDev.js +0 -8
- package/lib/cjs/envs/isDev.js.map +0 -1
- package/lib/esm/arrays/MaybeArray.js.map +0 -1
- package/lib/esm/arrays/index.js.map +0 -1
- package/lib/esm/asyncs/AsyncInterval.js.map +0 -1
- package/lib/esm/asyncs/LazyPromise.js.map +0 -1
- package/lib/esm/asyncs/MaybePromise.js.map +0 -1
- package/lib/esm/asyncs/generatorOfStream.js.map +0 -1
- package/lib/esm/asyncs/index.js.map +0 -1
- package/lib/esm/asyncs/isPromise.js.map +0 -1
- package/lib/esm/asyncs/promiseOfCallback.js.map +0 -1
- package/lib/esm/asyncs/sleep.js.map +0 -1
- package/lib/esm/asyncs/timeout.js.map +0 -1
- package/lib/esm/browsers/clipboard.js +0 -52
- package/lib/esm/browsers/clipboard.js.map +0 -1
- package/lib/esm/browsers/download.js.map +0 -1
- package/lib/esm/browsers/index.js.map +0 -1
- package/lib/esm/browsers/loaders.js.map +0 -1
- package/lib/esm/browsers/transfers.d.ts +0 -4
- package/lib/esm/browsers/transfers.js +0 -34
- package/lib/esm/browsers/transfers.js.map +0 -1
- package/lib/esm/envs/index.d.ts +0 -1
- package/lib/esm/envs/index.js +0 -2
- package/lib/esm/envs/index.js.map +0 -1
- package/lib/esm/envs/isDev.d.ts +0 -1
- package/lib/esm/envs/isDev.js +0 -5
- package/lib/esm/envs/isDev.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/io/index.js.map +0 -1
- package/lib/esm/io/isBuffer.js.map +0 -1
- package/lib/esm/isomorphics/getGlobalThis.js.map +0 -1
- package/lib/esm/isomorphics/index.js.map +0 -1
- package/lib/esm/maths/index.js.map +0 -1
- package/lib/esm/maths/random.js.map +0 -1
- package/lib/esm/strings/camelCase.js.map +0 -1
- package/lib/esm/strings/index.js.map +0 -1
- package/lib/esm/strings/templates.js.map +0 -1
- package/lib/esm/strings/urljoin.js.map +0 -1
- package/lib/esm/strings/urljoin.test.js.map +0 -1
- package/lib/esm/validations/asserts.js.map +0 -1
- package/lib/esm/validations/index.js.map +0 -1
- package/lib/esm/validations/isClass.js.map +0 -1
- package/lib/esm/validations/isDefined.js.map +0 -1
- package/lib/esm/validations/isEmptyObject.js.map +0 -1
- package/lib/esnext/browsers/clipboard.js.map +0 -1
- package/lib/esnext/browsers/transfers.d.ts +0 -4
- package/lib/esnext/browsers/transfers.js +0 -34
- package/lib/esnext/browsers/transfers.js.map +0 -1
- package/lib/esnext/envs/index.d.ts +0 -1
- package/lib/esnext/envs/index.js +0 -2
- package/lib/esnext/envs/index.js.map +0 -1
- package/lib/esnext/envs/isDev.d.ts +0 -1
- package/lib/esnext/envs/isDev.js +0 -5
- package/lib/esnext/envs/isDev.js.map +0 -1
- package/rollup.config.ts +0 -76
- package/src/envs/index.ts +0 -1
- package/src/envs/isDev.ts +0 -3
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
a.href = data;
|
|
11
|
-
}
|
|
12
|
-
else if (typeof data === 'string') {
|
|
13
|
-
data = new TextEncoder().encode(data);
|
|
14
|
-
}
|
|
15
|
-
if (data instanceof Uint8Array) {
|
|
16
|
-
data = new Blob([data], { type: type });
|
|
17
|
-
}
|
|
18
|
-
if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
|
|
19
|
-
a.href = URL.createObjectURL(data);
|
|
20
|
-
closer = function () { return URL.revokeObjectURL(a.href); };
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
console.error("invalid download data", data);
|
|
24
|
-
throw new Error("can not download " + Object.getPrototypeOf(data));
|
|
25
|
-
}
|
|
26
|
-
a.click();
|
|
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);
|
|
27
10
|
}
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
if (data instanceof Uint8Array) {
|
|
12
|
+
data = new Blob([data], { type });
|
|
30
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
|
+
}
|
|
31
25
|
}
|
|
32
|
-
|
|
26
|
+
export {
|
|
27
|
+
download
|
|
28
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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,5 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./copy";
|
|
2
|
+
export * from "./download";
|
|
3
|
+
export * from "./loaders";
|
|
4
|
+
export * from "./getFileFromDataTransfer";
|
|
@@ -1,36 +1,35 @@
|
|
|
1
1
|
function load(el, resolve, reject, options) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return el.setAttribute(k, v);
|
|
11
|
-
});
|
|
12
|
-
document.head.appendChild(el);
|
|
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);
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
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
|
+
});
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
});
|
|
35
31
|
}
|
|
36
|
-
|
|
32
|
+
export {
|
|
33
|
+
loadScripts,
|
|
34
|
+
loadStyles
|
|
35
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
};
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
|
|
10
|
-
|
|
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 * from "./isomorphics";
|
|
9
|
+
import { formatBytes } from "./formats/formatBytes";
|
|
10
|
+
export {
|
|
11
|
+
formatBytes
|
|
12
|
+
};
|
package/lib/esm/io/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./isBuffer";
|
package/lib/esm/io/isBuffer.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (obj != null &&
|
|
4
|
-
obj.constructor != null &&
|
|
5
|
-
typeof obj.constructor.isBuffer === 'function' &&
|
|
6
|
-
obj.constructor.isBuffer(obj));
|
|
1
|
+
function isBuffer(obj) {
|
|
2
|
+
return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
7
3
|
}
|
|
8
|
-
|
|
4
|
+
export {
|
|
5
|
+
isBuffer
|
|
6
|
+
};
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return self;
|
|
15
|
-
if (typeof window !== 'undefined')
|
|
16
|
-
return window;
|
|
17
|
-
if (typeof global !== 'undefined')
|
|
18
|
-
return global;
|
|
19
|
-
// eslint-disable-next-line
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
if (typeof _this !== 'undefined')
|
|
22
|
-
return _this;
|
|
23
|
-
throw new Error('Unable to locate global `this`');
|
|
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
|
|
24
14
|
};
|
|
25
|
-
//# sourceMappingURL=getGlobalThis.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./getGlobalThis";
|
package/lib/esm/maths/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./random";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function createRandom(
|
|
2
|
-
seed?:
|
|
1
|
+
export declare function createRandom(o?: {
|
|
2
|
+
seed?: string | number;
|
|
3
3
|
}): () => number;
|
package/lib/esm/maths/random.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (var i = 0; i < s.length; i++) {
|
|
8
|
-
sum += s.charCodeAt(i);
|
|
9
|
-
}
|
|
10
|
-
seed = sum;
|
|
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);
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
seed = sum;
|
|
9
|
+
}
|
|
10
|
+
return () => {
|
|
11
|
+
const x = Math.sin(seed++) * 1e4;
|
|
12
|
+
return x - Math.floor(x);
|
|
13
|
+
};
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
export {
|
|
16
|
+
createRandom
|
|
17
|
+
};
|
|
@@ -1,69 +1,57 @@
|
|
|
1
|
-
// https://github.com/sindresorhus/camelcase/blob/master/index.js
|
|
2
1
|
function preserveCamelCase(string) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
|
|
26
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
27
|
-
isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
|
|
28
|
-
}
|
|
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;
|
|
29
22
|
}
|
|
30
|
-
|
|
23
|
+
}
|
|
24
|
+
return string;
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
function pascalCase(input) {
|
|
27
|
+
return camelCase(input, { pascalCase: true });
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (hasUpperCase) {
|
|
60
|
-
input = preserveCamelCase(input);
|
|
61
|
-
}
|
|
62
|
-
input = input
|
|
63
|
-
.replace(/^[_.\- ]+/, '')
|
|
64
|
-
.toLowerCase()
|
|
65
|
-
.replace(/[_.\- ]+(\w|$)/g, function (_, p1) { return p1.toUpperCase(); })
|
|
66
|
-
.replace(/\d+(\w|$)/g, function (m) { return m.toUpperCase(); });
|
|
67
|
-
return postProcess(input);
|
|
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);
|
|
68
53
|
}
|
|
69
|
-
|
|
54
|
+
export {
|
|
55
|
+
camelCase,
|
|
56
|
+
pascalCase
|
|
57
|
+
};
|
package/lib/esm/strings/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./camelCase";
|
|
2
|
+
export * from "./templates";
|
|
3
|
+
export * from "./urljoin";
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* templateString('My name is ${name}',{name:'wener'})
|
|
6
|
-
*/
|
|
7
|
-
export function templateString(template, getter) {
|
|
8
|
-
return template.replace(/\${(.*?)}/g, function (_, g) {
|
|
9
|
-
// variables[g.trim()]
|
|
10
|
-
// 支持路径 - 例如 a.b[0]
|
|
11
|
-
return getter(g.trim());
|
|
12
|
-
});
|
|
1
|
+
function templateString(template, getter) {
|
|
2
|
+
return template.replace(/\${(.*?)}/g, (_, g) => {
|
|
3
|
+
return getter(g.trim());
|
|
4
|
+
});
|
|
13
5
|
}
|
|
14
|
-
|
|
6
|
+
export {
|
|
7
|
+
templateString
|
|
8
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function urljoin(...strArray: string[]):
|
|
1
|
+
export declare function urljoin(...strArray: string[]): any;
|
|
2
|
+
export declare function urljoin(strArray: string[]): any;
|
|
@@ -1,57 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
function urljoin(...args) {
|
|
2
|
+
let input;
|
|
3
|
+
if (typeof args[0] === "object") {
|
|
4
|
+
input = args[0];
|
|
5
|
+
} else {
|
|
6
|
+
input = args;
|
|
7
|
+
}
|
|
8
|
+
return normalize(input);
|
|
9
|
+
}
|
|
10
|
+
function normalize(strArray) {
|
|
11
|
+
const resultArray = [];
|
|
12
|
+
if (strArray.length === 0) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
if (typeof strArray[0] !== "string") {
|
|
16
|
+
throw new TypeError("Url must be a string. Received " + strArray[0]);
|
|
17
|
+
}
|
|
18
|
+
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
|
|
19
|
+
const first = strArray.shift();
|
|
20
|
+
strArray[0] = first + strArray[0];
|
|
21
|
+
}
|
|
22
|
+
if (strArray[0].match(/^file:\/\/\//)) {
|
|
23
|
+
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
|
|
24
|
+
} else {
|
|
25
|
+
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
|
|
26
|
+
}
|
|
27
|
+
for (let i = 0; i < strArray.length; i++) {
|
|
28
|
+
let component = strArray[i];
|
|
29
|
+
if (typeof component !== "string") {
|
|
30
|
+
throw new TypeError("Url must be a string. Received " + component);
|
|
18
31
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1:///');
|
|
32
|
+
if (component === "") {
|
|
33
|
+
continue;
|
|
22
34
|
}
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
if (i > 0) {
|
|
36
|
+
component = component.replace(/^[\/]+/, "");
|
|
25
37
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
if (component === '') {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (i > 0) {
|
|
35
|
-
// Removing the starting slashes for each component but the first.
|
|
36
|
-
component = component.replace(/^[/]+/, '');
|
|
37
|
-
}
|
|
38
|
-
if (i < strArray.length - 1) {
|
|
39
|
-
// Removing the ending slashes for each component but the last.
|
|
40
|
-
component = component.replace(/[/]+$/, '');
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
// For the last component we will combine multiple slashes to a single one.
|
|
44
|
-
component = component.replace(/[/]+$/, '/');
|
|
45
|
-
}
|
|
46
|
-
resultArray.push(component);
|
|
38
|
+
if (i < strArray.length - 1) {
|
|
39
|
+
component = component.replace(/[\/]+$/, "");
|
|
40
|
+
} else {
|
|
41
|
+
component = component.replace(/[\/]+$/, "/");
|
|
47
42
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return str;
|
|
43
|
+
resultArray.push(component);
|
|
44
|
+
}
|
|
45
|
+
let str = resultArray.join("/");
|
|
46
|
+
str = str.replace(/\/(\?|&|#[^!])/g, "$1");
|
|
47
|
+
const parts = str.split("?");
|
|
48
|
+
str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&");
|
|
49
|
+
return str;
|
|
56
50
|
}
|
|
57
|
-
|
|
51
|
+
export {
|
|
52
|
+
urljoin
|
|
53
|
+
};
|