@stacksjs/utils 0.51.0 → 0.52.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/base.d.ts +5 -5
- package/dist/base.mjs +11 -9
- package/dist/config.d.ts +23 -0
- package/dist/config.mjs +66 -0
- package/dist/debounce.d.ts +1 -0
- package/dist/debounce.mjs +1 -0
- package/dist/guards.d.ts +0 -1
- package/dist/guards.mjs +0 -3
- package/dist/helpers.d.ts +16 -5
- package/dist/helpers.mjs +14 -15
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +6 -3
- package/dist/is.d.ts +26 -10
- package/dist/is.mjs +80 -11
- package/dist/throttle.d.ts +19 -0
- package/dist/throttle.mjs +22 -0
- package/package.json +52 -28
- package/dist/vendor.d.ts +0 -1
- package/dist/vendor.mjs +0 -1
package/dist/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
1
|
+
export declare function assert(condition: boolean, message: string): asserts condition;
|
|
2
|
+
export declare function toString(v: any): any;
|
|
3
|
+
export declare function noop(): void;
|
|
4
|
+
export declare function loop(times: number, callback: any): void;
|
|
5
|
+
export declare function getTypeName(v: any): any;
|
package/dist/base.mjs
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function assert(condition, message) {
|
|
2
2
|
if (!condition)
|
|
3
3
|
throw new Error(message);
|
|
4
|
-
}
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export
|
|
4
|
+
}
|
|
5
|
+
export function toString(v) {
|
|
6
|
+
return Object.prototype.toString.call(v);
|
|
7
|
+
}
|
|
8
|
+
export function noop() {
|
|
9
|
+
}
|
|
10
|
+
export function loop(times, callback) {
|
|
9
11
|
[...Array(times)].forEach((item, i) => callback(i));
|
|
10
|
-
}
|
|
11
|
-
export
|
|
12
|
+
}
|
|
13
|
+
export function getTypeName(v) {
|
|
12
14
|
if (v === null)
|
|
13
15
|
return "null";
|
|
14
16
|
const type = toString(v).slice(8, -1).toLowerCase();
|
|
15
17
|
return typeof v === "object" || typeof v === "function" ? type : typeof v;
|
|
16
|
-
}
|
|
18
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { UserCliOptions, AppOptions, CacheOptions, CdnOptions, CronJobOptions, DatabaseOptions, DebugOptions, DnsOptions, EmailOptions, Events, GitOptions, HashingOptions, LibraryOptions, Model, NotificationOptions, PagesOption, PaymentOptions, SearchEngineOptions, ServicesOptions, StorageOptions, UiOptions } from '@stacksjs/types';
|
|
2
|
+
export declare function env(key: any, fallback?: any): any;
|
|
3
|
+
export declare function defineApp(options: Partial<AppOptions>): Partial<AppOptions>;
|
|
4
|
+
export declare function defineCache(options: Partial<CacheOptions>): Partial<CacheOptions>;
|
|
5
|
+
export declare function defineCdn(options: Partial<CdnOptions>): Partial<CdnOptions>;
|
|
6
|
+
export declare function defineCli(options: Partial<UserCliOptions>): Partial<UserCliOptions>;
|
|
7
|
+
export declare function defineCronJobsConfig(options: Partial<CronJobOptions>[]): Partial<CronJobOptions>[];
|
|
8
|
+
export declare function defineDatabase(options: Partial<DatabaseOptions>): Partial<DatabaseOptions>;
|
|
9
|
+
export declare function defineDebugConfig(options: Partial<DebugOptions>): Partial<DebugOptions>;
|
|
10
|
+
export declare function defineDns(options: Partial<DnsOptions>): Partial<DnsOptions>;
|
|
11
|
+
export declare function defineEmailConfig(options: Partial<EmailOptions>): Partial<EmailOptions>;
|
|
12
|
+
export declare function defineEvents(options: Partial<Events>): Partial<Events>;
|
|
13
|
+
export declare function defineGit(options: Partial<GitOptions>): Partial<GitOptions>;
|
|
14
|
+
export declare function defineHashing(options: Partial<HashingOptions>): Partial<HashingOptions>;
|
|
15
|
+
export declare function defineLibrary(options: Partial<LibraryOptions>): Partial<LibraryOptions>;
|
|
16
|
+
export declare function defineModel(options: Partial<Model>): Partial<Model>;
|
|
17
|
+
export declare function defineNotification(options: Partial<NotificationOptions>): Partial<NotificationOptions>;
|
|
18
|
+
export declare function definePage(options: Partial<PagesOption>): Partial<PagesOption>;
|
|
19
|
+
export declare function definePayment(options: Partial<PaymentOptions>): Partial<PaymentOptions>;
|
|
20
|
+
export declare function defineSearchEngine(options: Partial<SearchEngineOptions>): Partial<SearchEngineOptions>;
|
|
21
|
+
export declare function defineServices(options: Partial<ServicesOptions>): Partial<ServicesOptions>;
|
|
22
|
+
export declare function defineStorage(options: Partial<StorageOptions>): Partial<StorageOptions>;
|
|
23
|
+
export declare function defineUi(options: Partial<UiOptions>): Partial<UiOptions>;
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function env(key, fallback) {
|
|
2
|
+
return key;
|
|
3
|
+
}
|
|
4
|
+
export function defineApp(options) {
|
|
5
|
+
return options;
|
|
6
|
+
}
|
|
7
|
+
export function defineCache(options) {
|
|
8
|
+
return options;
|
|
9
|
+
}
|
|
10
|
+
export function defineCdn(options) {
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
13
|
+
export function defineCli(options) {
|
|
14
|
+
return options;
|
|
15
|
+
}
|
|
16
|
+
export function defineCronJobsConfig(options) {
|
|
17
|
+
return options;
|
|
18
|
+
}
|
|
19
|
+
export function defineDatabase(options) {
|
|
20
|
+
return options;
|
|
21
|
+
}
|
|
22
|
+
export function defineDebugConfig(options) {
|
|
23
|
+
return options;
|
|
24
|
+
}
|
|
25
|
+
export function defineDns(options) {
|
|
26
|
+
return options;
|
|
27
|
+
}
|
|
28
|
+
export function defineEmailConfig(options) {
|
|
29
|
+
return options;
|
|
30
|
+
}
|
|
31
|
+
export function defineEvents(options) {
|
|
32
|
+
return options;
|
|
33
|
+
}
|
|
34
|
+
export function defineGit(options) {
|
|
35
|
+
return options;
|
|
36
|
+
}
|
|
37
|
+
export function defineHashing(options) {
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
export function defineLibrary(options) {
|
|
41
|
+
return options;
|
|
42
|
+
}
|
|
43
|
+
export function defineModel(options) {
|
|
44
|
+
return options;
|
|
45
|
+
}
|
|
46
|
+
export function defineNotification(options) {
|
|
47
|
+
return options;
|
|
48
|
+
}
|
|
49
|
+
export function definePage(options) {
|
|
50
|
+
return options;
|
|
51
|
+
}
|
|
52
|
+
export function definePayment(options) {
|
|
53
|
+
return options;
|
|
54
|
+
}
|
|
55
|
+
export function defineSearchEngine(options) {
|
|
56
|
+
return options;
|
|
57
|
+
}
|
|
58
|
+
export function defineServices(options) {
|
|
59
|
+
return options;
|
|
60
|
+
}
|
|
61
|
+
export function defineStorage(options) {
|
|
62
|
+
return options;
|
|
63
|
+
}
|
|
64
|
+
export function defineUi(options) {
|
|
65
|
+
return options;
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { debounce } from 'perfect-debounce';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { debounce } from "perfect-debounce";
|
package/dist/guards.d.ts
CHANGED
package/dist/guards.mjs
CHANGED
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CliOptions, Manifest, NpmScript } from '@stacksjs/types';
|
|
1
|
+
import type { CliOptions, CommandResult, Manifest, NpmScript } from '@stacksjs/types';
|
|
2
2
|
import detectIndent from 'detect-indent';
|
|
3
3
|
export declare function isProjectCreated(): Promise<boolean>;
|
|
4
4
|
export declare function frameworkVersion(): Promise<string>;
|
|
@@ -10,8 +10,6 @@ export declare function isAppKeySet(): Promise<boolean>;
|
|
|
10
10
|
* @param preset
|
|
11
11
|
*/
|
|
12
12
|
export declare function determineResetPreset(preset?: string): string[];
|
|
13
|
-
export declare function env(key?: string, fallback?: any): any;
|
|
14
|
-
export declare function config(key?: string, fallback?: string): void;
|
|
15
13
|
/**
|
|
16
14
|
* Determines whether the specified value is a package manifest.
|
|
17
15
|
*/
|
|
@@ -24,12 +22,25 @@ export declare function setEnvValue(key: string, value: string): Promise<void>;
|
|
|
24
22
|
/**
|
|
25
23
|
* Runs the specified NPM script in the package.json file.
|
|
26
24
|
*/
|
|
27
|
-
export declare function runNpmScript(script: NpmScript, options?: CliOptions): Promise<
|
|
25
|
+
export declare function runNpmScript(script: NpmScript, options?: CliOptions): Promise<CommandResult>;
|
|
28
26
|
/**
|
|
29
27
|
* Determines whether the specified NPM script exists in the given manifest.
|
|
30
28
|
*/
|
|
31
29
|
export declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
|
|
32
|
-
export
|
|
30
|
+
export declare function parseYaml(content: any): any;
|
|
31
|
+
/**
|
|
32
|
+
* Determines the level of debugging.
|
|
33
|
+
*
|
|
34
|
+
* The debug level is determined by the following:
|
|
35
|
+
* 1. The --verbose flag
|
|
36
|
+
* 2. The debug property in the app configuration
|
|
37
|
+
*
|
|
38
|
+
* Currently, we don't support a custom debug level,
|
|
39
|
+
* though, we would like to in the future.
|
|
40
|
+
*
|
|
41
|
+
* @param options
|
|
42
|
+
*/
|
|
43
|
+
export declare function determineDebugLevel(options?: CliOptions): boolean;
|
|
33
44
|
export * from 'dinero.js';
|
|
34
45
|
export { detectIndent };
|
|
35
46
|
export { detectNewline } from 'detect-newline';
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import detectIndent from "detect-indent";
|
|
2
2
|
import { frameworkPath, projectPath } from "@stacksjs/path";
|
|
3
|
+
import { parse } from "yaml";
|
|
4
|
+
import { log, runCommand, spawn } from "@stacksjs/cli";
|
|
3
5
|
import storage from "@stacksjs/storage";
|
|
4
|
-
import { ui } from "@stacksjs/config";
|
|
5
|
-
import detectIndent from "detect-indent";
|
|
6
|
+
import { ui, app } from "@stacksjs/config";
|
|
6
7
|
export async function isProjectCreated() {
|
|
7
8
|
if (storage.isFile(".env"))
|
|
8
9
|
return await isAppKeySet();
|
|
@@ -15,8 +16,8 @@ export async function frameworkVersion() {
|
|
|
15
16
|
return packageJson.version;
|
|
16
17
|
}
|
|
17
18
|
export async function isAppKeySet() {
|
|
18
|
-
const
|
|
19
|
-
const lines =
|
|
19
|
+
const env = await storage.readTextFile(".env", projectPath());
|
|
20
|
+
const lines = env.data.split("\n");
|
|
20
21
|
const appKey = lines.find((line) => line.startsWith("APP_KEY="));
|
|
21
22
|
if (appKey && appKey.length > 16)
|
|
22
23
|
return true;
|
|
@@ -37,15 +38,6 @@ export function determineResetPreset(preset) {
|
|
|
37
38
|
return ["import '@unocss/reset/antfu.css'"];
|
|
38
39
|
return [];
|
|
39
40
|
}
|
|
40
|
-
export function env(key, fallback) {
|
|
41
|
-
if (key && import.meta?.env) {
|
|
42
|
-
return import.meta.env[key];
|
|
43
|
-
}
|
|
44
|
-
return fallback;
|
|
45
|
-
}
|
|
46
|
-
export function config(key, fallback) {
|
|
47
|
-
console.log("key", key, "fallback", fallback);
|
|
48
|
-
}
|
|
49
41
|
export function isManifest(obj) {
|
|
50
42
|
return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
|
|
51
43
|
}
|
|
@@ -74,7 +66,14 @@ export function hasScript(manifest, script) {
|
|
|
74
66
|
return Boolean(scripts[script]);
|
|
75
67
|
return false;
|
|
76
68
|
}
|
|
77
|
-
export
|
|
69
|
+
export function parseYaml(content) {
|
|
70
|
+
return parse(content);
|
|
71
|
+
}
|
|
72
|
+
export function determineDebugLevel(options) {
|
|
73
|
+
if (options?.verbose === true)
|
|
74
|
+
return true;
|
|
75
|
+
return app.debug === true;
|
|
76
|
+
}
|
|
78
77
|
export * from "dinero.js";
|
|
79
78
|
export { detectIndent };
|
|
80
79
|
export { detectNewline } from "detect-newline";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export { assert, toString, noop, loop, getTypeName } from './base';
|
|
2
|
+
export * from './config';
|
|
3
|
+
export * from './debounce';
|
|
2
4
|
export * from './equal';
|
|
3
|
-
export * from './helpers';
|
|
4
|
-
export type { SingletonPromiseReturn, ControlledPromise } from './promise';
|
|
5
|
-
export { createSingletonPromise, createPromiseLock, createControlledPromise, sleep } from './promise';
|
|
6
5
|
export * from './function';
|
|
7
6
|
export * from './guards';
|
|
7
|
+
export * from './helpers';
|
|
8
8
|
export { isDef, isBoolean, isFunction, isNumber, isString, isObject, isWindow, isBrowser, isServer, isMap, isSet, isPromise } from './is';
|
|
9
9
|
export * from './p';
|
|
10
|
-
export
|
|
10
|
+
export type { SingletonPromiseReturn, ControlledPromise } from './promise';
|
|
11
|
+
export { createSingletonPromise, createPromiseLock, createControlledPromise, sleep } from './promise';
|
|
12
|
+
export * as semver from 'semver';
|
|
13
|
+
export * from './throttle';
|
|
11
14
|
export * from '@vueuse/core';
|
|
12
15
|
export * from '@vueuse/math';
|
|
13
16
|
export * from '@vueuse/shared';
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
export { assert, toString, noop, loop, getTypeName } from "./base.mjs";
|
|
2
|
+
export * from "./config.mjs";
|
|
3
|
+
export * from "./debounce.mjs";
|
|
2
4
|
export * from "./equal.mjs";
|
|
3
|
-
export * from "./helpers.mjs";
|
|
4
|
-
export { createSingletonPromise, createPromiseLock, createControlledPromise, sleep } from "./promise.mjs";
|
|
5
5
|
export * from "./function.mjs";
|
|
6
6
|
export * from "./guards.mjs";
|
|
7
|
+
export * from "./helpers.mjs";
|
|
7
8
|
export { isDef, isBoolean, isFunction, isNumber, isString, isObject, isWindow, isBrowser, isServer, isMap, isSet, isPromise } from "./is.mjs";
|
|
8
9
|
export * from "./p.mjs";
|
|
9
|
-
export
|
|
10
|
+
export { createSingletonPromise, createPromiseLock, createControlledPromise, sleep } from "./promise.mjs";
|
|
11
|
+
export * as semver from "semver";
|
|
12
|
+
export * from "./throttle.mjs";
|
|
10
13
|
export * from "@vueuse/core";
|
|
11
14
|
export * from "@vueuse/math";
|
|
12
15
|
export * from "@vueuse/shared";
|
package/dist/is.d.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
1
|
+
export declare function isDef<T = any>(val?: T): val is T;
|
|
2
|
+
export declare function isBoolean(val: any): val is boolean;
|
|
3
|
+
export declare function isFunction<T extends Function>(val: any): val is T;
|
|
4
|
+
export declare function isNumber(val: any): val is number;
|
|
5
|
+
export declare function isString(val: unknown): val is string;
|
|
6
|
+
export declare function isObject(val: any): val is object;
|
|
7
|
+
export declare function isWindow(val: any): boolean;
|
|
8
8
|
export declare const isBrowser: boolean;
|
|
9
9
|
export declare const isServer: boolean;
|
|
10
|
-
export declare
|
|
11
|
-
export declare
|
|
12
|
-
export declare
|
|
10
|
+
export declare function isMap(val: any): val is Map<any, any>;
|
|
11
|
+
export declare function isSet(val: any): val is Set<any>;
|
|
12
|
+
export declare function isPromise<T = any>(val: any): val is Promise<T>;
|
|
13
|
+
export declare function isUndefined(v: any): boolean;
|
|
14
|
+
export declare function isNull(v: any): boolean;
|
|
15
|
+
export declare function isSymbol(v: any): boolean;
|
|
16
|
+
export declare function isDate(v: any): boolean;
|
|
17
|
+
export declare function isRegExp(v: any): boolean;
|
|
18
|
+
export declare function isArray(v: any): boolean;
|
|
19
|
+
export declare function isPrimitive(v: any): boolean;
|
|
20
|
+
export declare function isInteger(v: any): boolean;
|
|
21
|
+
export declare function isFloat(v: any): boolean;
|
|
22
|
+
export declare function isPositive(v: any): boolean;
|
|
23
|
+
export declare function isNegative(v: any): boolean;
|
|
24
|
+
export declare function isEven(v: any): boolean;
|
|
25
|
+
export declare function isOdd(v: any): boolean;
|
|
26
|
+
export declare function isEvenOrOdd(v: any): false | "even" | "odd";
|
|
27
|
+
export declare function isPositiveOrNegative(v: any): false | "positive" | "negative";
|
|
28
|
+
export declare function isIntegerOrFloat(v: any): false | "integer" | "float";
|
package/dist/is.mjs
CHANGED
|
@@ -1,13 +1,82 @@
|
|
|
1
|
-
import { toString } from "./base.mjs";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
1
|
+
import { getTypeName, toString } from "./base.mjs";
|
|
2
|
+
export function isDef(val) {
|
|
3
|
+
return typeof val !== "undefined";
|
|
4
|
+
}
|
|
5
|
+
export function isBoolean(val) {
|
|
6
|
+
return typeof val === "boolean";
|
|
7
|
+
}
|
|
8
|
+
export function isFunction(val) {
|
|
9
|
+
return typeof val === "function";
|
|
10
|
+
}
|
|
11
|
+
export function isNumber(val) {
|
|
12
|
+
return typeof val === "number";
|
|
13
|
+
}
|
|
14
|
+
export function isString(val) {
|
|
15
|
+
return typeof val === "string";
|
|
16
|
+
}
|
|
17
|
+
export function isObject(val) {
|
|
18
|
+
return toString(val) === "[object Object]";
|
|
19
|
+
}
|
|
20
|
+
export function isWindow(val) {
|
|
21
|
+
return typeof window !== "undefined" && toString(val) === "[object Window]";
|
|
22
|
+
}
|
|
9
23
|
export const isBrowser = typeof window !== "undefined";
|
|
10
24
|
export const isServer = typeof document === "undefined";
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
export function isMap(val) {
|
|
26
|
+
return toString(val) === "[object Map]";
|
|
27
|
+
}
|
|
28
|
+
export function isSet(val) {
|
|
29
|
+
return toString(val) === "[object Set]";
|
|
30
|
+
}
|
|
31
|
+
export function isPromise(val) {
|
|
32
|
+
return toString(val) === "[object Promise]";
|
|
33
|
+
}
|
|
34
|
+
export function isUndefined(v) {
|
|
35
|
+
return getTypeName(v) === "undefined";
|
|
36
|
+
}
|
|
37
|
+
export function isNull(v) {
|
|
38
|
+
return getTypeName(v) === "null";
|
|
39
|
+
}
|
|
40
|
+
export function isSymbol(v) {
|
|
41
|
+
return getTypeName(v) === "symbol";
|
|
42
|
+
}
|
|
43
|
+
export function isDate(v) {
|
|
44
|
+
return getTypeName(v) === "date";
|
|
45
|
+
}
|
|
46
|
+
export function isRegExp(v) {
|
|
47
|
+
return getTypeName(v) === "regexp";
|
|
48
|
+
}
|
|
49
|
+
export function isArray(v) {
|
|
50
|
+
return getTypeName(v) === "array";
|
|
51
|
+
}
|
|
52
|
+
export function isPrimitive(v) {
|
|
53
|
+
const type = getTypeName(v);
|
|
54
|
+
return type === "null" || type === "undefined" || type === "string" || type === "number" || type === "boolean" || type === "symbol";
|
|
55
|
+
}
|
|
56
|
+
export function isInteger(v) {
|
|
57
|
+
return isNumber(v) && Number.isInteger(v);
|
|
58
|
+
}
|
|
59
|
+
export function isFloat(v) {
|
|
60
|
+
return isNumber(v) && !Number.isInteger(v);
|
|
61
|
+
}
|
|
62
|
+
export function isPositive(v) {
|
|
63
|
+
return isNumber(v) && v > 0;
|
|
64
|
+
}
|
|
65
|
+
export function isNegative(v) {
|
|
66
|
+
return isNumber(v) && v < 0;
|
|
67
|
+
}
|
|
68
|
+
export function isEven(v) {
|
|
69
|
+
return isNumber(v) && v % 2 === 0;
|
|
70
|
+
}
|
|
71
|
+
export function isOdd(v) {
|
|
72
|
+
return isNumber(v) && v % 2 !== 0;
|
|
73
|
+
}
|
|
74
|
+
export function isEvenOrOdd(v) {
|
|
75
|
+
return isNumber(v) && (v % 2 === 0 ? "even" : "odd");
|
|
76
|
+
}
|
|
77
|
+
export function isPositiveOrNegative(v) {
|
|
78
|
+
return isNumber(v) && (v > 0 ? "positive" : "negative");
|
|
79
|
+
}
|
|
80
|
+
export function isIntegerOrFloat(v) {
|
|
81
|
+
return isNumber(v) && (Number.isInteger(v) ? "integer" : "float");
|
|
82
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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: any) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function throttle(fn, wait = 300) {
|
|
2
|
+
let inThrottle;
|
|
3
|
+
let lastFn;
|
|
4
|
+
let lastTime;
|
|
5
|
+
return function() {
|
|
6
|
+
const context = this;
|
|
7
|
+
const args = arguments;
|
|
8
|
+
if (!inThrottle) {
|
|
9
|
+
fn.apply(context, args);
|
|
10
|
+
lastTime = Date.now();
|
|
11
|
+
inThrottle = true;
|
|
12
|
+
} else {
|
|
13
|
+
clearTimeout(lastFn);
|
|
14
|
+
lastFn = setTimeout(() => {
|
|
15
|
+
if (Date.now() - lastTime >= wait) {
|
|
16
|
+
fn.apply(context, args);
|
|
17
|
+
lastTime = Date.now();
|
|
18
|
+
}
|
|
19
|
+
}, Math.max(wait - (Date.now() - lastTime), 0));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@
|
|
4
|
+
"version": "0.52.0",
|
|
5
|
+
"packageManager": "pnpm@8.5.1",
|
|
6
6
|
"description": "The Stacks helper functions.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -26,6 +26,12 @@
|
|
|
26
26
|
"functions",
|
|
27
27
|
"stacks"
|
|
28
28
|
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.mjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
29
35
|
"main": "dist/index.mjs",
|
|
30
36
|
"module": "dist/index.mjs",
|
|
31
37
|
"types": "dist/index.d.ts",
|
|
@@ -36,42 +42,60 @@
|
|
|
36
42
|
"dist",
|
|
37
43
|
"README.md"
|
|
38
44
|
],
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">=v18.14.0",
|
|
41
|
-
"pnpm": ">=7.26.3"
|
|
42
|
-
},
|
|
43
45
|
"peerDependencies": {
|
|
44
|
-
"@vueuse/core": "^
|
|
45
|
-
"@vueuse/head": "^1.
|
|
46
|
-
"@vueuse/math": "^
|
|
47
|
-
"@vueuse/shared": "^
|
|
46
|
+
"@vueuse/core": "^10.1.2",
|
|
47
|
+
"@vueuse/head": "^1.1.26",
|
|
48
|
+
"@vueuse/math": "^10.1.2",
|
|
49
|
+
"@vueuse/shared": "^10.1.2",
|
|
50
|
+
"defu": "^6.1.2",
|
|
51
|
+
"detect-indent": "^7.0.1",
|
|
52
|
+
"detect-newline": "^4.0.0",
|
|
53
|
+
"dinero.js": "2.0.0-alpha.14",
|
|
54
|
+
"fast-glob": "^3.2.12",
|
|
55
|
+
"kolorist": "1.8.0",
|
|
56
|
+
"p-limit": "^4.0.0",
|
|
57
|
+
"rimraf": "^5.0.0",
|
|
58
|
+
"semver": "^7.5.1",
|
|
59
|
+
"yaml": "^2.2.2",
|
|
60
|
+
"@stacksjs/arrays": "0.52.0",
|
|
61
|
+
"@stacksjs/cli": "0.52.0",
|
|
62
|
+
"@stacksjs/config": "0.52.0",
|
|
63
|
+
"@stacksjs/development": "0.52.0",
|
|
64
|
+
"@stacksjs/lint": "0.52.0",
|
|
65
|
+
"@stacksjs/path": "0.52.0",
|
|
66
|
+
"@stacksjs/storage": "0.52.0",
|
|
67
|
+
"@stacksjs/types": "0.52.0"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@vueuse/core": "^10.1.2",
|
|
71
|
+
"@vueuse/head": "^1.1.26",
|
|
72
|
+
"@vueuse/math": "^10.1.2",
|
|
73
|
+
"@vueuse/shared": "^10.1.2",
|
|
48
74
|
"defu": "^6.1.2",
|
|
49
75
|
"detect-indent": "^7.0.1",
|
|
50
76
|
"detect-newline": "^4.0.0",
|
|
51
|
-
"dinero.js": "2.0.0-alpha.
|
|
52
|
-
"esno": "^0.16.3",
|
|
77
|
+
"dinero.js": "2.0.0-alpha.14",
|
|
53
78
|
"fast-glob": "^3.2.12",
|
|
54
|
-
"kolorist": "1.
|
|
79
|
+
"kolorist": "1.8.0",
|
|
55
80
|
"p-limit": "^4.0.0",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"@stacksjs/
|
|
61
|
-
"@stacksjs/
|
|
62
|
-
"@stacksjs/
|
|
63
|
-
"@stacksjs/
|
|
64
|
-
"@stacksjs/
|
|
81
|
+
"perfect-debounce": "^1.0.0",
|
|
82
|
+
"rimraf": "^5.0.0",
|
|
83
|
+
"semver": "^7.5.1",
|
|
84
|
+
"yaml": "^2.2.2",
|
|
85
|
+
"@stacksjs/arrays": "0.52.0",
|
|
86
|
+
"@stacksjs/cli": "0.52.0",
|
|
87
|
+
"@stacksjs/config": "0.52.0",
|
|
88
|
+
"@stacksjs/lint": "0.52.0",
|
|
89
|
+
"@stacksjs/path": "0.52.0",
|
|
90
|
+
"@stacksjs/storage": "0.52.0",
|
|
91
|
+
"@stacksjs/types": "0.52.0"
|
|
65
92
|
},
|
|
66
93
|
"devDependencies": {
|
|
67
|
-
"@
|
|
68
|
-
"mkdist": "^1.1.0",
|
|
69
|
-
"typescript": "^4.9.5",
|
|
70
|
-
"@stacksjs/testing": "0.51.0"
|
|
94
|
+
"@stacksjs/development": "0.52.0"
|
|
71
95
|
},
|
|
72
96
|
"scripts": {
|
|
73
|
-
"build": "
|
|
74
|
-
"dev": "
|
|
97
|
+
"build": "unbuild",
|
|
98
|
+
"dev": "unbuild --stub",
|
|
75
99
|
"typecheck": "tsc --noEmit"
|
|
76
100
|
}
|
|
77
101
|
}
|
package/dist/vendor.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { throttle, debounce } from 'throttle-debounce';
|
package/dist/vendor.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { throttle, debounce } from "throttle-debounce";
|