@stacksjs/utils 0.64.6 → 0.67.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/clean.d.ts +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/equal.d.ts +1 -0
- package/dist/export-size.d.ts +1 -0
- package/dist/find.d.ts +5 -0
- package/dist/git.d.ts +1 -0
- package/dist/glob.d.ts +1 -0
- package/dist/hash.d.ts +3 -0
- package/dist/helpers.d.ts +50 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +64 -69
- package/dist/macroable.d.ts +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/versions.d.ts +3 -0
- package/package.json +21 -28
- package/dist/index.js.map +0 -478
- package/src/base.ts +0 -12
- package/src/clean.ts +0 -15
- package/src/config.ts +0 -25
- package/src/debounce.ts +0 -1
- package/src/equal.ts +0 -24
- package/src/export-size.ts +0 -1
- package/src/find.ts +0 -88
- package/src/function.ts +0 -32
- package/src/git.ts +0 -10
- package/src/glob.ts +0 -1
- package/src/guards.ts +0 -39
- package/src/hash.ts +0 -35
- package/src/helpers.ts +0 -174
- package/src/index.ts +0 -21
- package/src/macroable.ts +0 -1
- package/src/math.ts +0 -30
- package/src/promise.ts +0 -116
- package/src/regex.ts +0 -35
- package/src/retry.ts +0 -36
- package/src/sleep.ts +0 -60
- package/src/throttle.ts +0 -46
- package/src/utils.ts +0 -15
- package/src/vendors.ts +0 -258
- package/src/versions.ts +0 -6
package/src/retry.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export function retry(fn: Function, options: any): Promise<any> {
|
|
2
|
-
const { retries = 3, initialDelay = 1000, backoffFactor = 2, jitter = true } = options
|
|
3
|
-
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
let attemptCount = 0
|
|
6
|
-
const attempt = async () => {
|
|
7
|
-
try {
|
|
8
|
-
resolve(await fn())
|
|
9
|
-
} catch (err) {
|
|
10
|
-
if (attemptCount >= retries) {
|
|
11
|
-
reject(err)
|
|
12
|
-
} else {
|
|
13
|
-
const delay = calculateDelay(attemptCount, initialDelay, backoffFactor, jitter)
|
|
14
|
-
setTimeout(() => attempt(), delay)
|
|
15
|
-
attemptCount++
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
attempt()
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function calculateDelay(
|
|
24
|
-
attemptCount: number,
|
|
25
|
-
initialDelay: number,
|
|
26
|
-
backoffFactor: number,
|
|
27
|
-
jitter?: boolean,
|
|
28
|
-
): number {
|
|
29
|
-
let delay = initialDelay * backoffFactor ** attemptCount
|
|
30
|
-
if (jitter) {
|
|
31
|
-
const random = Math.random() // Generates a number between 0 and 1
|
|
32
|
-
const jitterValue = delay * 0.3 // Jitter will be up to 30% of the delay
|
|
33
|
-
delay = delay + jitterValue * (random - 0.5) * 2 // Adjust delay randomly within ±30%
|
|
34
|
-
}
|
|
35
|
-
return delay
|
|
36
|
-
}
|
package/src/sleep.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pauses execution for a specified number of milliseconds.
|
|
3
|
-
* @param ms The number of milliseconds to pause execution.
|
|
4
|
-
* @returns A promise that resolves after the specified delay.
|
|
5
|
-
*/
|
|
6
|
-
export function sleep(ms: number): Promise<void> {
|
|
7
|
-
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Pauses execution for a specified number of milliseconds.
|
|
12
|
-
* @param ms The number of milliseconds to pause execution.
|
|
13
|
-
* @returns A promise that resolves after the specified delay.
|
|
14
|
-
*/
|
|
15
|
-
export function wait(ms: number): Promise<void> {
|
|
16
|
-
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Pauses execution for a specified number of milliseconds.
|
|
21
|
-
* @param ms The number of milliseconds to pause execution.
|
|
22
|
-
* @returns A promise that resolves after the specified delay.
|
|
23
|
-
*/
|
|
24
|
-
export function delay(ms: number): Promise<void> {
|
|
25
|
-
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Pauses execution until a specified condition is met.
|
|
30
|
-
* @param condition The condition to wait for.
|
|
31
|
-
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
32
|
-
* @returns A promise that resolves when the condition is met.
|
|
33
|
-
*/
|
|
34
|
-
export function waitUntil(condition: () => boolean, interval = 1000): Promise<void> {
|
|
35
|
-
return new Promise((resolve) => {
|
|
36
|
-
const check = setInterval(() => {
|
|
37
|
-
if (condition()) {
|
|
38
|
-
clearInterval(check)
|
|
39
|
-
resolve()
|
|
40
|
-
}
|
|
41
|
-
}, interval)
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Pauses execution while a specified condition is met.
|
|
47
|
-
* @param condition The condition to wait while.
|
|
48
|
-
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
49
|
-
* @returns A promise that resolves when the condition is no longer met.
|
|
50
|
-
*/
|
|
51
|
-
export function waitWhile(condition: () => boolean, interval = 1000): Promise<void> {
|
|
52
|
-
return new Promise((resolve) => {
|
|
53
|
-
const check = setInterval(() => {
|
|
54
|
-
if (!condition()) {
|
|
55
|
-
clearInterval(check)
|
|
56
|
-
resolve()
|
|
57
|
-
}
|
|
58
|
-
}, interval)
|
|
59
|
-
})
|
|
60
|
-
}
|
package/src/throttle.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throttle a function.
|
|
3
|
-
*
|
|
4
|
-
* @param {Function} fn - The function to throttle.
|
|
5
|
-
* @param {number} [wait] - The time to wait between function calls.
|
|
6
|
-
* @returns {Function} - A new function that throttles the calls to the original function.
|
|
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
|
-
*/
|
|
20
|
-
|
|
21
|
-
export function throttle(fn: Function, wait = 300) {
|
|
22
|
-
let inThrottle: boolean
|
|
23
|
-
let lastFn: ReturnType<typeof setTimeout>
|
|
24
|
-
let lastTime: number
|
|
25
|
-
|
|
26
|
-
return function (this: unknown, ...args: any[]) {
|
|
27
|
-
if (!inThrottle) {
|
|
28
|
-
fn.apply(this, args)
|
|
29
|
-
|
|
30
|
-
lastTime = Date.now()
|
|
31
|
-
inThrottle = true
|
|
32
|
-
} else {
|
|
33
|
-
clearTimeout(lastFn)
|
|
34
|
-
|
|
35
|
-
lastFn = setTimeout(
|
|
36
|
-
() => {
|
|
37
|
-
if (Date.now() - lastTime >= wait) {
|
|
38
|
-
fn.apply(this, args) // Use 'this' directly
|
|
39
|
-
lastTime = Date.now()
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
Math.max(wait - (Date.now() - lastTime), 0),
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { resolve } from '@stacksjs/path'
|
|
2
|
-
import { fs } from '@stacksjs/storage'
|
|
3
|
-
import { kebabCase } from '@stacksjs/strings'
|
|
4
|
-
|
|
5
|
-
const ignore = ['readme-md']
|
|
6
|
-
|
|
7
|
-
export const components = fs
|
|
8
|
-
.readdirSync(resolve(__dirname, './resources/components'))
|
|
9
|
-
.map((item) => kebabCase(item.replace(/\.(stx|vue)/g, '')))
|
|
10
|
-
.filter((item) => !ignore.includes(item))
|
|
11
|
-
|
|
12
|
-
export const functions = fs
|
|
13
|
-
.readdirSync(resolve(__dirname, './resources/functions'))
|
|
14
|
-
.map((item) => kebabCase(item.replace(/.ts/g, '')))
|
|
15
|
-
.filter((item) => !ignore.includes(item))
|
package/src/vendors.ts
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
asyncComputed,
|
|
3
|
-
breakpointsAntDesign,
|
|
4
|
-
breakpointsBootstrapV5,
|
|
5
|
-
breakpointsMasterCss,
|
|
6
|
-
breakpointsQuasar,
|
|
7
|
-
breakpointsSematic,
|
|
8
|
-
breakpointsTailwind,
|
|
9
|
-
breakpointsVuetify,
|
|
10
|
-
cloneFnJSON,
|
|
11
|
-
computedAsync,
|
|
12
|
-
computedInject,
|
|
13
|
-
createFetch,
|
|
14
|
-
createReusableTemplate,
|
|
15
|
-
createTemplatePromise,
|
|
16
|
-
createUnrefFn,
|
|
17
|
-
customStorageEventName,
|
|
18
|
-
defaultDocument,
|
|
19
|
-
defaultLocation,
|
|
20
|
-
defaultNavigator,
|
|
21
|
-
defaultWindow,
|
|
22
|
-
executeTransition,
|
|
23
|
-
formatTimeAgo,
|
|
24
|
-
getSSRHandler,
|
|
25
|
-
mapGamepadToXbox360Controller,
|
|
26
|
-
onClickOutside,
|
|
27
|
-
onKeyDown,
|
|
28
|
-
onKeyPressed,
|
|
29
|
-
onKeyStroke,
|
|
30
|
-
onKeyUp,
|
|
31
|
-
onLongPress,
|
|
32
|
-
onStartTyping,
|
|
33
|
-
setSSRHandler,
|
|
34
|
-
templateRef,
|
|
35
|
-
unrefElement,
|
|
36
|
-
useActiveElement,
|
|
37
|
-
useAnimate,
|
|
38
|
-
useAsyncQueue,
|
|
39
|
-
useAsyncState,
|
|
40
|
-
useBase64,
|
|
41
|
-
useBattery,
|
|
42
|
-
useBluetooth,
|
|
43
|
-
useBreakpoints,
|
|
44
|
-
useBroadcastChannel,
|
|
45
|
-
useBrowserLocation,
|
|
46
|
-
useCached,
|
|
47
|
-
useClipboard,
|
|
48
|
-
useCloned,
|
|
49
|
-
useColorMode,
|
|
50
|
-
useConfirmDialog,
|
|
51
|
-
useCssVar,
|
|
52
|
-
useCurrentElement,
|
|
53
|
-
useCycleList,
|
|
54
|
-
useDark,
|
|
55
|
-
useDebouncedRefHistory,
|
|
56
|
-
useDeviceMotion,
|
|
57
|
-
useDeviceOrientation,
|
|
58
|
-
useDevicePixelRatio,
|
|
59
|
-
useDevicesList,
|
|
60
|
-
useDisplayMedia,
|
|
61
|
-
useDocumentVisibility,
|
|
62
|
-
useDraggable,
|
|
63
|
-
useDropZone,
|
|
64
|
-
useElementBounding,
|
|
65
|
-
useElementByPoint,
|
|
66
|
-
useElementHover,
|
|
67
|
-
useElementSize,
|
|
68
|
-
useElementVisibility,
|
|
69
|
-
useEventBus,
|
|
70
|
-
useEventListener,
|
|
71
|
-
useEventSource,
|
|
72
|
-
useEyeDropper,
|
|
73
|
-
useFavicon,
|
|
74
|
-
useFetch,
|
|
75
|
-
useFileDialog,
|
|
76
|
-
useFileSystemAccess,
|
|
77
|
-
useFocus,
|
|
78
|
-
useFocusWithin,
|
|
79
|
-
useFps,
|
|
80
|
-
useFullscreen,
|
|
81
|
-
useGamepad,
|
|
82
|
-
useGeolocation,
|
|
83
|
-
useIdle,
|
|
84
|
-
useImage,
|
|
85
|
-
useInfiniteScroll,
|
|
86
|
-
useIntersectionObserver,
|
|
87
|
-
useKeyModifier,
|
|
88
|
-
useLocalStorage,
|
|
89
|
-
useMagicKeys,
|
|
90
|
-
useManualRefHistory,
|
|
91
|
-
useMediaControls,
|
|
92
|
-
useMediaQuery,
|
|
93
|
-
useMemoize,
|
|
94
|
-
useMemory,
|
|
95
|
-
useMounted,
|
|
96
|
-
useMouse,
|
|
97
|
-
useMouseInElement,
|
|
98
|
-
useMousePressed,
|
|
99
|
-
useMutationObserver,
|
|
100
|
-
useNavigatorLanguage,
|
|
101
|
-
useNetwork,
|
|
102
|
-
useObjectUrl,
|
|
103
|
-
useOffsetPagination,
|
|
104
|
-
useOnline,
|
|
105
|
-
usePageLeave,
|
|
106
|
-
useParallax,
|
|
107
|
-
useParentElement,
|
|
108
|
-
usePerformanceObserver,
|
|
109
|
-
usePermission,
|
|
110
|
-
usePointer,
|
|
111
|
-
usePointerLock,
|
|
112
|
-
usePointerSwipe,
|
|
113
|
-
usePreferredColorScheme,
|
|
114
|
-
usePreferredContrast,
|
|
115
|
-
usePreferredDark,
|
|
116
|
-
usePreferredLanguages,
|
|
117
|
-
usePreferredReducedMotion,
|
|
118
|
-
usePrevious,
|
|
119
|
-
useRafFn,
|
|
120
|
-
useRefHistory,
|
|
121
|
-
useResizeObserver,
|
|
122
|
-
useScreenOrientation,
|
|
123
|
-
useScreenSafeArea,
|
|
124
|
-
useScriptTag,
|
|
125
|
-
useScroll,
|
|
126
|
-
useScrollLock,
|
|
127
|
-
useSessionStorage,
|
|
128
|
-
useShare,
|
|
129
|
-
useSorted,
|
|
130
|
-
useSpeechRecognition,
|
|
131
|
-
useSpeechSynthesis,
|
|
132
|
-
useStepper,
|
|
133
|
-
useStorage,
|
|
134
|
-
useStorageAsync,
|
|
135
|
-
useStyleTag,
|
|
136
|
-
useSupported,
|
|
137
|
-
useSwipe,
|
|
138
|
-
useTemplateRefsList,
|
|
139
|
-
useTextDirection,
|
|
140
|
-
useTextSelection,
|
|
141
|
-
useTextareaAutosize,
|
|
142
|
-
useThrottledRefHistory,
|
|
143
|
-
useTimeAgo,
|
|
144
|
-
useTimeoutPoll,
|
|
145
|
-
useTimestamp,
|
|
146
|
-
useTitle,
|
|
147
|
-
useTransition,
|
|
148
|
-
useToggle,
|
|
149
|
-
useUrlSearchParams,
|
|
150
|
-
useUserMedia,
|
|
151
|
-
useVModel,
|
|
152
|
-
useVModels,
|
|
153
|
-
useVibrate,
|
|
154
|
-
useVirtualList,
|
|
155
|
-
useWakeLock,
|
|
156
|
-
useWebNotification,
|
|
157
|
-
useWebSocket,
|
|
158
|
-
useWebWorker,
|
|
159
|
-
useWebWorkerFn,
|
|
160
|
-
useWindowFocus,
|
|
161
|
-
useWindowScroll,
|
|
162
|
-
useWindowSize,
|
|
163
|
-
useDateFormat,
|
|
164
|
-
useNow,
|
|
165
|
-
watchArray,
|
|
166
|
-
watchAtMost,
|
|
167
|
-
watchDebounced,
|
|
168
|
-
watchDeep,
|
|
169
|
-
watchIgnorable,
|
|
170
|
-
watchImmediate,
|
|
171
|
-
watchOnce,
|
|
172
|
-
watchPausable,
|
|
173
|
-
watchThrottled,
|
|
174
|
-
watchTriggerable,
|
|
175
|
-
watchWithFilter,
|
|
176
|
-
whenever,
|
|
177
|
-
syncRef,
|
|
178
|
-
syncRefs,
|
|
179
|
-
throttledRef,
|
|
180
|
-
throttledWatch,
|
|
181
|
-
toReactive,
|
|
182
|
-
tryOnBeforeMount,
|
|
183
|
-
tryOnBeforeUnmount,
|
|
184
|
-
tryOnMounted,
|
|
185
|
-
tryOnScopeDispose,
|
|
186
|
-
tryOnUnmounted,
|
|
187
|
-
until,
|
|
188
|
-
isDefined,
|
|
189
|
-
ignorableWatch,
|
|
190
|
-
extendRef,
|
|
191
|
-
eagerComputed,
|
|
192
|
-
debouncedRef,
|
|
193
|
-
debouncedWatch,
|
|
194
|
-
createReactiveFn,
|
|
195
|
-
createSharedComposable,
|
|
196
|
-
createInjectionState,
|
|
197
|
-
createGlobalState,
|
|
198
|
-
createEventHook,
|
|
199
|
-
controlledRef,
|
|
200
|
-
controlledComputed,
|
|
201
|
-
computedEager,
|
|
202
|
-
computedWithControl,
|
|
203
|
-
autoResetRef,
|
|
204
|
-
injectLocal,
|
|
205
|
-
makeDestructurable,
|
|
206
|
-
pausableWatch,
|
|
207
|
-
provideLocal,
|
|
208
|
-
reactify,
|
|
209
|
-
reactifyObject,
|
|
210
|
-
reactiveComputed,
|
|
211
|
-
reactiveOmit,
|
|
212
|
-
reactivePick,
|
|
213
|
-
refAutoReset,
|
|
214
|
-
refDebounced,
|
|
215
|
-
refDefault,
|
|
216
|
-
refThrottled,
|
|
217
|
-
refWithControl,
|
|
218
|
-
resolveRef,
|
|
219
|
-
resolveUnref,
|
|
220
|
-
useArrayDifference,
|
|
221
|
-
useArrayEvery,
|
|
222
|
-
useArrayFilter,
|
|
223
|
-
useArrayFind,
|
|
224
|
-
useArrayFindIndex,
|
|
225
|
-
useArrayIncludes,
|
|
226
|
-
useArrayMap,
|
|
227
|
-
useArrayReduce,
|
|
228
|
-
useArraySome,
|
|
229
|
-
useArrayUnique,
|
|
230
|
-
useClipboardItems,
|
|
231
|
-
useCounter,
|
|
232
|
-
useDebounce,
|
|
233
|
-
useDebounceFn,
|
|
234
|
-
useInterval,
|
|
235
|
-
useIntervalFn,
|
|
236
|
-
useLastChanged,
|
|
237
|
-
useThrottle,
|
|
238
|
-
useThrottleFn,
|
|
239
|
-
useTimeout,
|
|
240
|
-
useTimeoutFn,
|
|
241
|
-
useToNumber,
|
|
242
|
-
useToString,
|
|
243
|
-
} from '@vueuse/core'
|
|
244
|
-
|
|
245
|
-
export type {
|
|
246
|
-
// Head,
|
|
247
|
-
HeadObject,
|
|
248
|
-
HeadObjectPlain,
|
|
249
|
-
} from '@vueuse/head'
|
|
250
|
-
|
|
251
|
-
export {
|
|
252
|
-
Head,
|
|
253
|
-
HeadVuePlugin,
|
|
254
|
-
createHead,
|
|
255
|
-
renderHeadToString,
|
|
256
|
-
} from '@vueuse/head'
|
|
257
|
-
|
|
258
|
-
export { default as readableSize } from 'pretty-bytes'
|