@stacksjs/utils 0.53.1 → 0.56.23
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/index.d.ts +377 -15
- package/dist/index.mjs +401 -15
- package/package.json +31 -30
- package/dist/base.d.ts +0 -3
- package/dist/base.mjs +0 -12
- package/dist/config.d.ts +0 -23
- package/dist/config.mjs +0 -66
- package/dist/currency.d.ts +0 -1
- package/dist/currency.mjs +0 -26
- package/dist/debounce.d.ts +0 -1
- package/dist/debounce.mjs +0 -1
- package/dist/delete.d.ts +0 -2
- package/dist/delete.mjs +0 -2
- package/dist/equal.d.ts +0 -1
- package/dist/equal.mjs +0 -23
- package/dist/function.d.ts +0 -18
- package/dist/function.mjs +0 -7
- package/dist/guards.d.ts +0 -28
- package/dist/guards.mjs +0 -12
- package/dist/helpers.d.ts +0 -46
- package/dist/helpers.mjs +0 -92
- package/dist/math.d.ts +0 -3
- package/dist/math.mjs +0 -28
- package/dist/p.d.ts +0 -41
- package/dist/p.mjs +0 -74
- package/dist/promise.d.ts +0 -65
- package/dist/promise.mjs +0 -57
- package/dist/throttle.d.ts +0 -19
- package/dist/throttle.mjs +0 -20
- package/dist/vendors.d.ts +0 -3
- package/dist/vendors.mjs +0 -210
- package/dist/versions.d.ts +0 -1
- package/dist/versions.mjs +0 -1
package/dist/equal.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getTypeName } from "./base.mjs";
|
|
2
|
-
export function isDeepEqual(value1, value2) {
|
|
3
|
-
const type1 = getTypeName(value1);
|
|
4
|
-
const type2 = getTypeName(value2);
|
|
5
|
-
if (type1 !== type2)
|
|
6
|
-
return false;
|
|
7
|
-
if (type1 === "array") {
|
|
8
|
-
if (value1.length !== value2.length)
|
|
9
|
-
return false;
|
|
10
|
-
return value1.every((item, i) => {
|
|
11
|
-
return isDeepEqual(item, value2[i]);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
if (type1 === "object") {
|
|
15
|
-
const keyArr = Object.keys(value1);
|
|
16
|
-
if (keyArr.length !== Object.keys(value2).length)
|
|
17
|
-
return false;
|
|
18
|
-
return keyArr.every((key) => {
|
|
19
|
-
return isDeepEqual(value1[key], value2[key]);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return Object.is(value1, value2);
|
|
23
|
-
}
|
package/dist/function.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Fn, Nullable } from '@stacksjs/types';
|
|
2
|
-
/**
|
|
3
|
-
* Call every function in an array
|
|
4
|
-
*/
|
|
5
|
-
export declare function batchInvoke(functions: Nullable<Fn>[]): void;
|
|
6
|
-
/**
|
|
7
|
-
* Pass the value through the callback, and return the value
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```
|
|
11
|
-
* function createUser(name: string): User {
|
|
12
|
-
* return tap(new User, user => {
|
|
13
|
-
* user.name = name
|
|
14
|
-
* })
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function tap<T>(value: T, callback: (value: T) => void): T;
|
package/dist/function.mjs
DELETED
package/dist/guards.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard to filter out null-ish values
|
|
3
|
-
*
|
|
4
|
-
* @category Guards
|
|
5
|
-
* @example array.filter(notNullish)
|
|
6
|
-
*/
|
|
7
|
-
export declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
|
8
|
-
/**
|
|
9
|
-
* Type guard to filter out null values
|
|
10
|
-
*
|
|
11
|
-
* @category Guards
|
|
12
|
-
* @example array.filter(noNull)
|
|
13
|
-
*/
|
|
14
|
-
export declare function noNull<T>(v: T | null): v is Exclude<T, null>;
|
|
15
|
-
/**
|
|
16
|
-
* Type guard to filter out null-ish values
|
|
17
|
-
*
|
|
18
|
-
* @category Guards
|
|
19
|
-
* @example array.filter(notUndefined)
|
|
20
|
-
*/
|
|
21
|
-
export declare function notUndefined<T>(v: T): v is Exclude<T, undefined>;
|
|
22
|
-
/**
|
|
23
|
-
* Type guard to filter out falsy values
|
|
24
|
-
*
|
|
25
|
-
* @category Guards
|
|
26
|
-
* @example array.filter(isTruthy)
|
|
27
|
-
*/
|
|
28
|
-
export declare function isTruthy<T>(v: T): v is NonNullable<T>;
|
package/dist/guards.mjs
DELETED
package/dist/helpers.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { CliOptions, CommandResult, Manifest, NpmScript } from '@stacksjs/types';
|
|
2
|
-
import detectIndent from 'detect-indent';
|
|
3
|
-
export declare function isProjectCreated(): Promise<boolean>;
|
|
4
|
-
export declare function installIfVersionMismatch(): Promise<void>;
|
|
5
|
-
export declare function frameworkVersion(): Promise<string>;
|
|
6
|
-
export declare function isAppKeySet(): Promise<boolean>;
|
|
7
|
-
/**
|
|
8
|
-
* Determines the utilized reset preset.
|
|
9
|
-
*
|
|
10
|
-
* @url https://www.npmjs.com/package/@unocss/reset
|
|
11
|
-
* @param preset
|
|
12
|
-
*/
|
|
13
|
-
export declare function determineResetPreset(preset?: string): string[];
|
|
14
|
-
/**
|
|
15
|
-
* Determines whether the specified value is a package manifest.
|
|
16
|
-
*/
|
|
17
|
-
export declare function isManifest(obj: any): obj is Manifest;
|
|
18
|
-
/**
|
|
19
|
-
* Determines whether the specified value is a string, null, or undefined.
|
|
20
|
-
*/
|
|
21
|
-
export declare function isOptionalString(value: any): value is string | undefined;
|
|
22
|
-
export declare function setEnvValue(key: string, value: string): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Runs the specified NPM script in the package.json file.
|
|
25
|
-
*/
|
|
26
|
-
export declare function runNpmScript(script: NpmScript, options?: CliOptions): Promise<CommandResult>;
|
|
27
|
-
/**
|
|
28
|
-
* Determines whether the specified NPM script exists in the given manifest.
|
|
29
|
-
*/
|
|
30
|
-
export declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
|
|
31
|
-
export declare function parseYaml(content: any): any;
|
|
32
|
-
/**
|
|
33
|
-
* Determines the level of debugging.
|
|
34
|
-
*
|
|
35
|
-
* The debug level is determined by the following:
|
|
36
|
-
* 1. The --verbose flag
|
|
37
|
-
* 2. The debug property in the app configuration
|
|
38
|
-
*
|
|
39
|
-
* Currently, we don't support a custom debug level,
|
|
40
|
-
* though, we would like to in the future.
|
|
41
|
-
*
|
|
42
|
-
* @param options
|
|
43
|
-
*/
|
|
44
|
-
export declare function determineDebugLevel(options?: CliOptions): boolean;
|
|
45
|
-
export { detectIndent };
|
|
46
|
-
export { detectNewline } from 'detect-newline';
|
package/dist/helpers.mjs
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import detectIndent from "detect-indent";
|
|
2
|
-
import { frameworkPath, projectPath } from "@stacksjs/path";
|
|
3
|
-
import { parse } from "yaml";
|
|
4
|
-
import { execSync, log, runCommand, spawn } from "@stacksjs/cli";
|
|
5
|
-
import { app, ui } from "@stacksjs/config";
|
|
6
|
-
import { storage } from "@stacksjs/storage";
|
|
7
|
-
import { semver } from "./versions.mjs";
|
|
8
|
-
export async function isProjectCreated() {
|
|
9
|
-
if (storage.isFile(".env"))
|
|
10
|
-
return await isAppKeySet();
|
|
11
|
-
if (storage.isFile(".env.example"))
|
|
12
|
-
await spawn("cp .env.example .env", { stdio: "inherit", cwd: projectPath() });
|
|
13
|
-
return await isAppKeySet();
|
|
14
|
-
}
|
|
15
|
-
export async function installIfVersionMismatch() {
|
|
16
|
-
const dependenciesYaml = storage.fs.readFileSync(projectPath("tea.yaml"), "utf8");
|
|
17
|
-
const dependencies = parseYaml(dependenciesYaml).dependencies;
|
|
18
|
-
const requiredNodeVersion = dependencies["nodejs.org"];
|
|
19
|
-
const requiredPnpmVersion = dependencies["pnpm.io"];
|
|
20
|
-
const installedNodeVersion = process.version;
|
|
21
|
-
const installedPnpmVersion = execSync("pnpm -v").trim();
|
|
22
|
-
if (!semver.satisfies(installedNodeVersion, requiredNodeVersion)) {
|
|
23
|
-
log.error(`Installed Node.js version (${installedNodeVersion}) does not satisfy required version (${requiredNodeVersion}). One moment...`);
|
|
24
|
-
await runCommand(`tea +nodejs.org${requiredNodeVersion} >/dev/null 2>&1`);
|
|
25
|
-
}
|
|
26
|
-
if (!semver.satisfies(installedPnpmVersion, requiredPnpmVersion)) {
|
|
27
|
-
log.error(`Installed pnpm version (${installedPnpmVersion}) does not satisfy required version (${requiredPnpmVersion}). One moment...`);
|
|
28
|
-
await runCommand(`tea +pnpm.io${requiredPnpmVersion} >/dev/null 2>&1`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export async function frameworkVersion() {
|
|
32
|
-
return (await storage.readPackageJson(frameworkPath("package.json"))).version;
|
|
33
|
-
}
|
|
34
|
-
export async function isAppKeySet() {
|
|
35
|
-
const env = await storage.readTextFile(".env", projectPath());
|
|
36
|
-
const lines = env.data.split("\n");
|
|
37
|
-
const appKey = lines.find((line) => line.startsWith("APP_KEY="));
|
|
38
|
-
return !!(appKey && appKey.length > 16);
|
|
39
|
-
}
|
|
40
|
-
export function determineResetPreset(preset) {
|
|
41
|
-
if (ui.reset)
|
|
42
|
-
preset = ui.reset;
|
|
43
|
-
if (preset === "tailwind")
|
|
44
|
-
return ["import '@unocss/reset/tailwind.css'"];
|
|
45
|
-
if (preset === "normalize")
|
|
46
|
-
return ["import '@unocss/reset/normalize.css'"];
|
|
47
|
-
if (preset === "sanitize")
|
|
48
|
-
return ["import '@unocss/reset/sanitize/sanitize.css'", "import '@unocss/reset/sanitize/assets.css"];
|
|
49
|
-
if (preset === "eric-meyer")
|
|
50
|
-
return ["import '@unocss/reset/eric-meyer.css'"];
|
|
51
|
-
if (preset === "antfu")
|
|
52
|
-
return ["import '@unocss/reset/antfu.css'"];
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
export function isManifest(obj) {
|
|
56
|
-
return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
|
|
57
|
-
}
|
|
58
|
-
export function isOptionalString(value) {
|
|
59
|
-
const type = typeof value;
|
|
60
|
-
return value === null || type === "undefined" || type === "string";
|
|
61
|
-
}
|
|
62
|
-
export async function setEnvValue(key, value) {
|
|
63
|
-
const file = await storage.readTextFile(projectPath(".env"));
|
|
64
|
-
await storage.writeTextFile({
|
|
65
|
-
path: projectPath(".env"),
|
|
66
|
-
data: file.data.replace(/APP_KEY=/g, `APP_KEY=${value}`)
|
|
67
|
-
// todo: do not hardcode the APP_KEY here and instead use the key parameter
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
export async function runNpmScript(script, options) {
|
|
71
|
-
const { data: manifest } = await storage.readJsonFile("package.json", frameworkPath());
|
|
72
|
-
if (isManifest(manifest) && hasScript(manifest, script))
|
|
73
|
-
return await runCommand(`pnpm run ${script}`, options);
|
|
74
|
-
log.error(`The specified npm script "${script}" does not exist in the package.json file`);
|
|
75
|
-
process.exit();
|
|
76
|
-
}
|
|
77
|
-
export function hasScript(manifest, script) {
|
|
78
|
-
const scripts = manifest.scripts;
|
|
79
|
-
if (scripts && typeof scripts === "object")
|
|
80
|
-
return Boolean(scripts[script]);
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
export function parseYaml(content) {
|
|
84
|
-
return parse(content);
|
|
85
|
-
}
|
|
86
|
-
export function determineDebugLevel(options) {
|
|
87
|
-
if (options?.verbose === true)
|
|
88
|
-
return true;
|
|
89
|
-
return app.debug === true;
|
|
90
|
-
}
|
|
91
|
-
export { detectIndent };
|
|
92
|
-
export { detectNewline } from "detect-newline";
|
package/dist/math.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const clamp: (n: number, min: number, max: number) => number;
|
|
2
|
-
export declare function rand(min: number, max: number): number;
|
|
3
|
-
export { and, createGenericProjection, createProjection, logicNot, logicOr, not, or, useAbs, useAverage, useCeil, useClamp, useFloor, useMath, useMax, useMin, usePrecision, useProjection, useRound, useSum, useTrunc, } from '@vueuse/math';
|
package/dist/math.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
2
|
-
export function rand(min, max) {
|
|
3
|
-
min = Math.ceil(min);
|
|
4
|
-
max = Math.floor(max);
|
|
5
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
6
|
-
}
|
|
7
|
-
export {
|
|
8
|
-
and,
|
|
9
|
-
createGenericProjection,
|
|
10
|
-
createProjection,
|
|
11
|
-
logicNot,
|
|
12
|
-
logicOr,
|
|
13
|
-
not,
|
|
14
|
-
or,
|
|
15
|
-
useAbs,
|
|
16
|
-
useAverage,
|
|
17
|
-
useCeil,
|
|
18
|
-
useClamp,
|
|
19
|
-
useFloor,
|
|
20
|
-
useMath,
|
|
21
|
-
useMax,
|
|
22
|
-
useMin,
|
|
23
|
-
usePrecision,
|
|
24
|
-
useProjection,
|
|
25
|
-
useRound,
|
|
26
|
-
useSum,
|
|
27
|
-
useTrunc
|
|
28
|
-
} from "@vueuse/math";
|
package/dist/p.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
interface POptions {
|
|
2
|
-
/**
|
|
3
|
-
* How many promises are resolved at the same time.
|
|
4
|
-
*/
|
|
5
|
-
concurrency?: number | undefined;
|
|
6
|
-
}
|
|
7
|
-
declare class PInstance<T = any> extends Promise<Awaited<T>[]> {
|
|
8
|
-
items: Iterable<T>;
|
|
9
|
-
options?: POptions | undefined;
|
|
10
|
-
private promises;
|
|
11
|
-
get promise(): Promise<Awaited<T>[]>;
|
|
12
|
-
constructor(items?: Iterable<T>, options?: POptions | undefined);
|
|
13
|
-
add(...args: (T | Promise<T>)[]): void;
|
|
14
|
-
map<U>(fn: (value: Awaited<T>, index: number) => U): PInstance<Promise<U>>;
|
|
15
|
-
filter(fn: (value: Awaited<T>, index: number) => boolean | Promise<boolean>): PInstance<Promise<T>>;
|
|
16
|
-
forEach(fn: (value: Awaited<T>, index: number) => void): Promise<void>;
|
|
17
|
-
reduce<U>(fn: (previousValue: U, currentValue: Awaited<T>, currentIndex: number, array: Awaited<T>[]) => U, initialValue: U): Promise<U>;
|
|
18
|
-
clear(): void;
|
|
19
|
-
then(fn?: () => PromiseLike<any>): Promise<any>;
|
|
20
|
-
catch(fn?: (err: unknown) => PromiseLike<any>): Promise<any>;
|
|
21
|
-
finally(fn?: () => void): Promise<Awaited<T>[]>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Utility for managing multiple promises.
|
|
25
|
-
*
|
|
26
|
-
* @see https://github.com/antfu/utils/tree/main/docs/p.md
|
|
27
|
-
* @category Promise
|
|
28
|
-
* @example
|
|
29
|
-
* ```
|
|
30
|
-
* import { p } from '@stacksjs/utils'
|
|
31
|
-
*
|
|
32
|
-
* const items = [1, 2, 3, 4, 5]
|
|
33
|
-
*
|
|
34
|
-
* await p(items)
|
|
35
|
-
* .map(async i => await multiply(i, 3))
|
|
36
|
-
* .filter(async i => await isEven(i))
|
|
37
|
-
* // [6, 12]
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function p<T = any>(items?: Iterable<T>, options?: POptions): PInstance<T>;
|
|
41
|
-
export {};
|
package/dist/p.mjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import pLimit from "p-limit";
|
|
2
|
-
const VOID = Symbol("p-void");
|
|
3
|
-
class PInstance extends Promise {
|
|
4
|
-
constructor(items = [], options) {
|
|
5
|
-
super(() => {
|
|
6
|
-
});
|
|
7
|
-
this.items = items;
|
|
8
|
-
this.options = options;
|
|
9
|
-
this.promises = /* @__PURE__ */ new Set();
|
|
10
|
-
}
|
|
11
|
-
get promise() {
|
|
12
|
-
let batch;
|
|
13
|
-
const items = [...Array.from(this.items), ...Array.from(this.promises)];
|
|
14
|
-
if (this.options?.concurrency) {
|
|
15
|
-
const limit = pLimit(this.options.concurrency);
|
|
16
|
-
batch = Promise.all(items.map((p2) => limit(() => p2)));
|
|
17
|
-
} else {
|
|
18
|
-
batch = Promise.all(items);
|
|
19
|
-
}
|
|
20
|
-
return batch.then((l) => l.filter((i) => i !== VOID));
|
|
21
|
-
}
|
|
22
|
-
add(...args) {
|
|
23
|
-
args.forEach((i) => {
|
|
24
|
-
this.promises.add(i);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
map(fn) {
|
|
28
|
-
return new PInstance(
|
|
29
|
-
Array.from(this.items).map(async (i, idx) => {
|
|
30
|
-
const v = await i;
|
|
31
|
-
if (v === VOID)
|
|
32
|
-
return VOID;
|
|
33
|
-
return fn(v, idx);
|
|
34
|
-
}),
|
|
35
|
-
this.options
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
filter(fn) {
|
|
39
|
-
return new PInstance(
|
|
40
|
-
Array.from(this.items).map(async (i, idx) => {
|
|
41
|
-
const v = await i;
|
|
42
|
-
const r = await fn(v, idx);
|
|
43
|
-
if (!r)
|
|
44
|
-
return VOID;
|
|
45
|
-
return v;
|
|
46
|
-
}),
|
|
47
|
-
this.options
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
forEach(fn) {
|
|
51
|
-
return this.map(fn).then();
|
|
52
|
-
}
|
|
53
|
-
reduce(fn, initialValue) {
|
|
54
|
-
return this.promise.then((array) => array.reduce(fn, initialValue));
|
|
55
|
-
}
|
|
56
|
-
clear() {
|
|
57
|
-
this.promises.clear();
|
|
58
|
-
}
|
|
59
|
-
then(fn) {
|
|
60
|
-
const p2 = this.promise;
|
|
61
|
-
if (fn)
|
|
62
|
-
return p2.then(fn);
|
|
63
|
-
return p2;
|
|
64
|
-
}
|
|
65
|
-
catch(fn) {
|
|
66
|
-
return this.promise.catch(fn);
|
|
67
|
-
}
|
|
68
|
-
finally(fn) {
|
|
69
|
-
return this.promise.finally(fn);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export function p(items, options) {
|
|
73
|
-
return new PInstance(items, options);
|
|
74
|
-
}
|
package/dist/promise.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Fn } from '@stacksjs/types';
|
|
2
|
-
export interface SingletonPromiseReturn<T> {
|
|
3
|
-
(): Promise<T>;
|
|
4
|
-
/**
|
|
5
|
-
* Reset current staled promise.
|
|
6
|
-
* Await it to have proper shutdown.
|
|
7
|
-
*/
|
|
8
|
-
reset: () => Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Promise with `resolve` and `reject` methods of itself
|
|
12
|
-
*/
|
|
13
|
-
export interface ControlledPromise<T = void> extends Promise<T> {
|
|
14
|
-
resolve(value: T | PromiseLike<T>): void;
|
|
15
|
-
reject(reason?: any): void;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Create singleton promise function.
|
|
19
|
-
*
|
|
20
|
-
* @category Promise
|
|
21
|
-
*/
|
|
22
|
-
export declare function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromiseReturn<T>;
|
|
23
|
-
/**
|
|
24
|
-
* Create a promise lock.
|
|
25
|
-
*
|
|
26
|
-
* @category Promise
|
|
27
|
-
* @example
|
|
28
|
-
* ```
|
|
29
|
-
* const lock = createPromiseLock()
|
|
30
|
-
*
|
|
31
|
-
* lock.run(async () => {
|
|
32
|
-
* await doSomething()
|
|
33
|
-
* })
|
|
34
|
-
*
|
|
35
|
-
* // in anther context:
|
|
36
|
-
* await lock.wait() // it will wait all tasking finished
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function createPromiseLock(): {
|
|
40
|
-
run<T = void>(fn: () => Promise<T>): Promise<T>;
|
|
41
|
-
wait(): Promise<void>;
|
|
42
|
-
isWaiting(): boolean;
|
|
43
|
-
clear(): void;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Return a Promise with `resolve` and `reject` methods
|
|
47
|
-
*
|
|
48
|
-
* @category Promise
|
|
49
|
-
* @example
|
|
50
|
-
* ```
|
|
51
|
-
* const promise = createControlledPromise()
|
|
52
|
-
*
|
|
53
|
-
* await promise
|
|
54
|
-
*
|
|
55
|
-
* // in anther context:
|
|
56
|
-
* promise.resolve(data)
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
export declare function createControlledPromise<T>(): ControlledPromise<T>;
|
|
60
|
-
/**
|
|
61
|
-
* Promised `setTimeout`.
|
|
62
|
-
*
|
|
63
|
-
* @category Promise
|
|
64
|
-
*/
|
|
65
|
-
export declare function sleep(ms: number, callback?: Fn<any>): Promise<void>;
|
package/dist/promise.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { remove } from "@stacksjs/arrays";
|
|
2
|
-
export function createSingletonPromise(fn) {
|
|
3
|
-
let _promise;
|
|
4
|
-
function wrapper() {
|
|
5
|
-
if (!_promise)
|
|
6
|
-
_promise = fn();
|
|
7
|
-
return _promise;
|
|
8
|
-
}
|
|
9
|
-
wrapper.reset = async () => {
|
|
10
|
-
const _prev = _promise;
|
|
11
|
-
_promise = void 0;
|
|
12
|
-
if (_prev)
|
|
13
|
-
await _prev;
|
|
14
|
-
};
|
|
15
|
-
return wrapper;
|
|
16
|
-
}
|
|
17
|
-
export function createPromiseLock() {
|
|
18
|
-
const locks = [];
|
|
19
|
-
return {
|
|
20
|
-
async run(fn) {
|
|
21
|
-
const p = fn();
|
|
22
|
-
locks.push(p);
|
|
23
|
-
try {
|
|
24
|
-
return await p;
|
|
25
|
-
} finally {
|
|
26
|
-
remove(locks, p);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
async wait() {
|
|
30
|
-
await Promise.allSettled(locks);
|
|
31
|
-
},
|
|
32
|
-
isWaiting() {
|
|
33
|
-
return Boolean(locks.length);
|
|
34
|
-
},
|
|
35
|
-
clear() {
|
|
36
|
-
locks.length = 0;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export function createControlledPromise() {
|
|
41
|
-
let resolve, reject;
|
|
42
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
43
|
-
resolve = _resolve;
|
|
44
|
-
reject = _reject;
|
|
45
|
-
});
|
|
46
|
-
promise.resolve = resolve;
|
|
47
|
-
promise.reject = reject;
|
|
48
|
-
return promise;
|
|
49
|
-
}
|
|
50
|
-
export function sleep(ms, callback) {
|
|
51
|
-
return new Promise(
|
|
52
|
-
(resolve) => setTimeout(async () => {
|
|
53
|
-
await callback?.();
|
|
54
|
-
resolve();
|
|
55
|
-
}, ms)
|
|
56
|
-
);
|
|
57
|
-
}
|
package/dist/throttle.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throttle a function.
|
|
3
|
-
*
|
|
4
|
-
* @param fn
|
|
5
|
-
* @param wait
|
|
6
|
-
* @returns
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // logs window dimensions at most every 250ms
|
|
11
|
-
* window.addEventListener(
|
|
12
|
-
* "resize",
|
|
13
|
-
* throttle(function (evt) {
|
|
14
|
-
* console.log(window.innerWidth)
|
|
15
|
-
* console.log(window.innerHeight)
|
|
16
|
-
* }, 250)
|
|
17
|
-
* )
|
|
18
|
-
*/
|
|
19
|
-
export declare function throttle(fn: Function, wait?: number): (this: unknown, ...args: any[]) => void;
|
package/dist/throttle.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function throttle(fn, wait = 300) {
|
|
2
|
-
let inThrottle;
|
|
3
|
-
let lastFn;
|
|
4
|
-
let lastTime;
|
|
5
|
-
return function(...args) {
|
|
6
|
-
if (!inThrottle) {
|
|
7
|
-
fn.apply(this, args);
|
|
8
|
-
lastTime = Date.now();
|
|
9
|
-
inThrottle = true;
|
|
10
|
-
} else {
|
|
11
|
-
clearTimeout(lastFn);
|
|
12
|
-
lastFn = setTimeout(() => {
|
|
13
|
-
if (Date.now() - lastTime >= wait) {
|
|
14
|
-
fn.apply(this, args);
|
|
15
|
-
lastTime = Date.now();
|
|
16
|
-
}
|
|
17
|
-
}, Math.max(wait - (Date.now() - lastTime), 0));
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
package/dist/vendors.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { asyncComputed, breakpointsAntDesign, breakpointsBootstrapV5, breakpointsMasterCss, breakpointsQuasar, breakpointsSematic, breakpointsTailwind, breakpointsVuetify, cloneFnJSON, computedAsync, computedInject, createFetch, createReusableTemplate, createTemplatePromise, createUnrefFn, customStorageEventName, defaultDocument, defaultLocation, defaultNavigator, defaultWindow, executeTransition, formatTimeAgo, getSSRHandler, mapGamepadToXbox360Controller, onClickOutside, onKeyDown, onKeyPressed, onKeyStroke, onKeyUp, onLongPress, onStartTyping, setSSRHandler, templateRef, unrefElement, useActiveElement, useAnimate, useAsyncQueue, useAsyncState, useBase64, useBattery, useBluetooth, useBreakpoints, useBroadcastChannel, useBrowserLocation, useCached, useClipboard, useCloned, useColorMode, useConfirmDialog, useCssVar, useCurrentElement, useCycleList, useDark, useDebouncedRefHistory, useDeviceMotion, useDeviceOrientation, useDevicePixelRatio, useDevicesList, useDisplayMedia, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementHover, useElementSize, useElementVisibility, useEventBus, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetch, useFileDialog, useFileSystemAccess, useFocus, useFocusWithin, useFps, useFullscreen, useGamepad, useGeolocation, useIdle, useImage, useInfiniteScroll, useIntersectionObserver, useKeyModifier, useLocalStorage, useMagicKeys, useManualRefHistory, useMediaControls, useMediaQuery, useMemoize, useMemory, useMounted, useMouse, useMouseInElement, useMousePressed, useMutationObserver, useNavigatorLanguage, useNetwork, useObjectUrl, useOffsetPagination, useOnline, usePageLeave, useParallax, useParentElement, usePerformanceObserver, usePermission, usePointer, usePointerLock, usePointerSwipe, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePreferredReducedMotion, usePrevious, useRafFn, useRefHistory, useResizeObserver, useScreenOrientation, useScreenSafeArea, useScriptTag, useScroll, useScrollLock, useSessionStorage, useShare, useSorted, useSpeechRecognition, useSpeechSynthesis, useStepper, useStorage, useStorageAsync, useStyleTag, useSupported, useSwipe, useTemplateRefsList, useTextDirection, useTextSelection, useTextareaAutosize, useThrottledRefHistory, useTimeAgo, useTimeoutPoll, useTimestamp, useTitle, useTransition, useToggle, useUrlSearchParams, useUserMedia, useVModel, useVModels, useVibrate, useVirtualList, useWakeLock, useWebNotification, useWebSocket, useWebWorker, useWebWorkerFn, useWindowFocus, useWindowScroll, useWindowSize, useDateFormat, useNow, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever, syncRef, syncRefs, throttledRef, throttledWatch, toReactive, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, isDefined, ignorableWatch, extendRef, eagerComputed, debouncedRef, debouncedWatch, createReactiveFn, createSharedComposable, createInjectionState, createGlobalState, createEventHook, controlledRef, controlledComputed, computedEager, computedWithControl, autoResetRef, } from '@vueuse/core';
|
|
2
|
-
export type { HeadClient, HeadObject, HeadObjectPlain, HookBeforeDomUpdate, HookEntriesResolved, HookTagsResolved, LegacyHeadOptions, } from '@vueuse/head';
|
|
3
|
-
export { Head, HeadVuePlugin, createHead, renderHeadToString, } from '@vueuse/head';
|