@fluixi/core 1.0.0-alpha.82 → 1.0.0-alpha.84
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/cdn/core.global.js +2 -1
- package/dist/cli/generate.cjs +4117 -292
- package/dist/cli/generate.mjs +4122 -292
- package/dist/cli/index.cjs +4117 -292
- package/dist/cli/index.mjs +4122 -292
- package/dist/cli/run.cjs +63 -1
- package/dist/cli/run.mjs +39 -1
- package/dist/src/cdn/chunk-VNLCQBFQ.mjs +747 -0
- package/dist/src/cdn/core.cjs +1279 -1
- package/dist/src/cdn/core.d.ts +3 -3
- package/dist/src/cdn/core.js +3 -3
- package/dist/src/cdn/core.mjs +642 -1
- package/dist/src/cdn/router-WMN2AA7E.mjs +66 -0
- package/dist/src/index.cjs +1201 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.mjs +1313 -1
- package/dist/src/jsx-dev-runtime.cjs +26 -1
- package/dist/src/jsx-dev-runtime.mjs +24 -1
- package/dist/src/jsx-runtime.cjs +26 -1
- package/dist/src/jsx-runtime.js +0 -9
- package/dist/src/jsx-runtime.mjs +24 -1
- package/dist/src/lib/client/chunk-2C2KDDQV.mjs +133 -0
- package/dist/src/lib/client/index.cjs +870 -1
- package/dist/src/lib/client/index.d.ts +10 -14
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +36 -21
- package/dist/src/lib/client/index.mjs +222 -1
- package/dist/src/lib/client/router-X526HSWQ.mjs +548 -0
- package/dist/src/lib/context/context.cjs +118 -1
- package/dist/src/lib/context/context.d.ts +20 -38
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +10 -47
- package/dist/src/lib/context/context.mjs +99 -1
- package/dist/src/lib/context/index.cjs +120 -1
- package/dist/src/lib/context/index.mjs +99 -1
- package/dist/src/lib/control-flow.cjs +35 -1
- package/dist/src/lib/control-flow.mjs +25 -1
- package/dist/src/lib/core.cjs +1200 -1
- package/dist/src/lib/core.d.ts +0 -2
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +14 -48
- package/dist/src/lib/core.mjs +1313 -1
- package/dist/src/lib/env/index.cjs +60 -1
- package/dist/src/lib/env/index.d.ts +7 -8
- package/dist/src/lib/env/index.d.ts.map +1 -1
- package/dist/src/lib/env/index.js +14 -9
- package/dist/src/lib/env/index.mjs +39 -1
- package/dist/src/lib/i18n/index.cjs +108 -1
- package/dist/src/lib/i18n/index.d.ts +31 -10
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +31 -10
- package/dist/src/lib/i18n/index.mjs +88 -1
- package/dist/src/lib/index.cjs +633 -1
- package/dist/src/lib/index.d.ts +0 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/dist/src/lib/index.js +5 -11
- package/dist/src/lib/index.mjs +721 -1
- package/dist/src/lib/isomorphic.cjs +85 -1
- package/dist/src/lib/isomorphic.d.ts +41 -8
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +38 -5
- package/dist/src/lib/isomorphic.mjs +64 -1
- package/dist/src/lib/jsx-runtime/index.cjs +21 -1
- package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
- package/dist/src/lib/jsx-runtime/index.js +1 -11
- package/dist/src/lib/jsx-runtime/index.mjs +4 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
- package/dist/src/lib/plugins/index.cjs +311 -8
- package/dist/src/lib/plugins/index.mjs +279 -8
- package/dist/src/lib/plugins/route-codegen.cjs +73 -8
- package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-codegen.js +4 -5
- package/dist/src/lib/plugins/route-codegen.mjs +52 -8
- package/dist/src/lib/plugins/route-scanner.cjs +189 -1
- package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-scanner.js +7 -8
- package/dist/src/lib/plugins/route-scanner.mjs +158 -1
- package/dist/src/lib/plugins/vite.cjs +27 -1
- package/dist/src/lib/plugins/vite.mjs +6 -1
- package/dist/src/lib/render/await.cjs +38 -1
- package/dist/src/lib/render/await.d.ts +18 -0
- package/dist/src/lib/render/await.d.ts.map +1 -1
- package/dist/src/lib/render/await.js +20 -2
- package/dist/src/lib/render/await.mjs +17 -1
- package/dist/src/lib/render/component.cjs +221 -1
- package/dist/src/lib/render/component.d.ts +3 -44
- package/dist/src/lib/render/component.d.ts.map +1 -1
- package/dist/src/lib/render/component.js +32 -59
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.d.ts.map +1 -1
- package/dist/src/lib/render/deferred.js +8 -8
- package/dist/src/lib/render/deferred.mjs +158 -1
- package/dist/src/lib/render/index.cjs +573 -1
- package/dist/src/lib/render/index.d.ts +3 -17
- package/dist/src/lib/render/index.d.ts.map +1 -1
- package/dist/src/lib/render/index.js +12 -26
- package/dist/src/lib/render/index.mjs +590 -1
- package/dist/src/lib/render/lazy.cjs +67 -1
- package/dist/src/lib/render/lazy.d.ts +22 -1
- package/dist/src/lib/render/lazy.d.ts.map +1 -1
- package/dist/src/lib/render/lazy.js +47 -8
- package/dist/src/lib/render/lazy.mjs +50 -1
- package/dist/src/lib/render/suspense.cjs +141 -1
- package/dist/src/lib/render/suspense.d.ts +40 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -1
- package/dist/src/lib/render/suspense.js +47 -7
- package/dist/src/lib/render/suspense.mjs +136 -1
- package/dist/src/lib/render/versions.cjs +35 -1
- package/dist/src/lib/render/versions.js +6 -6
- package/dist/src/lib/render/versions.mjs +14 -1
- package/dist/src/lib/router/data.cjs +230 -1
- package/dist/src/lib/router/data.d.ts +1 -13
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +1 -13
- package/dist/src/lib/router/data.mjs +214 -1
- package/dist/src/lib/router/index.cjs +627 -1
- package/dist/src/lib/router/index.d.ts +62 -10
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +90 -39
- package/dist/src/lib/router/index.mjs +639 -1
- package/dist/src/lib/server/hydration.cjs +169 -1
- package/dist/src/lib/server/hydration.d.ts +15 -55
- package/dist/src/lib/server/hydration.d.ts.map +1 -1
- package/dist/src/lib/server/hydration.js +23 -62
- package/dist/src/lib/server/hydration.mjs +148 -1
- package/dist/src/lib/server/index.cjs +401 -11
- package/dist/src/lib/server/index.d.ts +30 -6
- package/dist/src/lib/server/index.d.ts.map +1 -1
- package/dist/src/lib/server/index.js +34 -11
- package/dist/src/lib/server/index.mjs +379 -11
- package/dist/src/lib/server/reactive.cjs +197 -1
- package/dist/src/lib/server/reactive.d.ts +18 -77
- package/dist/src/lib/server/reactive.d.ts.map +1 -1
- package/dist/src/lib/server/reactive.js +19 -78
- package/dist/src/lib/server/reactive.mjs +176 -1
- package/dist/src/lib/theme/index.cjs +110 -1
- package/dist/src/lib/theme/index.d.ts +19 -4
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +17 -2
- package/dist/src/lib/theme/index.mjs +89 -1
- package/dist/src/lib/utils/index.cjs +209 -1
- package/dist/src/lib/utils/index.d.ts +0 -93
- package/dist/src/lib/utils/index.d.ts.map +1 -1
- package/dist/src/lib/utils/index.js +0 -93
- package/dist/src/lib/utils/index.mjs +188 -1
- package/dist/src/routes.cjs +37 -1
- package/dist/src/routes.d.ts +1 -1
- package/dist/src/routes.js +2 -2
- package/dist/src/routes.mjs +17 -1
- package/dist/src/server.cjs +400 -11
- package/dist/src/server.d.ts +0 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +0 -1
- package/dist/src/server.mjs +377 -11
- package/dist/src/utils.cjs +21 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.mjs +4 -1
- package/dist/src/version.generated.cjs +26 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +2 -2
- package/dist/src/version.generated.mjs +5 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/index.ts +2 -14
- package/dist/src/cdn/chunk-RN7C7HNS.mjs +0 -1
- package/dist/src/cdn/router-QB3W43UQ.mjs +0 -1
- package/dist/src/lib/client/chunk-FT22BLCQ.mjs +0 -1
- package/dist/src/lib/client/router-IH7JYMRU.mjs +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview General utilities for Fluixi
|
|
3
2
|
* @module @fluixi/core/utils
|
|
4
3
|
*
|
|
5
4
|
* This module provides general utility functions for common operations.
|
|
@@ -7,11 +6,6 @@
|
|
|
7
6
|
/**
|
|
8
7
|
* Debounces a function call
|
|
9
8
|
*
|
|
10
|
-
* @template T - Function type
|
|
11
|
-
* @param {T} fn - Function to debounce
|
|
12
|
-
* @param {number} delay - Delay in milliseconds
|
|
13
|
-
* @returns {(...args: Parameters<T>) => void} Debounced function
|
|
14
|
-
*
|
|
15
9
|
* @example
|
|
16
10
|
* ```typescript
|
|
17
11
|
* import { debounce } from '@fluixi/core/utils';
|
|
@@ -25,11 +19,6 @@ export declare function debounce<T extends (...args: any[]) => any>(fn: T, delay
|
|
|
25
19
|
/**
|
|
26
20
|
* Throttles a function call
|
|
27
21
|
*
|
|
28
|
-
* @template T - Function type
|
|
29
|
-
* @param {T} fn - Function to throttle
|
|
30
|
-
* @param {number} limit - Time limit in milliseconds
|
|
31
|
-
* @returns {(...args: Parameters<T>) => void} Throttled function
|
|
32
|
-
*
|
|
33
22
|
* @example
|
|
34
23
|
* ```typescript
|
|
35
24
|
* import { throttle } from '@fluixi/core/utils';
|
|
@@ -43,10 +32,6 @@ export declare function throttle<T extends (...args: any[]) => any>(fn: T, limit
|
|
|
43
32
|
/**
|
|
44
33
|
* Creates a memoized version of a function
|
|
45
34
|
*
|
|
46
|
-
* @template T - Function type
|
|
47
|
-
* @param {T} fn - Function to memoize
|
|
48
|
-
* @returns {T} Memoized function
|
|
49
|
-
*
|
|
50
35
|
* @example
|
|
51
36
|
* ```typescript
|
|
52
37
|
* import { memoize } from '@fluixi/core/utils';
|
|
@@ -60,10 +45,6 @@ export declare function memoize<T extends (...args: any[]) => any>(fn: T): T;
|
|
|
60
45
|
/**
|
|
61
46
|
* Deep clones an object
|
|
62
47
|
*
|
|
63
|
-
* @template T - Object type
|
|
64
|
-
* @param {T} obj - Object to clone
|
|
65
|
-
* @returns {T} Cloned object
|
|
66
|
-
*
|
|
67
48
|
* @example
|
|
68
49
|
* ```typescript
|
|
69
50
|
* import { deepClone } from '@fluixi/core/utils';
|
|
@@ -76,10 +57,6 @@ export declare function deepClone<T>(obj: T): T;
|
|
|
76
57
|
/**
|
|
77
58
|
* Deep merges multiple objects
|
|
78
59
|
*
|
|
79
|
-
* @template T - Object type
|
|
80
|
-
* @param {...Partial<T>[]} objects - Objects to merge
|
|
81
|
-
* @returns {T} Merged object
|
|
82
|
-
*
|
|
83
60
|
* @example
|
|
84
61
|
* ```typescript
|
|
85
62
|
* import { deepMerge } from '@fluixi/core/utils';
|
|
@@ -95,9 +72,6 @@ export declare function deepMerge<T extends Record<string, any>>(...objects: Par
|
|
|
95
72
|
/**
|
|
96
73
|
* Generates a unique ID
|
|
97
74
|
*
|
|
98
|
-
* @param {string} prefix - Optional prefix
|
|
99
|
-
* @returns {string} Unique ID
|
|
100
|
-
*
|
|
101
75
|
* @example
|
|
102
76
|
* ```typescript
|
|
103
77
|
* import { uniqueId } from '@fluixi/core/utils';
|
|
@@ -110,9 +84,6 @@ export declare function uniqueId(prefix?: string): string;
|
|
|
110
84
|
/**
|
|
111
85
|
* Formats a number with commas
|
|
112
86
|
*
|
|
113
|
-
* @param {number} num - Number to format
|
|
114
|
-
* @returns {string} Formatted number
|
|
115
|
-
*
|
|
116
87
|
* @example
|
|
117
88
|
* ```typescript
|
|
118
89
|
* import { formatNumber } from '@fluixi/core/utils';
|
|
@@ -124,10 +95,6 @@ export declare function formatNumber(num: number): string;
|
|
|
124
95
|
/**
|
|
125
96
|
* Formats bytes to human readable string
|
|
126
97
|
*
|
|
127
|
-
* @param {number} bytes - Number of bytes
|
|
128
|
-
* @param {number} decimals - Decimal places (default: 2)
|
|
129
|
-
* @returns {string} Formatted string
|
|
130
|
-
*
|
|
131
98
|
* @example
|
|
132
99
|
* ```typescript
|
|
133
100
|
* import { formatBytes } from '@fluixi/core/utils';
|
|
@@ -140,9 +107,6 @@ export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
|
140
107
|
/**
|
|
141
108
|
* Capitalizes first letter of a string
|
|
142
109
|
*
|
|
143
|
-
* @param {string} str - String to capitalize
|
|
144
|
-
* @returns {string} Capitalized string
|
|
145
|
-
*
|
|
146
110
|
* @example
|
|
147
111
|
* ```typescript
|
|
148
112
|
* import { capitalize } from '@fluixi/core/utils';
|
|
@@ -154,9 +118,6 @@ export declare function capitalize(str: string): string;
|
|
|
154
118
|
/**
|
|
155
119
|
* Converts string to kebab-case
|
|
156
120
|
*
|
|
157
|
-
* @param {string} str - String to convert
|
|
158
|
-
* @returns {string} Kebab-case string
|
|
159
|
-
*
|
|
160
121
|
* @example
|
|
161
122
|
* ```typescript
|
|
162
123
|
* import { kebabCase } from '@fluixi/core/utils';
|
|
@@ -168,9 +129,6 @@ export declare function kebabCase(str: string): string;
|
|
|
168
129
|
/**
|
|
169
130
|
* Converts string to camelCase
|
|
170
131
|
*
|
|
171
|
-
* @param {string} str - String to convert
|
|
172
|
-
* @returns {string} CamelCase string
|
|
173
|
-
*
|
|
174
132
|
* @example
|
|
175
133
|
* ```typescript
|
|
176
134
|
* import { camelCase } from '@fluixi/core/utils';
|
|
@@ -182,11 +140,6 @@ export declare function camelCase(str: string): string;
|
|
|
182
140
|
/**
|
|
183
141
|
* Clamps a number between min and max
|
|
184
142
|
*
|
|
185
|
-
* @param {number} value - Value to clamp
|
|
186
|
-
* @param {number} min - Minimum value
|
|
187
|
-
* @param {number} max - Maximum value
|
|
188
|
-
* @returns {number} Clamped value
|
|
189
|
-
*
|
|
190
143
|
* @example
|
|
191
144
|
* ```typescript
|
|
192
145
|
* import { clamp } from '@fluixi/core/utils';
|
|
@@ -200,10 +153,6 @@ export declare function clamp(value: number, min: number, max: number): number;
|
|
|
200
153
|
/**
|
|
201
154
|
* Generates a random number between min and max
|
|
202
155
|
*
|
|
203
|
-
* @param {number} min - Minimum value
|
|
204
|
-
* @param {number} max - Maximum value
|
|
205
|
-
* @returns {number} Random number
|
|
206
|
-
*
|
|
207
156
|
* @example
|
|
208
157
|
* ```typescript
|
|
209
158
|
* import { random } from '@fluixi/core/utils';
|
|
@@ -215,9 +164,6 @@ export declare function random(min: number, max: number): number;
|
|
|
215
164
|
/**
|
|
216
165
|
* Checks if a value is empty
|
|
217
166
|
*
|
|
218
|
-
* @param {any} value - Value to check
|
|
219
|
-
* @returns {boolean} True if empty
|
|
220
|
-
*
|
|
221
167
|
* @example
|
|
222
168
|
* ```typescript
|
|
223
169
|
* import { isEmpty } from '@fluixi/core/utils';
|
|
@@ -233,12 +179,6 @@ export declare function isEmpty(value: any): boolean;
|
|
|
233
179
|
/**
|
|
234
180
|
* Picks specific keys from an object
|
|
235
181
|
*
|
|
236
|
-
* @template T - Object type
|
|
237
|
-
* @template K - Keys to pick
|
|
238
|
-
* @param {T} obj - Source object
|
|
239
|
-
* @param {...K[]} keys - Keys to pick
|
|
240
|
-
* @returns {Pick<T, K>} Object with picked keys
|
|
241
|
-
*
|
|
242
182
|
* @example
|
|
243
183
|
* ```typescript
|
|
244
184
|
* import { pick } from '@fluixi/core/utils';
|
|
@@ -251,12 +191,6 @@ export declare function pick<T extends object, K extends keyof T>(obj: T, ...key
|
|
|
251
191
|
/**
|
|
252
192
|
* Omits specific keys from an object
|
|
253
193
|
*
|
|
254
|
-
* @template T - Object type
|
|
255
|
-
* @template K - Keys to omit
|
|
256
|
-
* @param {T} obj - Source object
|
|
257
|
-
* @param {...K[]} keys - Keys to omit
|
|
258
|
-
* @returns {Omit<T, K>} Object without omitted keys
|
|
259
|
-
*
|
|
260
194
|
* @example
|
|
261
195
|
* ```typescript
|
|
262
196
|
* import { omit } from '@fluixi/core/utils';
|
|
@@ -269,12 +203,6 @@ export declare function omit<T extends object, K extends keyof T>(obj: T, ...key
|
|
|
269
203
|
/**
|
|
270
204
|
* Groups array items by a key
|
|
271
205
|
*
|
|
272
|
-
* @template T - Array item type
|
|
273
|
-
* @template K - Key type
|
|
274
|
-
* @param {T[]} array - Array to group
|
|
275
|
-
* @param {(item: T) => K} fn - Key extraction function
|
|
276
|
-
* @returns {Map<K, T[]>} Grouped items
|
|
277
|
-
*
|
|
278
206
|
* @example
|
|
279
207
|
* ```typescript
|
|
280
208
|
* import { groupBy } from '@fluixi/core/utils';
|
|
@@ -292,11 +220,6 @@ export declare function groupBy<T, K>(array: T[], fn: (item: T) => K): Map<K, T[
|
|
|
292
220
|
/**
|
|
293
221
|
* Creates an array of numbers from start to end
|
|
294
222
|
*
|
|
295
|
-
* @param {number} start - Start number
|
|
296
|
-
* @param {number} end - End number
|
|
297
|
-
* @param {number} step - Step size (default: 1)
|
|
298
|
-
* @returns {number[]} Array of numbers
|
|
299
|
-
*
|
|
300
223
|
* @example
|
|
301
224
|
* ```typescript
|
|
302
225
|
* import { range } from '@fluixi/core/utils';
|
|
@@ -309,12 +232,6 @@ export declare function range(start: number, end: number, step?: number): number
|
|
|
309
232
|
/**
|
|
310
233
|
* Retries an async function
|
|
311
234
|
*
|
|
312
|
-
* @template T - Return type
|
|
313
|
-
* @param {() => Promise<T>} fn - Async function to retry
|
|
314
|
-
* @param {number} retries - Number of retries (default: 3)
|
|
315
|
-
* @param {number} delay - Delay between retries in ms (default: 1000)
|
|
316
|
-
* @returns {Promise<T>} Promise that resolves with the result
|
|
317
|
-
*
|
|
318
235
|
* @example
|
|
319
236
|
* ```typescript
|
|
320
237
|
* import { retry } from '@fluixi/core/utils';
|
|
@@ -330,9 +247,6 @@ export declare function retry<T>(fn: () => Promise<T>, retries?: number, delay?:
|
|
|
330
247
|
/**
|
|
331
248
|
* Sleep for specified milliseconds
|
|
332
249
|
*
|
|
333
|
-
* @param {number} ms - Milliseconds to sleep
|
|
334
|
-
* @returns {Promise<void>} Promise that resolves after delay
|
|
335
|
-
*
|
|
336
250
|
* @example
|
|
337
251
|
* ```typescript
|
|
338
252
|
* import { sleep } from '@fluixi/core/utils';
|
|
@@ -344,10 +258,6 @@ export declare function sleep(ms: number): Promise<void>;
|
|
|
344
258
|
/**
|
|
345
259
|
* Type guard to check if value is defined
|
|
346
260
|
*
|
|
347
|
-
* @template T - Value type
|
|
348
|
-
* @param {T | null | undefined} value - Value to check
|
|
349
|
-
* @returns {value is T} True if value is defined
|
|
350
|
-
*
|
|
351
261
|
* @example
|
|
352
262
|
* ```typescript
|
|
353
263
|
* import { isDefined } from '@fluixi/core/utils';
|
|
@@ -360,9 +270,6 @@ export declare function isDefined<T>(value: T | null | undefined): value is T;
|
|
|
360
270
|
/**
|
|
361
271
|
* Creates a chainable pipe function
|
|
362
272
|
*
|
|
363
|
-
* @param {...Function[]} fns - Functions to chain
|
|
364
|
-
* @returns {Function} Piped function
|
|
365
|
-
*
|
|
366
273
|
* @example
|
|
367
274
|
* ```typescript
|
|
368
275
|
* import { pipe } from '@fluixi/core/utils';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview General utilities for Fluixi
|
|
3
2
|
* @module @fluixi/core/utils
|
|
4
3
|
*
|
|
5
4
|
* This module provides general utility functions for common operations.
|
|
@@ -7,11 +6,6 @@
|
|
|
7
6
|
/**
|
|
8
7
|
* Debounces a function call
|
|
9
8
|
*
|
|
10
|
-
* @template T - Function type
|
|
11
|
-
* @param {T} fn - Function to debounce
|
|
12
|
-
* @param {number} delay - Delay in milliseconds
|
|
13
|
-
* @returns {(...args: Parameters<T>) => void} Debounced function
|
|
14
|
-
*
|
|
15
9
|
* @example
|
|
16
10
|
* ```typescript
|
|
17
11
|
* import { debounce } from '@fluixi/core/utils';
|
|
@@ -31,11 +25,6 @@ export function debounce(fn, delay) {
|
|
|
31
25
|
/**
|
|
32
26
|
* Throttles a function call
|
|
33
27
|
*
|
|
34
|
-
* @template T - Function type
|
|
35
|
-
* @param {T} fn - Function to throttle
|
|
36
|
-
* @param {number} limit - Time limit in milliseconds
|
|
37
|
-
* @returns {(...args: Parameters<T>) => void} Throttled function
|
|
38
|
-
*
|
|
39
28
|
* @example
|
|
40
29
|
* ```typescript
|
|
41
30
|
* import { throttle } from '@fluixi/core/utils';
|
|
@@ -58,10 +47,6 @@ export function throttle(fn, limit) {
|
|
|
58
47
|
/**
|
|
59
48
|
* Creates a memoized version of a function
|
|
60
49
|
*
|
|
61
|
-
* @template T - Function type
|
|
62
|
-
* @param {T} fn - Function to memoize
|
|
63
|
-
* @returns {T} Memoized function
|
|
64
|
-
*
|
|
65
50
|
* @example
|
|
66
51
|
* ```typescript
|
|
67
52
|
* import { memoize } from '@fluixi/core/utils';
|
|
@@ -86,10 +71,6 @@ export function memoize(fn) {
|
|
|
86
71
|
/**
|
|
87
72
|
* Deep clones an object
|
|
88
73
|
*
|
|
89
|
-
* @template T - Object type
|
|
90
|
-
* @param {T} obj - Object to clone
|
|
91
|
-
* @returns {T} Cloned object
|
|
92
|
-
*
|
|
93
74
|
* @example
|
|
94
75
|
* ```typescript
|
|
95
76
|
* import { deepClone } from '@fluixi/core/utils';
|
|
@@ -128,10 +109,6 @@ export function deepClone(obj) {
|
|
|
128
109
|
/**
|
|
129
110
|
* Deep merges multiple objects
|
|
130
111
|
*
|
|
131
|
-
* @template T - Object type
|
|
132
|
-
* @param {...Partial<T>[]} objects - Objects to merge
|
|
133
|
-
* @returns {T} Merged object
|
|
134
|
-
*
|
|
135
112
|
* @example
|
|
136
113
|
* ```typescript
|
|
137
114
|
* import { deepMerge } from '@fluixi/core/utils';
|
|
@@ -165,9 +142,6 @@ export function deepMerge(...objects) {
|
|
|
165
142
|
/**
|
|
166
143
|
* Generates a unique ID
|
|
167
144
|
*
|
|
168
|
-
* @param {string} prefix - Optional prefix
|
|
169
|
-
* @returns {string} Unique ID
|
|
170
|
-
*
|
|
171
145
|
* @example
|
|
172
146
|
* ```typescript
|
|
173
147
|
* import { uniqueId } from '@fluixi/core/utils';
|
|
@@ -182,9 +156,6 @@ export function uniqueId(prefix = '') {
|
|
|
182
156
|
/**
|
|
183
157
|
* Formats a number with commas
|
|
184
158
|
*
|
|
185
|
-
* @param {number} num - Number to format
|
|
186
|
-
* @returns {string} Formatted number
|
|
187
|
-
*
|
|
188
159
|
* @example
|
|
189
160
|
* ```typescript
|
|
190
161
|
* import { formatNumber } from '@fluixi/core/utils';
|
|
@@ -198,10 +169,6 @@ export function formatNumber(num) {
|
|
|
198
169
|
/**
|
|
199
170
|
* Formats bytes to human readable string
|
|
200
171
|
*
|
|
201
|
-
* @param {number} bytes - Number of bytes
|
|
202
|
-
* @param {number} decimals - Decimal places (default: 2)
|
|
203
|
-
* @returns {string} Formatted string
|
|
204
|
-
*
|
|
205
172
|
* @example
|
|
206
173
|
* ```typescript
|
|
207
174
|
* import { formatBytes } from '@fluixi/core/utils';
|
|
@@ -222,9 +189,6 @@ export function formatBytes(bytes, decimals = 2) {
|
|
|
222
189
|
/**
|
|
223
190
|
* Capitalizes first letter of a string
|
|
224
191
|
*
|
|
225
|
-
* @param {string} str - String to capitalize
|
|
226
|
-
* @returns {string} Capitalized string
|
|
227
|
-
*
|
|
228
192
|
* @example
|
|
229
193
|
* ```typescript
|
|
230
194
|
* import { capitalize } from '@fluixi/core/utils';
|
|
@@ -238,9 +202,6 @@ export function capitalize(str) {
|
|
|
238
202
|
/**
|
|
239
203
|
* Converts string to kebab-case
|
|
240
204
|
*
|
|
241
|
-
* @param {string} str - String to convert
|
|
242
|
-
* @returns {string} Kebab-case string
|
|
243
|
-
*
|
|
244
205
|
* @example
|
|
245
206
|
* ```typescript
|
|
246
207
|
* import { kebabCase } from '@fluixi/core/utils';
|
|
@@ -257,9 +218,6 @@ export function kebabCase(str) {
|
|
|
257
218
|
/**
|
|
258
219
|
* Converts string to camelCase
|
|
259
220
|
*
|
|
260
|
-
* @param {string} str - String to convert
|
|
261
|
-
* @returns {string} CamelCase string
|
|
262
|
-
*
|
|
263
221
|
* @example
|
|
264
222
|
* ```typescript
|
|
265
223
|
* import { camelCase } from '@fluixi/core/utils';
|
|
@@ -273,11 +231,6 @@ export function camelCase(str) {
|
|
|
273
231
|
/**
|
|
274
232
|
* Clamps a number between min and max
|
|
275
233
|
*
|
|
276
|
-
* @param {number} value - Value to clamp
|
|
277
|
-
* @param {number} min - Minimum value
|
|
278
|
-
* @param {number} max - Maximum value
|
|
279
|
-
* @returns {number} Clamped value
|
|
280
|
-
*
|
|
281
234
|
* @example
|
|
282
235
|
* ```typescript
|
|
283
236
|
* import { clamp } from '@fluixi/core/utils';
|
|
@@ -293,10 +246,6 @@ export function clamp(value, min, max) {
|
|
|
293
246
|
/**
|
|
294
247
|
* Generates a random number between min and max
|
|
295
248
|
*
|
|
296
|
-
* @param {number} min - Minimum value
|
|
297
|
-
* @param {number} max - Maximum value
|
|
298
|
-
* @returns {number} Random number
|
|
299
|
-
*
|
|
300
249
|
* @example
|
|
301
250
|
* ```typescript
|
|
302
251
|
* import { random } from '@fluixi/core/utils';
|
|
@@ -310,9 +259,6 @@ export function random(min, max) {
|
|
|
310
259
|
/**
|
|
311
260
|
* Checks if a value is empty
|
|
312
261
|
*
|
|
313
|
-
* @param {any} value - Value to check
|
|
314
|
-
* @returns {boolean} True if empty
|
|
315
|
-
*
|
|
316
262
|
* @example
|
|
317
263
|
* ```typescript
|
|
318
264
|
* import { isEmpty } from '@fluixi/core/utils';
|
|
@@ -338,12 +284,6 @@ export function isEmpty(value) {
|
|
|
338
284
|
/**
|
|
339
285
|
* Picks specific keys from an object
|
|
340
286
|
*
|
|
341
|
-
* @template T - Object type
|
|
342
|
-
* @template K - Keys to pick
|
|
343
|
-
* @param {T} obj - Source object
|
|
344
|
-
* @param {...K[]} keys - Keys to pick
|
|
345
|
-
* @returns {Pick<T, K>} Object with picked keys
|
|
346
|
-
*
|
|
347
287
|
* @example
|
|
348
288
|
* ```typescript
|
|
349
289
|
* import { pick } from '@fluixi/core/utils';
|
|
@@ -364,12 +304,6 @@ export function pick(obj, ...keys) {
|
|
|
364
304
|
/**
|
|
365
305
|
* Omits specific keys from an object
|
|
366
306
|
*
|
|
367
|
-
* @template T - Object type
|
|
368
|
-
* @template K - Keys to omit
|
|
369
|
-
* @param {T} obj - Source object
|
|
370
|
-
* @param {...K[]} keys - Keys to omit
|
|
371
|
-
* @returns {Omit<T, K>} Object without omitted keys
|
|
372
|
-
*
|
|
373
307
|
* @example
|
|
374
308
|
* ```typescript
|
|
375
309
|
* import { omit } from '@fluixi/core/utils';
|
|
@@ -388,12 +322,6 @@ export function omit(obj, ...keys) {
|
|
|
388
322
|
/**
|
|
389
323
|
* Groups array items by a key
|
|
390
324
|
*
|
|
391
|
-
* @template T - Array item type
|
|
392
|
-
* @template K - Key type
|
|
393
|
-
* @param {T[]} array - Array to group
|
|
394
|
-
* @param {(item: T) => K} fn - Key extraction function
|
|
395
|
-
* @returns {Map<K, T[]>} Grouped items
|
|
396
|
-
*
|
|
397
325
|
* @example
|
|
398
326
|
* ```typescript
|
|
399
327
|
* import { groupBy } from '@fluixi/core/utils';
|
|
@@ -419,11 +347,6 @@ export function groupBy(array, fn) {
|
|
|
419
347
|
/**
|
|
420
348
|
* Creates an array of numbers from start to end
|
|
421
349
|
*
|
|
422
|
-
* @param {number} start - Start number
|
|
423
|
-
* @param {number} end - End number
|
|
424
|
-
* @param {number} step - Step size (default: 1)
|
|
425
|
-
* @returns {number[]} Array of numbers
|
|
426
|
-
*
|
|
427
350
|
* @example
|
|
428
351
|
* ```typescript
|
|
429
352
|
* import { range } from '@fluixi/core/utils';
|
|
@@ -442,12 +365,6 @@ export function range(start, end, step = 1) {
|
|
|
442
365
|
/**
|
|
443
366
|
* Retries an async function
|
|
444
367
|
*
|
|
445
|
-
* @template T - Return type
|
|
446
|
-
* @param {() => Promise<T>} fn - Async function to retry
|
|
447
|
-
* @param {number} retries - Number of retries (default: 3)
|
|
448
|
-
* @param {number} delay - Delay between retries in ms (default: 1000)
|
|
449
|
-
* @returns {Promise<T>} Promise that resolves with the result
|
|
450
|
-
*
|
|
451
368
|
* @example
|
|
452
369
|
* ```typescript
|
|
453
370
|
* import { retry } from '@fluixi/core/utils';
|
|
@@ -473,9 +390,6 @@ export async function retry(fn, retries = 3, delay = 1000) {
|
|
|
473
390
|
/**
|
|
474
391
|
* Sleep for specified milliseconds
|
|
475
392
|
*
|
|
476
|
-
* @param {number} ms - Milliseconds to sleep
|
|
477
|
-
* @returns {Promise<void>} Promise that resolves after delay
|
|
478
|
-
*
|
|
479
393
|
* @example
|
|
480
394
|
* ```typescript
|
|
481
395
|
* import { sleep } from '@fluixi/core/utils';
|
|
@@ -489,10 +403,6 @@ export function sleep(ms) {
|
|
|
489
403
|
/**
|
|
490
404
|
* Type guard to check if value is defined
|
|
491
405
|
*
|
|
492
|
-
* @template T - Value type
|
|
493
|
-
* @param {T | null | undefined} value - Value to check
|
|
494
|
-
* @returns {value is T} True if value is defined
|
|
495
|
-
*
|
|
496
406
|
* @example
|
|
497
407
|
* ```typescript
|
|
498
408
|
* import { isDefined } from '@fluixi/core/utils';
|
|
@@ -507,9 +417,6 @@ export function isDefined(value) {
|
|
|
507
417
|
/**
|
|
508
418
|
* Creates a chainable pipe function
|
|
509
419
|
*
|
|
510
|
-
* @param {...Function[]} fns - Functions to chain
|
|
511
|
-
* @returns {Function} Piped function
|
|
512
|
-
*
|
|
513
420
|
* @example
|
|
514
421
|
* ```typescript
|
|
515
422
|
* import { pipe } from '@fluixi/core/utils';
|
|
@@ -1 +1,188 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/utils/index.ts
|
|
2
|
+
function debounce(fn, delay) {
|
|
3
|
+
let timeoutId;
|
|
4
|
+
return (...args) => {
|
|
5
|
+
clearTimeout(timeoutId);
|
|
6
|
+
timeoutId = setTimeout(() => fn(...args), delay);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function throttle(fn, limit) {
|
|
10
|
+
let inThrottle;
|
|
11
|
+
return (...args) => {
|
|
12
|
+
if (!inThrottle) {
|
|
13
|
+
fn(...args);
|
|
14
|
+
inThrottle = true;
|
|
15
|
+
setTimeout(() => inThrottle = false, limit);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function memoize(fn) {
|
|
20
|
+
const cache = /* @__PURE__ */ new Map();
|
|
21
|
+
return ((...args) => {
|
|
22
|
+
const key = JSON.stringify(args);
|
|
23
|
+
if (cache.has(key)) {
|
|
24
|
+
return cache.get(key);
|
|
25
|
+
}
|
|
26
|
+
const result = fn(...args);
|
|
27
|
+
cache.set(key, result);
|
|
28
|
+
return result;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function deepClone(obj) {
|
|
32
|
+
if (obj === null || typeof obj !== "object") {
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
if (obj instanceof Date) {
|
|
36
|
+
return new Date(obj.getTime());
|
|
37
|
+
}
|
|
38
|
+
if (obj instanceof Array) {
|
|
39
|
+
return Array.from(obj).map((item) => deepClone(item));
|
|
40
|
+
}
|
|
41
|
+
if (obj instanceof Set) {
|
|
42
|
+
return new Set(Array.from(obj).map((item) => deepClone(item)));
|
|
43
|
+
}
|
|
44
|
+
if (obj instanceof Map) {
|
|
45
|
+
return new Map(
|
|
46
|
+
Array.from(obj.entries()).map(([key, value]) => [
|
|
47
|
+
deepClone(key),
|
|
48
|
+
deepClone(value)
|
|
49
|
+
])
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const clonedObj = {};
|
|
53
|
+
for (const key in obj) {
|
|
54
|
+
if (obj.hasOwnProperty(key)) {
|
|
55
|
+
clonedObj[key] = deepClone(obj[key]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return clonedObj;
|
|
59
|
+
}
|
|
60
|
+
function deepMerge(...objects) {
|
|
61
|
+
const result = {};
|
|
62
|
+
for (const obj of objects) {
|
|
63
|
+
for (const key in obj) {
|
|
64
|
+
if (obj.hasOwnProperty(key)) {
|
|
65
|
+
const value = obj[key];
|
|
66
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
67
|
+
result[key] = deepMerge(
|
|
68
|
+
result[key] || {},
|
|
69
|
+
value
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
result[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function uniqueId(prefix = "") {
|
|
80
|
+
return prefix + Math.random().toString(36).substr(2, 9);
|
|
81
|
+
}
|
|
82
|
+
function formatNumber(num) {
|
|
83
|
+
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
84
|
+
}
|
|
85
|
+
function formatBytes(bytes, decimals = 2) {
|
|
86
|
+
if (bytes === 0) return "0 Bytes";
|
|
87
|
+
const k = 1024;
|
|
88
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
89
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
|
|
90
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
91
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
|
92
|
+
}
|
|
93
|
+
function capitalize(str) {
|
|
94
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
95
|
+
}
|
|
96
|
+
function kebabCase(str) {
|
|
97
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
98
|
+
}
|
|
99
|
+
function camelCase(str) {
|
|
100
|
+
return str.replace(/[-_\s](.)/g, (_, char) => char.toUpperCase());
|
|
101
|
+
}
|
|
102
|
+
function clamp(value, min, max) {
|
|
103
|
+
return Math.min(Math.max(value, min), max);
|
|
104
|
+
}
|
|
105
|
+
function random(min, max) {
|
|
106
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
107
|
+
}
|
|
108
|
+
function isEmpty(value) {
|
|
109
|
+
if (value === null || value === void 0) return true;
|
|
110
|
+
if (typeof value === "string") return value.trim().length === 0;
|
|
111
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
112
|
+
if (typeof value === "object") return Object.keys(value).length === 0;
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
function pick(obj, ...keys) {
|
|
116
|
+
const result = {};
|
|
117
|
+
keys.forEach((key) => {
|
|
118
|
+
if (key in obj) {
|
|
119
|
+
result[key] = obj[key];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function omit(obj, ...keys) {
|
|
125
|
+
const result = { ...obj };
|
|
126
|
+
keys.forEach((key) => {
|
|
127
|
+
delete result[key];
|
|
128
|
+
});
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function groupBy(array, fn) {
|
|
132
|
+
return array.reduce((acc, item) => {
|
|
133
|
+
const key = fn(item);
|
|
134
|
+
const group = acc.get(key) || [];
|
|
135
|
+
group.push(item);
|
|
136
|
+
acc.set(key, group);
|
|
137
|
+
return acc;
|
|
138
|
+
}, /* @__PURE__ */ new Map());
|
|
139
|
+
}
|
|
140
|
+
function range(start, end, step = 1) {
|
|
141
|
+
const result = [];
|
|
142
|
+
for (let i = start; i <= end; i += step) {
|
|
143
|
+
result.push(i);
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
async function retry(fn, retries = 3, delay = 1e3) {
|
|
148
|
+
try {
|
|
149
|
+
return await fn();
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (retries <= 0) throw error;
|
|
152
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
153
|
+
return retry(fn, retries - 1, delay);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function sleep(ms) {
|
|
157
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
158
|
+
}
|
|
159
|
+
function isDefined(value) {
|
|
160
|
+
return value !== null && value !== void 0;
|
|
161
|
+
}
|
|
162
|
+
function pipe(...fns) {
|
|
163
|
+
return (arg) => fns.reduce((acc, fn) => fn(acc), arg);
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
camelCase,
|
|
167
|
+
capitalize,
|
|
168
|
+
clamp,
|
|
169
|
+
debounce,
|
|
170
|
+
deepClone,
|
|
171
|
+
deepMerge,
|
|
172
|
+
formatBytes,
|
|
173
|
+
formatNumber,
|
|
174
|
+
groupBy,
|
|
175
|
+
isDefined,
|
|
176
|
+
isEmpty,
|
|
177
|
+
kebabCase,
|
|
178
|
+
memoize,
|
|
179
|
+
omit,
|
|
180
|
+
pick,
|
|
181
|
+
pipe,
|
|
182
|
+
random,
|
|
183
|
+
range,
|
|
184
|
+
retry,
|
|
185
|
+
sleep,
|
|
186
|
+
throttle,
|
|
187
|
+
uniqueId
|
|
188
|
+
};
|