zero-query 0.9.0 → 0.9.5

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/types/store.d.ts CHANGED
@@ -23,6 +23,9 @@ export interface StoreConfig<
23
23
 
24
24
  /** Log dispatched actions to the console. */
25
25
  debug?: boolean;
26
+
27
+ /** Maximum number of action history entries to keep (default `1000`). */
28
+ maxHistory?: number;
26
29
  }
27
30
 
28
31
  /** A store action history entry. */
package/types/utils.d.ts CHANGED
@@ -48,6 +48,9 @@ export function sleep(ms: number): Promise<void>;
48
48
  /** Escape HTML entities: `&`, `<`, `>`, `"`, `'`. */
49
49
  export function escapeHtml(str: string): string;
50
50
 
51
+ /** Strip all HTML tags from a string, returning only text content. */
52
+ export function stripHtml(str: string): string;
53
+
51
54
  /**
52
55
  * Tagged template literal that auto-escapes interpolated values.
53
56
  * Use `$.trust()` to mark values as safe.
@@ -140,3 +143,103 @@ export interface EventBus {
140
143
 
141
144
  /** Global event bus instance. */
142
145
  export declare const bus: EventBus;
146
+
147
+ // ---------------------------------------------------------------------------
148
+ // Array Utilities
149
+ // ---------------------------------------------------------------------------
150
+
151
+ /**
152
+ * Generate a range of numbers.
153
+ * - `range(n)` → `[0, 1, ..., n-1]`
154
+ * - `range(start, end)` → `[start, start+1, ..., end-1]`
155
+ * - `range(start, end, step)` → stepped range
156
+ */
157
+ export function range(end: number): number[];
158
+ export function range(start: number, end: number, step?: number): number[];
159
+
160
+ /** Deduplicate an array. Optional `keyFn` for object identity. */
161
+ export function unique<T>(arr: T[], keyFn?: (item: T) => any): T[];
162
+
163
+ /** Split an array into chunks of `size`. */
164
+ export function chunk<T>(arr: T[], size: number): T[][];
165
+
166
+ /** Group array elements by a key function. */
167
+ export function groupBy<T>(arr: T[], keyFn: (item: T) => string): Record<string, T[]>;
168
+
169
+ // ---------------------------------------------------------------------------
170
+ // Object Utilities (extended)
171
+ // ---------------------------------------------------------------------------
172
+
173
+ /** Pick specified keys from an object. */
174
+ export function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
175
+
176
+ /** Omit specified keys from an object. */
177
+ export function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
178
+
179
+ /** Get a deeply nested value by dot-path string. */
180
+ export function getPath<T = any>(obj: any, path: string, fallback?: T): T;
181
+
182
+ /** Set a deeply nested value by dot-path string. Returns the object. */
183
+ export function setPath<T extends object>(obj: T, path: string, value: any): T;
184
+
185
+ /** Check if a value is empty (null, undefined, '', [], {}, empty Map/Set). */
186
+ export function isEmpty(val: any): boolean;
187
+
188
+ // ---------------------------------------------------------------------------
189
+ // String Utilities (extended)
190
+ // ---------------------------------------------------------------------------
191
+
192
+ /** Capitalize the first letter and lowercase the rest. */
193
+ export function capitalize(str: string): string;
194
+
195
+ /** Truncate a string to `maxLen`, appending `suffix` (default `'…'`). */
196
+ export function truncate(str: string, maxLen: number, suffix?: string): string;
197
+
198
+ // ---------------------------------------------------------------------------
199
+ // Number Utilities
200
+ // ---------------------------------------------------------------------------
201
+
202
+ /** Clamp a number between `min` and `max` (inclusive). */
203
+ export function clamp(val: number, min: number, max: number): number;
204
+
205
+ // ---------------------------------------------------------------------------
206
+ // Function Utilities (extended)
207
+ // ---------------------------------------------------------------------------
208
+
209
+ /** Memoized function with `.clear()` to reset cache. */
210
+ export interface MemoizedFunction<T extends (...args: any[]) => any> {
211
+ (...args: Parameters<T>): ReturnType<T>;
212
+ clear(): void;
213
+ }
214
+
215
+ /**
216
+ * Memoize a function. Supports custom key function or `{ maxSize }` option.
217
+ */
218
+ export function memoize<T extends (...args: any[]) => any>(fn: T, keyFn?: (...args: Parameters<T>) => any): MemoizedFunction<T>;
219
+ export function memoize<T extends (...args: any[]) => any>(fn: T, opts?: { maxSize?: number }): MemoizedFunction<T>;
220
+
221
+ // ---------------------------------------------------------------------------
222
+ // Async Utilities
223
+ // ---------------------------------------------------------------------------
224
+
225
+ /** Options for `retry`. */
226
+ export interface RetryOptions {
227
+ /** Max attempts (default `3`). */
228
+ attempts?: number;
229
+ /** Initial delay in ms (default `1000`). */
230
+ delay?: number;
231
+ /** Backoff multiplier (default `1`). */
232
+ backoff?: number;
233
+ }
234
+
235
+ /**
236
+ * Retry an async function with configurable backoff.
237
+ * The function receives the current attempt number (1-based).
238
+ */
239
+ export function retry<T>(fn: (attempt: number) => Promise<T>, opts?: RetryOptions): Promise<T>;
240
+
241
+ /**
242
+ * Race a promise against a timeout.
243
+ * Rejects with an Error if the timeout is reached first.
244
+ */
245
+ export function timeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>;