@stacksjs/utils 0.56.34 → 0.57.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/index.d.ts CHANGED
@@ -1,377 +1,15 @@
1
- import { AppOptions, CacheOptions, CdnOptions, UserCliOptions, CronJobOptions, JobOptions, DatabaseOptions, DebugOptions, DnsOptions, EmailOptions, Events, GitOptions, HashingOptions, LibraryOptions, Model, NotificationOptions, PagesOption, PaymentOptions, QueueOptions, SearchEngineOptions, ServicesOptions, StorageOptions, UiOptions, Nullable, Fn, Manifest, NpmScript, CliOptions, CommandResult } from '@stacksjs/types';
2
- export { Currency, Dinero, add, allocate, compare, convert, dinero as currency, dinero, equal, greaterThan, greaterThanOrEqual, hasSubUnits, haveSameAmount, haveSameCurrency, isZero, lessThan, lessThanOrEqual, maximum, minimum, dinero as money, multiply, normalizeScale, subtract, toDecimal, toSnapshot, toUnits, trimScale } from 'dinero.js';
3
- export { USD } from '@dinero.js/currencies';
4
- export { debounce } from 'perfect-debounce';
5
- export { rimraf as del, rimraf } from 'rimraf';
6
- import { AddressInfo } from 'node:net';
7
- export { asyncComputed, autoResetRef, breakpointsAntDesign, breakpointsBootstrapV5, breakpointsMasterCss, breakpointsQuasar, breakpointsSematic, breakpointsTailwind, breakpointsVuetify, cloneFnJSON, computedAsync, computedEager, computedInject, computedWithControl, controlledComputed, controlledRef, createEventHook, createFetch, createGlobalState, createInjectionState, createReactiveFn, createReusableTemplate, createSharedComposable, createTemplatePromise, createUnrefFn, customStorageEventName, debouncedRef, debouncedWatch, defaultDocument, defaultLocation, defaultNavigator, defaultWindow, eagerComputed, executeTransition, extendRef, formatTimeAgo, getSSRHandler, ignorableWatch, isDefined, mapGamepadToXbox360Controller, onClickOutside, onKeyDown, onKeyPressed, onKeyStroke, onKeyUp, onLongPress, onStartTyping, setSSRHandler, syncRef, syncRefs, templateRef, throttledRef, throttledWatch, toReactive, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, unrefElement, until, useActiveElement, useAnimate, useAsyncQueue, useAsyncState, useBase64, useBattery, useBluetooth, useBreakpoints, useBroadcastChannel, useBrowserLocation, useCached, useClipboard, useCloned, useColorMode, useConfirmDialog, useCssVar, useCurrentElement, useCycleList, useDark, useDateFormat, 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, useNow, 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, useToggle, useTransition, useUrlSearchParams, useUserMedia, useVModel, useVModels, useVibrate, useVirtualList, useWakeLock, useWebNotification, useWebSocket, useWebWorker, useWebWorkerFn, useWindowFocus, useWindowScroll, useWindowSize, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever } from '@vueuse/core';
8
- export { Head, HeadClient, HeadObject, HeadObjectPlain, HeadVuePlugin, HookBeforeDomUpdate, HookEntriesResolved, HookTagsResolved, LegacyHeadOptions, createHead, renderHeadToString } from '@vueuse/head';
9
- import * as semver from 'semver';
10
- export { semver };
11
- export { loadStacksConfig as config } from '@stacksjs/config';
12
- export { and, createGenericProjection, createProjection, logicNot, logicOr, not, or, useAbs, useAverage, useCeil, useClamp, useFloor, useMath, useMax, useMin, usePrecision, useProjection, useRound, useSum, useTrunc } from '@vueuse/math';
13
-
14
- declare function toString(v: any): string;
15
- declare function loop(times: number, callback: any): void;
16
- declare function getTypeName(v: any): string;
17
-
18
- declare function defineApp(config: Partial<AppOptions>): Partial<AppOptions>;
19
- declare function defineCache(config: Partial<CacheOptions>): Partial<CacheOptions>;
20
- declare function defineCdn(config: Partial<CdnOptions>): Partial<CdnOptions>;
21
- declare function defineCli(config: Partial<UserCliOptions>): Partial<UserCliOptions>;
22
- declare function defineCronJobsConfig(config: Partial<CronJobOptions>[]): Partial<CronJobOptions>[];
23
- declare function defineJobsConfig(config: Partial<JobOptions>[]): Partial<JobOptions>[];
24
- declare function defineDatabase(config: Partial<DatabaseOptions>): Partial<DatabaseOptions>;
25
- declare function defineDebugConfig(config: Partial<DebugOptions>): Partial<DebugOptions>;
26
- declare function defineDns(config: Partial<DnsOptions>): Partial<DnsOptions>;
27
- declare function defineEmailConfig(config: Partial<EmailOptions>): Partial<EmailOptions>;
28
- declare function defineEvents(config: Partial<Events>): Partial<Events>;
29
- declare function defineGit(config: Partial<GitOptions>): Partial<GitOptions>;
30
- declare function defineHashing(config: Partial<HashingOptions>): Partial<HashingOptions>;
31
- declare function defineLibrary(config: Partial<LibraryOptions>): Partial<LibraryOptions>;
32
- declare function defineModel(config: Partial<Model>): Partial<Model>;
33
- declare function defineNotification(config: Partial<NotificationOptions>): Partial<NotificationOptions>;
34
- declare function defineSms(config: Partial<NotificationOptions['sms']>): Partial<{
35
- default: string;
36
- from: string;
37
- drivers: {
38
- twilio: {
39
- sid: string;
40
- authToken: string;
41
- };
42
- nexmo: {
43
- key: string;
44
- secret: string;
45
- };
46
- gupshup: {
47
- user: string;
48
- password: string;
49
- };
50
- plivo: {
51
- sid: string;
52
- authToken: string;
53
- };
54
- sms77: {
55
- key: string;
56
- };
57
- sns: {
58
- region: string;
59
- key: string;
60
- secret: string;
61
- };
62
- telnyx: {
63
- key: string;
64
- messageProfileId: string;
65
- };
66
- termii: {
67
- key: string;
68
- };
69
- };
70
- }>;
71
- declare function defineEmail(config: Partial<NotificationOptions['email']>): Partial<{
72
- default: string;
73
- from: {
74
- name: string;
75
- address: string;
76
- };
77
- drivers: {
78
- smtp: {
79
- host: string;
80
- port: number;
81
- secure: boolean;
82
- auth: {
83
- user: string;
84
- pass: string;
85
- };
86
- };
87
- sendgrid: {
88
- key: string;
89
- senderName: string;
90
- };
91
- emailjs: {
92
- host: string;
93
- user: string;
94
- password: string;
95
- port: number;
96
- secure: boolean;
97
- };
98
- mailgun: {
99
- key: string;
100
- domain: string;
101
- username: string;
102
- };
103
- mailjet: {
104
- key: string;
105
- secret: string;
106
- };
107
- mandrill: {
108
- key: string;
109
- };
110
- netcore: {
111
- key: string;
112
- };
113
- nodemailer: {
114
- host: string;
115
- user: string;
116
- password: string;
117
- port: number;
118
- secure: boolean;
119
- };
120
- postmark: {
121
- key: string;
122
- };
123
- ses: {
124
- region: string;
125
- key: string;
126
- secret: string;
127
- };
128
- };
129
- }>;
130
- declare function defineChat(config: Partial<NotificationOptions['chat']>): Partial<{
131
- default: string;
132
- from: string;
133
- drivers: {
134
- slack?: {
135
- appId: string;
136
- clientId: string;
137
- secret: string;
138
- } | undefined;
139
- msTeams?: {
140
- appId: string;
141
- clientId: string;
142
- secret: string;
143
- } | undefined;
144
- discord?: {} | undefined;
145
- };
146
- }>;
147
- declare function definePage(config: Partial<PagesOption>): Partial<PagesOption>;
148
- declare function definePayment(config: Partial<PaymentOptions>): Partial<PaymentOptions>;
149
- declare function defineQueue(config: Partial<QueueOptions>): Partial<QueueOptions>;
150
- declare function defineSearchEngine(config: Partial<SearchEngineOptions>): Partial<SearchEngineOptions>;
151
- declare function defineServices(config: Partial<ServicesOptions>): Partial<ServicesOptions>;
152
- declare function defineStorage(config: Partial<StorageOptions>): Partial<StorageOptions>;
153
- declare function defineUi(config: Partial<UiOptions>): Partial<UiOptions>;
154
-
155
- declare function isDeepEqual(value1: any, value2: any): boolean;
156
-
157
- /**
158
- * Call every function in an array
159
- */
160
- declare function batchInvoke(functions: Nullable<Fn>[]): void;
161
- /**
162
- * Pass the value through the callback, and return the value
163
- *
164
- * @example
165
- * ```
166
- * function createUser(name: string): User {
167
- * return tap(new User, user => {
168
- * user.name = name
169
- * })
170
- * }
171
- * ```
172
- */
173
- declare function tap<T>(value: T, callback: (value: T) => void): T;
174
-
175
- /**
176
- * Type guard to filter out null-ish values
177
- *
178
- * @category Guards
179
- * @example array.filter(notNullish)
180
- */
181
- declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>;
182
- /**
183
- * Type guard to filter out null values
184
- *
185
- * @category Guards
186
- * @example array.filter(noNull)
187
- */
188
- declare function noNull<T>(v: T | null): v is Exclude<T, null>;
189
- /**
190
- * Type guard to filter out null-ish values
191
- *
192
- * @category Guards
193
- * @example array.filter(notUndefined)
194
- */
195
- declare function notUndefined<T>(v: T): v is Exclude<T, undefined>;
196
- /**
197
- * Type guard to filter out falsy values
198
- *
199
- * @category Guards
200
- * @example array.filter(isTruthy)
201
- */
202
- declare function isTruthy<T>(v: T): v is NonNullable<T>;
203
-
204
- declare function isProjectCreated(): Promise<boolean>;
205
- declare function installIfVersionMismatch(): Promise<void>;
206
- declare function frameworkVersion(): Promise<string>;
207
- declare function isAppKeySet(): Promise<boolean>;
208
- /**
209
- * Determines the utilized reset preset.
210
- *
211
- * @url https://www.npmjs.com/package/@unocss/reset
212
- * @param preset
213
- */
214
- declare function determineResetPreset(preset?: string): string[];
215
- /**
216
- * Determines whether the specified value is a package manifest.
217
- */
218
- declare function isManifest(obj: any): obj is Manifest;
219
- /**
220
- * Determines whether the specified value is a string, null, or undefined.
221
- */
222
- declare function isOptionalString(value: any): value is string | undefined;
223
- declare function setEnvValue(key: string, value: string): Promise<void>;
224
- /**
225
- * Runs the specified NPM script in the package.json file.
226
- */
227
- declare function runNpmScript(script: NpmScript, options?: CliOptions): Promise<CommandResult>;
228
- /**
229
- * Determines whether the specified NPM script exists in the given manifest.
230
- */
231
- declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
232
- declare function parseYaml(content: any): any;
233
- /**
234
- * Determines the level of debugging.
235
- *
236
- * The debug level is determined by the following:
237
- * 1. The --verbose flag
238
- * 2. The debug property in the app configuration
239
- *
240
- * Currently, we don't support a custom debug level,
241
- * though, we would like to in the future.
242
- *
243
- * @param options
244
- */
245
- declare function determineDebugLevel(options?: CliOptions): boolean;
246
- declare function isIpv6(address: AddressInfo): boolean;
247
-
248
- declare const clamp: (n: number, min: number, max: number) => number;
249
- declare function rand(min: number, max: number): number;
250
-
251
- interface POptions {
252
- /**
253
- * How many promises are resolved at the same time.
254
- */
255
- concurrency?: number | undefined;
256
- }
257
- declare class PInstance<T = any> extends Promise<Awaited<T>[]> {
258
- items: Iterable<T>;
259
- options?: POptions | undefined;
260
- private promises;
261
- get promise(): Promise<Awaited<T>[]>;
262
- constructor(items?: Iterable<T>, options?: POptions | undefined);
263
- add(...args: (T | Promise<T>)[]): void;
264
- map<U>(fn: (value: Awaited<T>, index: number) => U): PInstance<Promise<U>>;
265
- filter(fn: (value: Awaited<T>, index: number) => boolean | Promise<boolean>): PInstance<Promise<T>>;
266
- forEach(fn: (value: Awaited<T>, index: number) => void): Promise<void>;
267
- reduce<U>(fn: (previousValue: U, currentValue: Awaited<T>, currentIndex: number, array: Awaited<T>[]) => U, initialValue: U): Promise<U>;
268
- clear(): void;
269
- then(fn?: () => PromiseLike<any>): Promise<any>;
270
- catch(fn?: (err: unknown) => PromiseLike<any>): Promise<any>;
271
- finally(fn?: () => void): Promise<Awaited<T>[]>;
272
- }
273
- /**
274
- * Utility for managing multiple promises.
275
- *
276
- * @see https://github.com/antfu/utils/tree/main/docs/p.md
277
- * @category Promise
278
- * @example
279
- * ```
280
- * import { p } from '@stacksjs/utils'
281
- *
282
- * const items = [1, 2, 3, 4, 5]
283
- *
284
- * await p(items)
285
- * .map(async i => await multiply(i, 3))
286
- * .filter(async i => await isEven(i))
287
- * // [6, 12]
288
- * ```
289
- */
290
- declare function p<T = any>(items?: Iterable<T>, options?: POptions): PInstance<T>;
291
-
292
- interface SingletonPromiseReturn<T> {
293
- (): Promise<T>;
294
- /**
295
- * Reset current staled promise.
296
- * Await it to have proper shutdown.
297
- */
298
- reset: () => Promise<void>;
299
- }
300
- /**
301
- * Promise with `resolve` and `reject` methods of itself
302
- */
303
- interface ControlledPromise<T = void> extends Promise<T> {
304
- resolve(value: T | PromiseLike<T>): void;
305
- reject(reason?: any): void;
306
- }
307
- /**
308
- * Create singleton promise function.
309
- *
310
- * @category Promise
311
- */
312
- declare function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromiseReturn<T>;
313
- /**
314
- * Create a promise lock.
315
- *
316
- * @category Promise
317
- * @example
318
- * ```
319
- * const lock = createPromiseLock()
320
- *
321
- * lock.run(async () => {
322
- * await doSomething()
323
- * })
324
- *
325
- * // in anther context:
326
- * await lock.wait() // it will wait all tasking finished
327
- * ```
328
- */
329
- declare function createPromiseLock(): {
330
- run<T = void>(fn: () => Promise<T>): Promise<T>;
331
- wait(): Promise<void>;
332
- isWaiting(): boolean;
333
- clear(): void;
334
- };
335
- /**
336
- * Return a Promise with `resolve` and `reject` methods
337
- *
338
- * @category Promise
339
- * @example
340
- * ```
341
- * const promise = createControlledPromise()
342
- *
343
- * await promise
344
- *
345
- * // in anther context:
346
- * promise.resolve(data)
347
- * ```
348
- */
349
- declare function createControlledPromise<T>(): ControlledPromise<T>;
350
- /**
351
- * Promised `setTimeout`.
352
- *
353
- * @category Promise
354
- */
355
- declare function sleep(ms: number, callback?: Fn<any>): Promise<void>;
356
-
357
- /**
358
- * Throttle a function.
359
- *
360
- * @param fn
361
- * @param wait
362
- * @returns
363
- *
364
- * @example
365
- * ```ts
366
- * // logs window dimensions at most every 250ms
367
- * window.addEventListener(
368
- * "resize",
369
- * throttle(function (evt) {
370
- * console.log(window.innerWidth)
371
- * console.log(window.innerHeight)
372
- * }, 250)
373
- * )
374
- */
375
- declare function throttle(fn: Function, wait?: number): (this: unknown, ...args: any[]) => void;
376
-
377
- export { ControlledPromise, SingletonPromiseReturn, batchInvoke, clamp, createControlledPromise, createPromiseLock, createSingletonPromise, defineApp, defineCache, defineCdn, defineChat, defineCli, defineCronJobsConfig, defineDatabase, defineDebugConfig, defineDns, defineEmail, defineEmailConfig, defineEvents, defineGit, defineHashing, defineJobsConfig, defineLibrary, defineModel, defineNotification, definePage, definePayment, defineQueue, defineSearchEngine, defineServices, defineSms, defineStorage, defineUi, determineDebugLevel, determineResetPreset, frameworkVersion, getTypeName, hasScript, installIfVersionMismatch, isAppKeySet, isDeepEqual, isIpv6, isManifest, isOptionalString, isProjectCreated, isTruthy, loop, noNull, notNullish, notUndefined, p, parseYaml, rand, runNpmScript, setEnvValue, sleep, tap, throttle, toString };
1
+ export * from './base';
2
+ export * from './config';
3
+ export * from './currency';
4
+ export * from './debounce';
5
+ export * from './delete';
6
+ export * from './equal';
7
+ export * from './function';
8
+ export * from './guards';
9
+ export * from './helpers';
10
+ export * from './math';
11
+ export * from './p';
12
+ export * from './promise';
13
+ export * from './throttle';
14
+ export * from './vendors';
15
+ export * from './versions';