@stacksjs/browser 0.70.57 → 0.70.59
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/auto-init.js +61 -0
- package/dist/composables/auth/useGithub.d.ts +12 -0
- package/dist/composables/auth/useGithub.js +41 -0
- package/dist/composables/index.js +110 -0
- package/dist/composables/useApi.js +66 -0
- package/dist/composables/useAuth.js +127 -0
- package/dist/composables/useFetch.d.ts +1 -0
- package/dist/composables/useFetch.js +1 -0
- package/dist/index.js +12 -2539
- package/dist/model-loader.js +61 -0
- package/dist/types/dashboard.js +3 -0
- package/dist/utils/base.js +4 -0
- package/dist/utils/billable.js +64 -0
- package/dist/utils/date.js +2 -0
- package/dist/utils/debounce.js +43 -0
- package/dist/utils/fetch.js +94 -0
- package/dist/utils/function.js +7 -0
- package/dist/utils/guards.js +12 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/lazy.js +9 -0
- package/dist/utils/math.js +23 -0
- package/dist/utils/plans.js +135 -0
- package/dist/utils/promise.js +55 -0
- package/dist/utils/random.js +67 -0
- package/dist/utils/regex.js +29 -0
- package/dist/utils/retry.js +28 -0
- package/dist/utils/sleep.js +59 -0
- package/dist/utils/throttle.js +18 -0
- package/dist/utils/vendors.js +37 -0
- package/package.json +3 -3
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function sleep(ms) {
|
|
2
|
+
if (ms < 0 || !Number.isInteger(ms))
|
|
3
|
+
throw Error("sleep() requires a non-negative integer");
|
|
4
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
}
|
|
6
|
+
export function wait(ms) {
|
|
7
|
+
if (ms < 0 || !Number.isInteger(ms))
|
|
8
|
+
throw Error("wait() requires a non-negative integer");
|
|
9
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
}
|
|
11
|
+
export function delay(ms) {
|
|
12
|
+
if (ms < 0 || !Number.isInteger(ms))
|
|
13
|
+
throw Error("delay() requires a non-negative integer");
|
|
14
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
15
|
+
}
|
|
16
|
+
export function waitUntil(condition, options = {}) {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const { interval, timeout } = normalizeOptions(options);
|
|
19
|
+
if (condition()) {
|
|
20
|
+
resolve();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const check = () => {
|
|
24
|
+
if (condition())
|
|
25
|
+
resolve();
|
|
26
|
+
else
|
|
27
|
+
setTimeout(check, interval);
|
|
28
|
+
};
|
|
29
|
+
if (timeout)
|
|
30
|
+
setTimeout(resolve, timeout);
|
|
31
|
+
check();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function normalizeOptions(options) {
|
|
35
|
+
if (typeof options === "number")
|
|
36
|
+
return { interval: options, timeout: 0 };
|
|
37
|
+
return {
|
|
38
|
+
interval: options.interval ?? 100,
|
|
39
|
+
timeout: options.timeout ?? 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function waitWhile(condition, options = {}) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
const { interval = 100, timeout = 0 } = options;
|
|
45
|
+
if (!condition()) {
|
|
46
|
+
resolve();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const check = () => {
|
|
50
|
+
if (!condition())
|
|
51
|
+
resolve();
|
|
52
|
+
else
|
|
53
|
+
setTimeout(check, interval);
|
|
54
|
+
};
|
|
55
|
+
if (timeout)
|
|
56
|
+
setTimeout(resolve, timeout);
|
|
57
|
+
check();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function throttle(fn, wait = 300) {
|
|
2
|
+
let inThrottle, lastFn, lastTime;
|
|
3
|
+
return function(...args) {
|
|
4
|
+
if (!inThrottle) {
|
|
5
|
+
fn.apply(this, args);
|
|
6
|
+
lastTime = Date.now();
|
|
7
|
+
inThrottle = !0;
|
|
8
|
+
} else {
|
|
9
|
+
clearTimeout(lastFn);
|
|
10
|
+
lastFn = setTimeout(() => {
|
|
11
|
+
if (Date.now() - lastTime >= wait) {
|
|
12
|
+
fn.apply(this, args);
|
|
13
|
+
lastTime = Date.now();
|
|
14
|
+
}
|
|
15
|
+
}, Math.max(wait - (Date.now() - lastTime), 0));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export {
|
|
2
|
+
useDark,
|
|
3
|
+
useDateFormat,
|
|
4
|
+
useFetch,
|
|
5
|
+
useNow,
|
|
6
|
+
useOnline,
|
|
7
|
+
usePreferredDark,
|
|
8
|
+
useStorage,
|
|
9
|
+
useToggle
|
|
10
|
+
} from "@stacksjs/composables";
|
|
11
|
+
export {
|
|
12
|
+
useHead as createHead,
|
|
13
|
+
useHead as Head,
|
|
14
|
+
renderHead as renderHeadToString
|
|
15
|
+
} from "@stacksjs/stx";
|
|
16
|
+
const DECIMAL_UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], BINARY_UNITS = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
17
|
+
export function readableSize(bytes, options = {}) {
|
|
18
|
+
const {
|
|
19
|
+
precision = 1,
|
|
20
|
+
binary = !1,
|
|
21
|
+
space = !0,
|
|
22
|
+
locale = "en-US",
|
|
23
|
+
minimumFractionDigits = 0,
|
|
24
|
+
maximumFractionDigits = precision
|
|
25
|
+
} = options;
|
|
26
|
+
if (!Number.isFinite(bytes))
|
|
27
|
+
throw TypeError(`Expected a finite number, got ${typeof bytes}: ${bytes}`);
|
|
28
|
+
const isNegative = bytes < 0, prefix = isNegative ? "-" : "";
|
|
29
|
+
if (isNegative)
|
|
30
|
+
bytes = -bytes;
|
|
31
|
+
if (bytes < 1) {
|
|
32
|
+
const numberString = bytes.toLocaleString(locale, { minimumFractionDigits, maximumFractionDigits });
|
|
33
|
+
return `${prefix}${numberString}${space ? " " : ""}B`;
|
|
34
|
+
}
|
|
35
|
+
const base = binary ? 1024 : 1000, units = binary ? BINARY_UNITS : DECIMAL_UNITS, exponent = Math.min(Math.floor(Math.log(bytes) / Math.log(base)), units.length - 1), numberString = (bytes / base ** exponent).toLocaleString(locale, { minimumFractionDigits, maximumFractionDigits });
|
|
36
|
+
return `${prefix}${numberString}${space ? " " : ""}${units[exponent]}`;
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.59",
|
|
5
5
|
"description": "Stacks core frontend/browser functionalities.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"prepublishOnly": "bun run build"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@stacksjs/composables": "0.70.
|
|
54
|
+
"@stacksjs/composables": "0.70.59",
|
|
55
55
|
"@stacksjs/stx": "^0.2.82",
|
|
56
56
|
"@stripe/stripe-js": "^9.0.0",
|
|
57
57
|
"bun-query-builder": "^0.1.38",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"better-dx": "^0.2.12",
|
|
62
|
-
"@stacksjs/utils": "0.70.
|
|
62
|
+
"@stacksjs/utils": "0.70.59"
|
|
63
63
|
}
|
|
64
64
|
}
|