@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.
- package/dist/cjs/index.js +579 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.development.js +545 -0
- package/dist/esm/index.development.js.map +1 -0
- package/dist/esm/index.min.js +2 -0
- package/dist/esm/index.min.js.map +1 -0
- package/dist/system/index.development.js +585 -0
- package/dist/system/index.development.js.map +1 -0
- package/dist/system/index.min.js +2 -0
- package/dist/system/index.min.js.map +1 -0
- package/lib/esm/arrays/MaybeArray.mjs +30 -0
- package/lib/esm/arrays/MaybeArray.mjs.map +1 -0
- package/lib/esm/asyncs/AsyncInterval.mjs +15 -0
- package/lib/esm/asyncs/AsyncInterval.mjs.map +1 -0
- package/lib/esm/asyncs/LazyPromise.mjs +24 -0
- package/lib/esm/asyncs/LazyPromise.mjs.map +1 -0
- package/lib/esm/asyncs/isPromise.mjs +6 -0
- package/lib/esm/asyncs/isPromise.mjs.map +1 -0
- package/lib/esm/asyncs/{sleep.js → sleep.mjs} +3 -3
- package/lib/esm/asyncs/sleep.mjs.map +1 -0
- package/lib/esm/asyncs/timeout.mjs +24 -0
- package/lib/esm/asyncs/timeout.mjs.map +1 -0
- package/lib/esm/browsers/copy.mjs +57 -0
- package/lib/esm/browsers/copy.mjs.map +1 -0
- package/lib/esm/browsers/download.mjs +40 -0
- package/lib/esm/browsers/download.mjs.map +1 -0
- package/lib/esm/browsers/getFileFromDataTransfer.mjs +39 -0
- package/lib/esm/browsers/getFileFromDataTransfer.mjs.map +1 -0
- package/lib/esm/browsers/loaders.mjs +52 -0
- package/lib/esm/browsers/loaders.mjs.map +1 -0
- package/lib/esm/crypto/hashing.mjs +25 -0
- package/lib/esm/crypto/hashing.mjs.map +1 -0
- package/lib/esm/crypto/hex.mjs +8 -0
- package/lib/esm/crypto/hex.mjs.map +1 -0
- package/lib/esm/crypto/randomUUID.mjs +13 -0
- package/lib/esm/crypto/randomUUID.mjs.map +1 -0
- package/lib/esm/formats/formatBytes.mjs +29 -0
- package/lib/esm/formats/formatBytes.mjs.map +1 -0
- package/lib/esm/index.mjs +24 -0
- package/lib/esm/index.mjs.map +1 -0
- package/lib/esm/io/isBuffer.mjs +10 -0
- package/lib/esm/io/isBuffer.mjs.map +1 -0
- package/lib/esm/isomorphics/getGlobalThis.mjs +23 -0
- package/lib/esm/isomorphics/getGlobalThis.mjs.map +1 -0
- package/lib/esm/maths/random.mjs +18 -0
- package/lib/esm/maths/random.mjs.map +1 -0
- package/lib/esm/shim/urljoin.mjs +65 -0
- package/lib/esm/shim/urljoin.mjs.map +1 -0
- package/lib/esm/strings/camelCase.mjs +70 -0
- package/lib/esm/strings/camelCase.mjs.map +1 -0
- package/lib/esm/strings/templates.mjs +16 -0
- package/lib/esm/strings/templates.mjs.map +1 -0
- package/lib/esm/validations/isClass.mjs +6 -0
- package/lib/esm/validations/isClass.mjs.map +1 -0
- package/lib/esm/validations/isDefined.mjs +6 -0
- package/lib/esm/validations/isDefined.mjs.map +1 -0
- package/lib/esm/validations/isEmptyObject.mjs +9 -0
- package/lib/esm/validations/isEmptyObject.mjs.map +1 -0
- package/package.json +35 -22
- package/src/browsers/copy.ts +7 -3
- package/src/browsers/download.ts +7 -0
- package/src/browsers/loaders.ts +32 -7
- package/src/crypto/hashing.test.ts +26 -0
- package/src/crypto/hashing.ts +27 -0
- package/src/crypto/hex.ts +5 -0
- package/src/crypto/randomUUID.ts +10 -0
- package/src/index.ts +34 -7
- package/src/shim/urljoin.test.ts +3 -2
- package/src/types.d.ts +7 -0
- package/tsconfig.json +5 -9
- package/jest.config.js +0 -18
- package/jest.setup.js +0 -1
- package/lib/cjs/arrays/MaybeArray.js +0 -52
- package/lib/cjs/arrays/index.js +0 -17
- package/lib/cjs/asyncs/AsyncInterval.js +0 -35
- package/lib/cjs/asyncs/LazyPromise.js +0 -43
- package/lib/cjs/asyncs/MaybePromise.js +0 -15
- package/lib/cjs/asyncs/generatorOfStream.js +0 -35
- package/lib/cjs/asyncs/index.js +0 -23
- package/lib/cjs/asyncs/isPromise.js +0 -25
- package/lib/cjs/asyncs/promiseOfCallback.js +0 -37
- package/lib/cjs/asyncs/sleep.js +0 -23
- package/lib/cjs/asyncs/timeout.js +0 -44
- package/lib/cjs/browsers/copy.js +0 -71
- package/lib/cjs/browsers/download.js +0 -47
- package/lib/cjs/browsers/getFileFromDataTransfer.js +0 -48
- package/lib/cjs/browsers/index.js +0 -20
- package/lib/cjs/browsers/loaders.js +0 -54
- package/lib/cjs/formats/formatBytes.js +0 -36
- package/lib/cjs/index.js +0 -35
- package/lib/cjs/io/index.js +0 -17
- package/lib/cjs/io/isBuffer.js +0 -25
- package/lib/cjs/isomorphics/getGlobalThis.js +0 -33
- package/lib/cjs/maths/index.js +0 -17
- package/lib/cjs/maths/random.js +0 -36
- package/lib/cjs/shim/urljoin.js +0 -70
- package/lib/cjs/shim/urljoin.test.js +0 -4
- package/lib/cjs/strings/camelCase.js +0 -76
- package/lib/cjs/strings/index.js +0 -18
- package/lib/cjs/strings/templates.js +0 -27
- package/lib/cjs/validations/asserts.js +0 -29
- package/lib/cjs/validations/index.js +0 -20
- package/lib/cjs/validations/isClass.js +0 -25
- package/lib/cjs/validations/isDefined.js +0 -25
- package/lib/cjs/validations/isEmptyObject.js +0 -28
- package/lib/esm/arrays/MaybeArray.d.ts +0 -5
- package/lib/esm/arrays/MaybeArray.js +0 -33
- package/lib/esm/arrays/index.d.ts +0 -1
- package/lib/esm/arrays/index.js +0 -1
- package/lib/esm/asyncs/AsyncInterval.d.ts +0 -3
- package/lib/esm/asyncs/AsyncInterval.js +0 -16
- package/lib/esm/asyncs/LazyPromise.d.ts +0 -5
- package/lib/esm/asyncs/LazyPromise.js +0 -24
- package/lib/esm/asyncs/MaybePromise.d.ts +0 -1
- package/lib/esm/asyncs/MaybePromise.js +0 -0
- package/lib/esm/asyncs/generatorOfStream.d.ts +0 -1
- package/lib/esm/asyncs/generatorOfStream.js +0 -16
- package/lib/esm/asyncs/index.d.ts +0 -7
- package/lib/esm/asyncs/index.js +0 -7
- package/lib/esm/asyncs/isPromise.d.ts +0 -1
- package/lib/esm/asyncs/isPromise.js +0 -6
- package/lib/esm/asyncs/promiseOfCallback.d.ts +0 -1
- package/lib/esm/asyncs/promiseOfCallback.js +0 -18
- package/lib/esm/asyncs/sleep.d.ts +0 -1
- package/lib/esm/asyncs/timeout.d.ts +0 -4
- package/lib/esm/asyncs/timeout.js +0 -25
- package/lib/esm/browsers/copy.d.ts +0 -1
- package/lib/esm/browsers/copy.js +0 -52
- package/lib/esm/browsers/download.d.ts +0 -4
- package/lib/esm/browsers/download.js +0 -28
- package/lib/esm/browsers/getFileFromDataTransfer.d.ts +0 -4
- package/lib/esm/browsers/getFileFromDataTransfer.js +0 -29
- package/lib/esm/browsers/index.d.ts +0 -4
- package/lib/esm/browsers/index.js +0 -4
- package/lib/esm/browsers/loaders.d.ts +0 -6
- package/lib/esm/browsers/loaders.js +0 -35
- package/lib/esm/formats/formatBytes.d.ts +0 -11
- package/lib/esm/formats/formatBytes.js +0 -17
- package/lib/esm/index.d.ts +0 -10
- package/lib/esm/index.js +0 -15
- package/lib/esm/io/index.d.ts +0 -1
- package/lib/esm/io/index.js +0 -1
- package/lib/esm/io/isBuffer.d.ts +0 -2
- package/lib/esm/io/isBuffer.js +0 -6
- package/lib/esm/isomorphics/getGlobalThis.d.ts +0 -9
- package/lib/esm/isomorphics/getGlobalThis.js +0 -14
- package/lib/esm/maths/index.d.ts +0 -1
- package/lib/esm/maths/index.js +0 -1
- package/lib/esm/maths/random.d.ts +0 -3
- package/lib/esm/maths/random.js +0 -17
- package/lib/esm/shim/urljoin.d.ts +0 -2
- package/lib/esm/shim/urljoin.js +0 -51
- package/lib/esm/shim/urljoin.test.d.ts +0 -1
- package/lib/esm/shim/urljoin.test.js +0 -4
- package/lib/esm/strings/camelCase.d.ts +0 -4
- package/lib/esm/strings/camelCase.js +0 -57
- package/lib/esm/strings/index.d.ts +0 -2
- package/lib/esm/strings/index.js +0 -2
- package/lib/esm/strings/templates.d.ts +0 -7
- package/lib/esm/strings/templates.js +0 -8
- package/lib/esm/validations/asserts.d.ts +0 -2
- package/lib/esm/validations/asserts.js +0 -10
- package/lib/esm/validations/index.d.ts +0 -4
- package/lib/esm/validations/index.js +0 -4
- package/lib/esm/validations/isClass.d.ts +0 -1
- package/lib/esm/validations/isClass.js +0 -6
- package/lib/esm/validations/isDefined.d.ts +0 -1
- package/lib/esm/validations/isDefined.js +0 -6
- package/lib/esm/validations/isEmptyObject.d.ts +0 -1
- package/lib/esm/validations/isEmptyObject.js +0 -9
- package/src/arrays/index.ts +0 -1
- package/src/asyncs/index.ts +0 -8
- package/src/browsers/index.ts +0 -4
- package/src/io/index.ts +0 -1
- package/src/maths/index.ts +0 -1
- package/src/strings/index.ts +0 -2
- package/src/validations/index.ts +0 -4
- package/tsconfig.jest.json +0 -7
package/lib/esm/browsers/copy.js
DELETED
|
@@ -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,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,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,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
|
-
};
|
package/lib/esm/index.d.ts
DELETED
|
@@ -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
|
-
};
|
package/lib/esm/io/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './isBuffer';
|
package/lib/esm/io/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./isBuffer";
|
package/lib/esm/io/isBuffer.d.ts
DELETED
package/lib/esm/io/isBuffer.js
DELETED
|
@@ -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
|
-
};
|
package/lib/esm/maths/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './random';
|
package/lib/esm/maths/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./random";
|
package/lib/esm/maths/random.js
DELETED
|
@@ -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
|
-
};
|
package/lib/esm/shim/urljoin.js
DELETED
|
@@ -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,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
|
-
};
|
package/lib/esm/strings/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isClass(func: any): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDefined<T = any>(v: T): v is NonNullable<T>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isEmptyObject(o: any): boolean;
|
package/src/arrays/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './MaybeArray';
|
package/src/asyncs/index.ts
DELETED
package/src/browsers/index.ts
DELETED
package/src/io/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './isBuffer';
|
package/src/maths/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './random';
|
package/src/strings/index.ts
DELETED
package/src/validations/index.ts
DELETED