zero-query 1.1.1 → 1.2.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/LICENSE +21 -21
- package/README.md +2 -0
- package/cli/args.js +33 -33
- package/cli/commands/build-api.js +443 -442
- package/cli/commands/build.js +254 -247
- package/cli/commands/bundle.js +1228 -1224
- package/cli/commands/create.js +137 -121
- package/cli/commands/dev/devtools/index.js +56 -56
- package/cli/commands/dev/devtools/js/components.js +49 -49
- package/cli/commands/dev/devtools/js/core.js +423 -423
- package/cli/commands/dev/devtools/js/elements.js +421 -421
- package/cli/commands/dev/devtools/js/network.js +166 -166
- package/cli/commands/dev/devtools/js/performance.js +73 -73
- package/cli/commands/dev/devtools/js/router.js +105 -105
- package/cli/commands/dev/devtools/js/source.js +132 -132
- package/cli/commands/dev/devtools/js/stats.js +35 -35
- package/cli/commands/dev/devtools/js/tabs.js +79 -79
- package/cli/commands/dev/devtools/panel.html +95 -95
- package/cli/commands/dev/devtools/styles.css +244 -244
- package/cli/commands/dev/index.js +107 -107
- package/cli/commands/dev/logger.js +75 -75
- package/cli/commands/dev/overlay.js +858 -858
- package/cli/commands/dev/server.js +220 -220
- package/cli/commands/dev/validator.js +94 -94
- package/cli/commands/dev/watcher.js +172 -172
- package/cli/help.js +114 -112
- package/cli/index.js +52 -52
- package/cli/scaffold/default/LICENSE +21 -21
- package/cli/scaffold/default/app/app.js +207 -207
- package/cli/scaffold/default/app/components/about.js +201 -201
- package/cli/scaffold/default/app/components/api-demo.js +143 -143
- package/cli/scaffold/default/app/components/contact-card.js +231 -231
- package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
- package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
- package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
- package/cli/scaffold/default/app/components/counter.js +127 -127
- package/cli/scaffold/default/app/components/home.js +249 -249
- package/cli/scaffold/default/app/components/not-found.js +16 -16
- package/cli/scaffold/default/app/components/playground/playground.css +115 -115
- package/cli/scaffold/default/app/components/playground/playground.html +161 -161
- package/cli/scaffold/default/app/components/playground/playground.js +116 -116
- package/cli/scaffold/default/app/components/todos.js +225 -225
- package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
- package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
- package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
- package/cli/scaffold/default/app/routes.js +15 -15
- package/cli/scaffold/default/app/store.js +101 -101
- package/cli/scaffold/default/global.css +552 -552
- package/cli/scaffold/default/index.html +99 -99
- package/cli/scaffold/minimal/app/app.js +85 -85
- package/cli/scaffold/minimal/app/components/about.js +68 -68
- package/cli/scaffold/minimal/app/components/counter.js +122 -122
- package/cli/scaffold/minimal/app/components/home.js +68 -68
- package/cli/scaffold/minimal/app/components/not-found.js +16 -16
- package/cli/scaffold/minimal/app/routes.js +9 -9
- package/cli/scaffold/minimal/app/store.js +36 -36
- package/cli/scaffold/minimal/global.css +300 -300
- package/cli/scaffold/minimal/index.html +44 -44
- package/cli/scaffold/ssr/app/app.js +41 -41
- package/cli/scaffold/ssr/app/components/about.js +55 -55
- package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
- package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
- package/cli/scaffold/ssr/app/components/home.js +37 -37
- package/cli/scaffold/ssr/app/components/not-found.js +15 -15
- package/cli/scaffold/ssr/app/routes.js +8 -8
- package/cli/scaffold/ssr/global.css +228 -228
- package/cli/scaffold/ssr/index.html +37 -37
- package/cli/scaffold/ssr/package.json +8 -8
- package/cli/scaffold/ssr/server/data/posts.js +144 -144
- package/cli/scaffold/ssr/server/index.js +213 -213
- package/cli/scaffold/webrtc/app/app.js +11 -0
- package/cli/scaffold/webrtc/app/components/video-room.js +295 -0
- package/cli/scaffold/webrtc/app/lib/room.js +252 -0
- package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
- package/cli/scaffold/webrtc/global.css +250 -0
- package/cli/scaffold/webrtc/index.html +21 -0
- package/cli/utils.js +305 -287
- package/dist/API.md +661 -0
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +10313 -6614
- package/dist/zquery.min.js +8 -631
- package/index.d.ts +570 -371
- package/index.js +311 -240
- package/package.json +76 -70
- package/src/component.js +1709 -1691
- package/src/core.js +921 -921
- package/src/diff.js +497 -497
- package/src/errors.js +209 -209
- package/src/expression.js +922 -922
- package/src/http.js +242 -242
- package/src/package.json +1 -1
- package/src/reactive.js +255 -255
- package/src/router.js +843 -843
- package/src/ssr.js +418 -418
- package/src/store.js +318 -318
- package/src/utils.js +515 -515
- package/src/webrtc/e2ee.js +351 -0
- package/src/webrtc/errors.js +116 -0
- package/src/webrtc/ice.js +301 -0
- package/src/webrtc/index.js +131 -0
- package/src/webrtc/joinToken.js +119 -0
- package/src/webrtc/observe.js +172 -0
- package/src/webrtc/peer.js +351 -0
- package/src/webrtc/reactive.js +268 -0
- package/src/webrtc/room.js +625 -0
- package/src/webrtc/sdp.js +302 -0
- package/src/webrtc/sfu/index.js +43 -0
- package/src/webrtc/sfu/livekit.js +131 -0
- package/src/webrtc/sfu/mediasoup.js +150 -0
- package/src/webrtc/signaling.js +373 -0
- package/src/webrtc/turn.js +237 -0
- package/tests/_helpers/webrtcFakes.js +289 -0
- package/tests/audit.test.js +4158 -4158
- package/tests/cli.test.js +1136 -1103
- package/tests/compare.test.js +497 -486
- package/tests/component.test.js +3969 -3938
- package/tests/core.test.js +1910 -1910
- package/tests/dev-server.test.js +489 -489
- package/tests/diff.test.js +1416 -1416
- package/tests/docs.test.js +1664 -1650
- package/tests/electron-features.test.js +864 -864
- package/tests/errors.test.js +619 -619
- package/tests/expression.test.js +1056 -1056
- package/tests/http.test.js +648 -648
- package/tests/reactive.test.js +819 -819
- package/tests/router.test.js +2327 -2327
- package/tests/ssr.test.js +870 -870
- package/tests/store.test.js +830 -830
- package/tests/test-minifier.js +153 -153
- package/tests/test-ssr.js +27 -27
- package/tests/utils.test.js +1377 -1377
- package/tests/webrtc/e2ee.test.js +283 -0
- package/tests/webrtc/ice.test.js +202 -0
- package/tests/webrtc/joinToken.test.js +89 -0
- package/tests/webrtc/observe.test.js +111 -0
- package/tests/webrtc/peer.test.js +373 -0
- package/tests/webrtc/reactive.test.js +235 -0
- package/tests/webrtc/room.test.js +406 -0
- package/tests/webrtc/sdp.test.js +151 -0
- package/tests/webrtc/sfu-livekit.test.js +119 -0
- package/tests/webrtc/sfu.test.js +160 -0
- package/tests/webrtc/signaling.test.js +251 -0
- package/tests/webrtc/turn.test.js +256 -0
- package/types/collection.d.ts +383 -383
- package/types/component.d.ts +186 -186
- package/types/errors.d.ts +135 -135
- package/types/http.d.ts +92 -92
- package/types/misc.d.ts +201 -201
- package/types/reactive.d.ts +98 -98
- package/types/router.d.ts +190 -190
- package/types/ssr.d.ts +102 -102
- package/types/store.d.ts +146 -146
- package/types/utils.d.ts +245 -245
- package/types/webrtc.d.ts +653 -0
package/types/utils.d.ts
CHANGED
|
@@ -1,245 +1,245 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions - debounce, throttle, strings, objects, URL, storage, event bus.
|
|
3
|
-
*
|
|
4
|
-
* @module utils
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
// Function Utilities
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
/** Debounced function with a `.cancel()` helper. */
|
|
12
|
-
export interface DebouncedFunction<T extends (...args: any[]) => any> {
|
|
13
|
-
(...args: Parameters<T>): void;
|
|
14
|
-
/** Cancel the pending invocation. */
|
|
15
|
-
cancel(): void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns a debounced function that delays execution until `ms` ms of inactivity.
|
|
20
|
-
* @param ms Default `250`.
|
|
21
|
-
*/
|
|
22
|
-
export function debounce<T extends (...args: any[]) => any>(fn: T, ms?: number): DebouncedFunction<T>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Returns a throttled function that executes at most once per `ms` ms.
|
|
26
|
-
* The return value of the original function is discarded.
|
|
27
|
-
* @param ms Default `250`.
|
|
28
|
-
*/
|
|
29
|
-
export function throttle<T extends (...args: any[]) => any>(fn: T, ms?: number): (...args: Parameters<T>) => void;
|
|
30
|
-
|
|
31
|
-
/** Left-to-right function composition. */
|
|
32
|
-
export function pipe<A, B>(f1: (a: A) => B): (input: A) => B;
|
|
33
|
-
export function pipe<A, B, C>(f1: (a: A) => B, f2: (b: B) => C): (input: A) => C;
|
|
34
|
-
export function pipe<A, B, C, D>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D): (input: A) => D;
|
|
35
|
-
export function pipe<A, B, C, D, E>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D, f4: (d: D) => E): (input: A) => E;
|
|
36
|
-
export function pipe<T>(...fns: Array<(value: any) => any>): (input: T) => any;
|
|
37
|
-
|
|
38
|
-
/** Returns a function that only executes once, caching the result. */
|
|
39
|
-
export function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
40
|
-
|
|
41
|
-
/** Returns a `Promise` that resolves after `ms` milliseconds. */
|
|
42
|
-
export function sleep(ms: number): Promise<void>;
|
|
43
|
-
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
// String Utilities
|
|
46
|
-
// ---------------------------------------------------------------------------
|
|
47
|
-
|
|
48
|
-
/** Escape HTML entities: `&`, `<`, `>`, `"`, `'`. */
|
|
49
|
-
export function escapeHtml(str: string): string;
|
|
50
|
-
|
|
51
|
-
/** Strip all HTML tags from a string, returning only text content. */
|
|
52
|
-
export function stripHtml(str: string): string;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Tagged template literal that auto-escapes interpolated values.
|
|
56
|
-
* Use `$.trust()` to mark values as safe.
|
|
57
|
-
*/
|
|
58
|
-
export function html(strings: TemplateStringsArray, ...values: any[]): string;
|
|
59
|
-
|
|
60
|
-
/** Wrapper that marks an HTML string as trusted (not escaped by `$.html`). */
|
|
61
|
-
export interface TrustedHTML {
|
|
62
|
-
toString(): string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Mark an HTML string as trusted so it won't be escaped in `$.html`. */
|
|
66
|
-
export function trust(htmlStr: string): TrustedHTML;
|
|
67
|
-
|
|
68
|
-
/** Generate a UUID v4 string. */
|
|
69
|
-
export function uuid(): string;
|
|
70
|
-
|
|
71
|
-
/** Convert kebab-case to camelCase. */
|
|
72
|
-
export function camelCase(str: string): string;
|
|
73
|
-
|
|
74
|
-
/** Convert camelCase to kebab-case. */
|
|
75
|
-
export function kebabCase(str: string): string;
|
|
76
|
-
|
|
77
|
-
// ---------------------------------------------------------------------------
|
|
78
|
-
// Object Utilities
|
|
79
|
-
// ---------------------------------------------------------------------------
|
|
80
|
-
|
|
81
|
-
/** Deep clone using `structuredClone` (JSON fallback). */
|
|
82
|
-
export function deepClone<T>(obj: T): T;
|
|
83
|
-
|
|
84
|
-
/** Recursively merge objects. Arrays are replaced, not merged. */
|
|
85
|
-
export function deepMerge<T extends object>(target: T, ...sources: Partial<T>[]): T;
|
|
86
|
-
|
|
87
|
-
/** Deep equality comparison. */
|
|
88
|
-
export function isEqual(a: any, b: any): boolean;
|
|
89
|
-
|
|
90
|
-
// ---------------------------------------------------------------------------
|
|
91
|
-
// URL Utilities
|
|
92
|
-
// ---------------------------------------------------------------------------
|
|
93
|
-
|
|
94
|
-
/** Serialize an object to a URL query string. */
|
|
95
|
-
export function param(obj: Record<string, any>): string;
|
|
96
|
-
|
|
97
|
-
/** Parse a URL query string into an object. */
|
|
98
|
-
export function parseQuery(str: string): Record<string, string>;
|
|
99
|
-
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
// Storage Wrappers
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
|
|
104
|
-
/** JSON-aware storage wrapper (localStorage or sessionStorage). */
|
|
105
|
-
export interface StorageWrapper {
|
|
106
|
-
/**
|
|
107
|
-
* Get and JSON-parse a value.
|
|
108
|
-
* @param key Storage key.
|
|
109
|
-
* @param fallback Value returned if key is missing or parse fails (default `null`).
|
|
110
|
-
*/
|
|
111
|
-
get<T = any>(key: string, fallback?: T): T;
|
|
112
|
-
/** JSON-stringify and store. */
|
|
113
|
-
set(key: string, value: any): void;
|
|
114
|
-
/** Remove a key. */
|
|
115
|
-
remove(key: string): void;
|
|
116
|
-
/** Clear all entries. */
|
|
117
|
-
clear(): void;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** `localStorage` wrapper with auto JSON serialization. */
|
|
121
|
-
export declare const storage: StorageWrapper;
|
|
122
|
-
|
|
123
|
-
/** `sessionStorage` wrapper (same API as `storage`). */
|
|
124
|
-
export declare const session: StorageWrapper;
|
|
125
|
-
|
|
126
|
-
// ---------------------------------------------------------------------------
|
|
127
|
-
// Event Bus
|
|
128
|
-
// ---------------------------------------------------------------------------
|
|
129
|
-
|
|
130
|
-
/** Singleton pub/sub event bus for cross-component communication. */
|
|
131
|
-
export interface EventBus {
|
|
132
|
-
/** Subscribe. Returns an unsubscribe function. */
|
|
133
|
-
on(event: string, fn: (...args: any[]) => void): () => void;
|
|
134
|
-
/** Unsubscribe a specific handler. */
|
|
135
|
-
off(event: string, fn: (...args: any[]) => void): void;
|
|
136
|
-
/** Emit an event with arguments. */
|
|
137
|
-
emit(event: string, ...args: any[]): void;
|
|
138
|
-
/** Subscribe for a single invocation. Returns an unsubscribe function. */
|
|
139
|
-
once(event: string, fn: (...args: any[]) => void): () => void;
|
|
140
|
-
/** Remove all listeners. */
|
|
141
|
-
clear(): void;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Global event bus instance. */
|
|
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>;
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions - debounce, throttle, strings, objects, URL, storage, event bus.
|
|
3
|
+
*
|
|
4
|
+
* @module utils
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Function Utilities
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/** Debounced function with a `.cancel()` helper. */
|
|
12
|
+
export interface DebouncedFunction<T extends (...args: any[]) => any> {
|
|
13
|
+
(...args: Parameters<T>): void;
|
|
14
|
+
/** Cancel the pending invocation. */
|
|
15
|
+
cancel(): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a debounced function that delays execution until `ms` ms of inactivity.
|
|
20
|
+
* @param ms Default `250`.
|
|
21
|
+
*/
|
|
22
|
+
export function debounce<T extends (...args: any[]) => any>(fn: T, ms?: number): DebouncedFunction<T>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns a throttled function that executes at most once per `ms` ms.
|
|
26
|
+
* The return value of the original function is discarded.
|
|
27
|
+
* @param ms Default `250`.
|
|
28
|
+
*/
|
|
29
|
+
export function throttle<T extends (...args: any[]) => any>(fn: T, ms?: number): (...args: Parameters<T>) => void;
|
|
30
|
+
|
|
31
|
+
/** Left-to-right function composition. */
|
|
32
|
+
export function pipe<A, B>(f1: (a: A) => B): (input: A) => B;
|
|
33
|
+
export function pipe<A, B, C>(f1: (a: A) => B, f2: (b: B) => C): (input: A) => C;
|
|
34
|
+
export function pipe<A, B, C, D>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D): (input: A) => D;
|
|
35
|
+
export function pipe<A, B, C, D, E>(f1: (a: A) => B, f2: (b: B) => C, f3: (c: C) => D, f4: (d: D) => E): (input: A) => E;
|
|
36
|
+
export function pipe<T>(...fns: Array<(value: any) => any>): (input: T) => any;
|
|
37
|
+
|
|
38
|
+
/** Returns a function that only executes once, caching the result. */
|
|
39
|
+
export function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
40
|
+
|
|
41
|
+
/** Returns a `Promise` that resolves after `ms` milliseconds. */
|
|
42
|
+
export function sleep(ms: number): Promise<void>;
|
|
43
|
+
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// String Utilities
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
/** Escape HTML entities: `&`, `<`, `>`, `"`, `'`. */
|
|
49
|
+
export function escapeHtml(str: string): string;
|
|
50
|
+
|
|
51
|
+
/** Strip all HTML tags from a string, returning only text content. */
|
|
52
|
+
export function stripHtml(str: string): string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Tagged template literal that auto-escapes interpolated values.
|
|
56
|
+
* Use `$.trust()` to mark values as safe.
|
|
57
|
+
*/
|
|
58
|
+
export function html(strings: TemplateStringsArray, ...values: any[]): string;
|
|
59
|
+
|
|
60
|
+
/** Wrapper that marks an HTML string as trusted (not escaped by `$.html`). */
|
|
61
|
+
export interface TrustedHTML {
|
|
62
|
+
toString(): string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Mark an HTML string as trusted so it won't be escaped in `$.html`. */
|
|
66
|
+
export function trust(htmlStr: string): TrustedHTML;
|
|
67
|
+
|
|
68
|
+
/** Generate a UUID v4 string. */
|
|
69
|
+
export function uuid(): string;
|
|
70
|
+
|
|
71
|
+
/** Convert kebab-case to camelCase. */
|
|
72
|
+
export function camelCase(str: string): string;
|
|
73
|
+
|
|
74
|
+
/** Convert camelCase to kebab-case. */
|
|
75
|
+
export function kebabCase(str: string): string;
|
|
76
|
+
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Object Utilities
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
/** Deep clone using `structuredClone` (JSON fallback). */
|
|
82
|
+
export function deepClone<T>(obj: T): T;
|
|
83
|
+
|
|
84
|
+
/** Recursively merge objects. Arrays are replaced, not merged. */
|
|
85
|
+
export function deepMerge<T extends object>(target: T, ...sources: Partial<T>[]): T;
|
|
86
|
+
|
|
87
|
+
/** Deep equality comparison. */
|
|
88
|
+
export function isEqual(a: any, b: any): boolean;
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// URL Utilities
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
/** Serialize an object to a URL query string. */
|
|
95
|
+
export function param(obj: Record<string, any>): string;
|
|
96
|
+
|
|
97
|
+
/** Parse a URL query string into an object. */
|
|
98
|
+
export function parseQuery(str: string): Record<string, string>;
|
|
99
|
+
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// Storage Wrappers
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
/** JSON-aware storage wrapper (localStorage or sessionStorage). */
|
|
105
|
+
export interface StorageWrapper {
|
|
106
|
+
/**
|
|
107
|
+
* Get and JSON-parse a value.
|
|
108
|
+
* @param key Storage key.
|
|
109
|
+
* @param fallback Value returned if key is missing or parse fails (default `null`).
|
|
110
|
+
*/
|
|
111
|
+
get<T = any>(key: string, fallback?: T): T;
|
|
112
|
+
/** JSON-stringify and store. */
|
|
113
|
+
set(key: string, value: any): void;
|
|
114
|
+
/** Remove a key. */
|
|
115
|
+
remove(key: string): void;
|
|
116
|
+
/** Clear all entries. */
|
|
117
|
+
clear(): void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** `localStorage` wrapper with auto JSON serialization. */
|
|
121
|
+
export declare const storage: StorageWrapper;
|
|
122
|
+
|
|
123
|
+
/** `sessionStorage` wrapper (same API as `storage`). */
|
|
124
|
+
export declare const session: StorageWrapper;
|
|
125
|
+
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Event Bus
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
/** Singleton pub/sub event bus for cross-component communication. */
|
|
131
|
+
export interface EventBus {
|
|
132
|
+
/** Subscribe. Returns an unsubscribe function. */
|
|
133
|
+
on(event: string, fn: (...args: any[]) => void): () => void;
|
|
134
|
+
/** Unsubscribe a specific handler. */
|
|
135
|
+
off(event: string, fn: (...args: any[]) => void): void;
|
|
136
|
+
/** Emit an event with arguments. */
|
|
137
|
+
emit(event: string, ...args: any[]): void;
|
|
138
|
+
/** Subscribe for a single invocation. Returns an unsubscribe function. */
|
|
139
|
+
once(event: string, fn: (...args: any[]) => void): () => void;
|
|
140
|
+
/** Remove all listeners. */
|
|
141
|
+
clear(): void;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Global event bus instance. */
|
|
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>;
|