@sohanemon/utils 6.4.7 → 7.0.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/components/index.cjs +1 -1
- package/dist/components/index.d.cts +4 -4
- package/dist/components/index.js +1 -1
- package/dist/functions-CUn5JJn0.cjs +11 -0
- package/dist/functions-NBY7C4F1.js +11 -0
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks-D0giyGCY.cjs +1 -0
- package/dist/hooks-DftaZyen.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -1247
- package/dist/index.d.ts +174 -492
- package/dist/index.js +1 -1
- package/package.json +4 -1
- package/dist/functions-BXM8RFi-.js +0 -11
- package/dist/functions-HUrMwWSC.cjs +0 -11
- package/dist/hooks-CSmMIrB4.js +0 -1
- package/dist/hooks-oAfGz4K9.cjs +0 -1
- package/dist/index-CG2oc6F7.d.ts +0 -970
- package/dist/schedule-BqFAJlSO.d.cts +0 -43
package/dist/index.d.ts
CHANGED
|
@@ -1,613 +1,295 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClassValue } from "clsx";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export * from "@ts-utilities/core";
|
|
2
4
|
|
|
3
|
-
//#region src/
|
|
5
|
+
//#region src/functions/cookie.d.ts
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Sets a client-side cookie with optional expiration and path.
|
|
7
9
|
*
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
+
* @param name - The name of the cookie
|
|
11
|
+
* @param value - The value to store in the cookie
|
|
12
|
+
* @param days - Optional number of days until the cookie expires
|
|
13
|
+
* @param path - Optional path for the cookie (defaults to '/')
|
|
10
14
|
*
|
|
11
15
|
* @example
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* type UserKeys = Keys<User>; // 'name' | 'age'
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
type Keys<T extends object> = keyof T;
|
|
18
|
-
/**
|
|
19
|
-
* Extracts the values of an object type as a union type.
|
|
20
|
-
*
|
|
21
|
-
* @template T - The object type to extract values from
|
|
22
|
-
* @returns A union of all values in the object type
|
|
16
|
+
* // Set a cookie that expires in 7 days
|
|
17
|
+
* setClientSideCookie('userId', '12345', 7);
|
|
23
18
|
*
|
|
24
19
|
* @example
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* type UserValues = Values<User>; // string | number
|
|
28
|
-
* ```
|
|
20
|
+
* // Set a session cookie (no expiration)
|
|
21
|
+
* setClientSideCookie('sessionId', 'abc123');
|
|
29
22
|
*/
|
|
30
|
-
|
|
23
|
+
declare const setClientSideCookie: (name: string, value: string, days?: number, path?: string) => void;
|
|
31
24
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* This type traverses through nested objects and arrays, making all properties optional.
|
|
35
|
-
* Functions and primitives are left unchanged.
|
|
25
|
+
* Deletes a client-side cookie by setting its expiration to a past date.
|
|
36
26
|
*
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
27
|
+
* @param name - The name of the cookie to delete
|
|
28
|
+
* @param path - Optional path for the cookie (defaults to '/')
|
|
39
29
|
*
|
|
40
30
|
* @example
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* server: { host: string; port: number };
|
|
44
|
-
* features: string[];
|
|
45
|
-
* };
|
|
46
|
-
*
|
|
47
|
-
* type PartialConfig = DeepPartial<Config>;
|
|
48
|
-
* // {
|
|
49
|
-
* // server?: { host?: string; port?: number };
|
|
50
|
-
* // features?: string[];
|
|
51
|
-
* // }
|
|
52
|
-
* ```
|
|
31
|
+
* // Delete a cookie
|
|
32
|
+
* deleteClientSideCookie('userId');
|
|
53
33
|
*/
|
|
54
|
-
|
|
34
|
+
declare const deleteClientSideCookie: (name: string, path?: string) => void;
|
|
55
35
|
/**
|
|
56
|
-
*
|
|
36
|
+
* Checks if a client-side cookie exists.
|
|
57
37
|
*
|
|
58
|
-
* @
|
|
59
|
-
* @
|
|
60
|
-
* @returns An object type with specified properties optional
|
|
38
|
+
* @param name - The name of the cookie to check
|
|
39
|
+
* @returns True if the cookie exists, false otherwise
|
|
61
40
|
*
|
|
62
41
|
* @example
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* ```
|
|
42
|
+
* // Check if a cookie exists
|
|
43
|
+
* if (hasClientSideCookie('userId')) {
|
|
44
|
+
* console.log('User is logged in');
|
|
45
|
+
* }
|
|
68
46
|
*/
|
|
69
|
-
|
|
47
|
+
declare const hasClientSideCookie: (name: string) => boolean;
|
|
70
48
|
/**
|
|
71
|
-
*
|
|
49
|
+
* Retrieves the value of a client-side cookie.
|
|
72
50
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @template T - The type to make deeply required
|
|
77
|
-
* @returns A type with all properties required recursively
|
|
51
|
+
* @param name - The name of the cookie to retrieve
|
|
52
|
+
* @returns An object containing the cookie value, or undefined if not found
|
|
78
53
|
*
|
|
79
54
|
* @example
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* type RequiredConfig = DeepRequired<PartialConfig>;
|
|
86
|
-
* // {
|
|
87
|
-
* // server: { host: string; port: number };
|
|
88
|
-
* // }
|
|
89
|
-
* ```
|
|
55
|
+
* // Get a cookie value
|
|
56
|
+
* const { value } = getClientSideCookie('userId');
|
|
57
|
+
* if (value) {
|
|
58
|
+
* console.log('User ID:', value);
|
|
59
|
+
* }
|
|
90
60
|
*/
|
|
91
|
-
|
|
61
|
+
declare const getClientSideCookie: (name: string) => {
|
|
62
|
+
value: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/functions/utils.d.ts
|
|
92
66
|
/**
|
|
93
|
-
*
|
|
67
|
+
* Utility to merge class names with Tailwind CSS and additional custom merging logic.
|
|
94
68
|
*
|
|
95
|
-
* @
|
|
96
|
-
* @
|
|
97
|
-
* @returns An object type with specified properties required
|
|
69
|
+
* @param {...ClassValue[]} inputs - Class names to merge.
|
|
70
|
+
* @returns {string} - A string of merged class names.
|
|
98
71
|
*
|
|
99
72
|
* @example
|
|
100
73
|
* ```ts
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* // { name: string; age?: number; email?: string }
|
|
74
|
+
* cn('px-2 py-1', 'bg-red-500') // 'px-2 py-1 bg-red-500'
|
|
75
|
+
* cn('px-2', 'px-4') // 'px-4' (Tailwind resolves conflicts)
|
|
104
76
|
* ```
|
|
105
77
|
*/
|
|
106
|
-
|
|
78
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
107
79
|
/**
|
|
108
|
-
*
|
|
80
|
+
* @deprecated Use isLinkActive instead.
|
|
109
81
|
*
|
|
110
|
-
*
|
|
82
|
+
* Determines if a navigation link is active based on the current path.
|
|
111
83
|
*
|
|
112
|
-
* @
|
|
113
|
-
* @
|
|
84
|
+
* @param href - The target URL.
|
|
85
|
+
* @param path - The current browser path.
|
|
86
|
+
* @returns - True if the navigation is active, false otherwise.
|
|
114
87
|
*
|
|
115
88
|
* @example
|
|
116
89
|
* ```ts
|
|
117
|
-
*
|
|
118
|
-
*
|
|
90
|
+
* isNavActive('/about', '/about/team') // true
|
|
91
|
+
* isNavActive('/contact', '/about') // false
|
|
119
92
|
* ```
|
|
120
93
|
*/
|
|
121
|
-
|
|
94
|
+
declare function isNavActive(href: string, path: string): boolean;
|
|
122
95
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* @template T - The type to make nullable
|
|
126
|
-
* @returns A type where all properties can be null
|
|
96
|
+
* Checks if a link is active, considering optional localization prefixes.
|
|
127
97
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* type User = { name: string; profile: { age: number } };
|
|
131
|
-
* type NullableUser = Nullable<User>;
|
|
132
|
-
* // { name: string | null; profile: { age: number | null } | null }
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
type Nullable<T> = T extends object ? { [P in keyof T]: Nullable<T[P]> } : T | null;
|
|
136
|
-
/**
|
|
137
|
-
* Makes all properties of an object type optional (undefined) recursively.
|
|
98
|
+
* Compares paths while ignoring locale prefixes (e.g., /en/, /fr/) for consistent
|
|
99
|
+
* navigation highlighting across different language versions of the same page.
|
|
138
100
|
*
|
|
139
|
-
* @
|
|
140
|
-
* @
|
|
101
|
+
* @param params - Parameters object.
|
|
102
|
+
* @param params.path - The target path of the link.
|
|
103
|
+
* @param params.currentPath - The current browser path.
|
|
104
|
+
* @param params.locales - Supported locale prefixes to ignore during comparison.
|
|
105
|
+
* @param params.exact - Whether to require exact path match (default: true). If false, checks if current path starts with target path.
|
|
106
|
+
* @returns True if the link is active, false otherwise.
|
|
141
107
|
*
|
|
142
108
|
* @example
|
|
143
109
|
* ```ts
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
type Optional<T> = T extends object ? { [P in keyof T]: Optional<T[P]> } : T | undefined;
|
|
150
|
-
/**
|
|
151
|
-
* Makes all properties of an object type nullish (null or undefined) recursively.
|
|
110
|
+
* // Exact match
|
|
111
|
+
* isLinkActive({ path: '/about', currentPath: '/about' }) // true
|
|
112
|
+
* isLinkActive({ path: '/about', currentPath: '/about/team' }) // false
|
|
152
113
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
114
|
+
* // With locales
|
|
115
|
+
* isLinkActive({ path: '/about', currentPath: '/en/about' }) // true
|
|
116
|
+
* isLinkActive({ path: '/about', currentPath: '/fr/about' }) // true
|
|
155
117
|
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* type User = { name: string; profile: { age: number } };
|
|
159
|
-
* type NullishUser = Nullish<User>;
|
|
160
|
-
* // { name: string | null | undefined; profile: { age: number | null | undefined } | null | undefined }
|
|
118
|
+
* // Partial match
|
|
119
|
+
* isLinkActive({ path: '/blog', currentPath: '/blog/post-1', exact: false }) // true
|
|
161
120
|
* ```
|
|
162
121
|
*/
|
|
163
|
-
|
|
122
|
+
declare function isLinkActive({
|
|
123
|
+
path,
|
|
124
|
+
currentPath,
|
|
125
|
+
locales,
|
|
126
|
+
exact
|
|
127
|
+
}: {
|
|
128
|
+
path: string;
|
|
129
|
+
currentPath: string;
|
|
130
|
+
locales?: string[];
|
|
131
|
+
exact?: boolean;
|
|
132
|
+
}): boolean;
|
|
164
133
|
/**
|
|
165
|
-
*
|
|
134
|
+
* Cleans a file path by removing the `/public/` prefix if present.
|
|
166
135
|
*
|
|
167
|
-
*
|
|
136
|
+
* Useful when working with static assets that may have been processed
|
|
137
|
+
* or when normalizing paths between development and production environments.
|
|
168
138
|
*
|
|
169
|
-
* @
|
|
170
|
-
* @returns
|
|
139
|
+
* @param src - The source path to clean.
|
|
140
|
+
* @returns The cleaned path with `/public/` prefix removed and whitespace trimmed.
|
|
171
141
|
*
|
|
172
142
|
* @example
|
|
173
143
|
* ```ts
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* //
|
|
144
|
+
* cleanSrc('/public/images/logo.png') // '/images/logo.png'
|
|
145
|
+
* cleanSrc('images/logo.png') // 'images/logo.png'
|
|
146
|
+
* cleanSrc(' /public/docs/readme.md ') // '/docs/readme.md'
|
|
177
147
|
* ```
|
|
178
148
|
*/
|
|
179
|
-
|
|
149
|
+
declare function cleanSrc(src: string): string;
|
|
180
150
|
/**
|
|
181
|
-
*
|
|
151
|
+
* Smoothly scrolls to the top or bottom of a specified container.
|
|
182
152
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
153
|
+
* Provides smooth scrolling animation to either end of a scrollable element.
|
|
154
|
+
* Accepts either a CSS selector string or a React ref to the container element.
|
|
185
155
|
*
|
|
186
|
-
* @
|
|
187
|
-
* @
|
|
156
|
+
* @param containerSelector - The CSS selector string or React ref for the scrollable container.
|
|
157
|
+
* @param to - Direction to scroll: 'top' for top of container, 'bottom' for bottom.
|
|
188
158
|
*
|
|
189
159
|
* @example
|
|
190
160
|
* ```ts
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* features: string[];
|
|
194
|
-
* };
|
|
161
|
+
* // Scroll to top using selector
|
|
162
|
+
* scrollTo('.main-content', 'top');
|
|
195
163
|
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* // readonly server: { readonly host: string; readonly port: number };
|
|
199
|
-
* // readonly features: readonly string[];
|
|
200
|
-
* // }
|
|
164
|
+
* // Scroll to bottom using ref
|
|
165
|
+
* scrollTo(containerRef, 'bottom');
|
|
201
166
|
* ```
|
|
202
167
|
*/
|
|
203
|
-
|
|
168
|
+
declare const scrollTo: (containerSelector: string | React.RefObject<HTMLDivElement>, to: "top" | "bottom") => void;
|
|
204
169
|
/**
|
|
205
|
-
*
|
|
170
|
+
* Copies a given string to the clipboard using the modern Clipboard API.
|
|
206
171
|
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
172
|
+
* Safely attempts to copy text to the user's clipboard. Falls back gracefully
|
|
173
|
+
* if the Clipboard API is not available or if the operation fails.
|
|
209
174
|
*
|
|
210
|
-
* @
|
|
211
|
-
*
|
|
212
|
-
* type ReadonlyUser = { readonly name: string; readonly profile: { readonly age: number } };
|
|
213
|
-
* type MutableUser = Mutable<ReadonlyUser>;
|
|
214
|
-
* // { name: string; profile: { age: number } }
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
type Mutable<T> = { -readonly [P in keyof T]: T[P] };
|
|
218
|
-
/**
|
|
219
|
-
* Extracts keys of an object type that have values of a specific type.
|
|
220
|
-
*
|
|
221
|
-
* @template T - The object type to search
|
|
222
|
-
* @template U - The value type to match
|
|
223
|
-
* @returns A union of keys whose values match the specified type
|
|
175
|
+
* @param value - The text value to copy to the clipboard.
|
|
176
|
+
* @param onSuccess - Optional callback executed after successful copy operation.
|
|
224
177
|
*
|
|
225
178
|
* @example
|
|
226
179
|
* ```ts
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
180
|
+
* copyToClipboard('Hello World!', () => {
|
|
181
|
+
* console.log('Text copied successfully');
|
|
182
|
+
* });
|
|
230
183
|
* ```
|
|
231
184
|
*/
|
|
232
|
-
|
|
185
|
+
declare const copyToClipboard: (value: string, onSuccess?: () => void) => void;
|
|
233
186
|
/**
|
|
234
|
-
*
|
|
187
|
+
* Checks if the code is running in a server-side environment.
|
|
235
188
|
*
|
|
236
|
-
* @
|
|
237
|
-
* @template U - The value type to exclude
|
|
238
|
-
* @returns An object type without properties of the specified value type
|
|
189
|
+
* @returns - True if the code is executed in SSR (Server-Side Rendering) context, false otherwise
|
|
239
190
|
*
|
|
240
191
|
* @example
|
|
241
192
|
* ```ts
|
|
242
|
-
*
|
|
243
|
-
*
|
|
193
|
+
* if (isSSR) {
|
|
194
|
+
* // Server-side only code
|
|
195
|
+
* console.log('Running on server');
|
|
196
|
+
* } else {
|
|
197
|
+
* // Client-side only code
|
|
198
|
+
* window.addEventListener('load', () => {});
|
|
199
|
+
* }
|
|
244
200
|
* ```
|
|
245
201
|
*/
|
|
246
|
-
|
|
202
|
+
declare const isSSR: boolean;
|
|
247
203
|
/**
|
|
248
|
-
*
|
|
204
|
+
* Converts an SVG string to a Base64-encoded string.
|
|
249
205
|
*
|
|
250
|
-
* @
|
|
251
|
-
* @
|
|
252
|
-
* @returns An object type with specified properties required
|
|
206
|
+
* @param str - The SVG string to encode
|
|
207
|
+
* @returns - Base64-encoded string representation of the SVG
|
|
253
208
|
*
|
|
254
209
|
* @example
|
|
255
210
|
* ```ts
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* //
|
|
211
|
+
* const svg = '<svg><circle cx="50" cy="50" r="40"/></svg>';
|
|
212
|
+
* const base64 = svgToBase64(svg);
|
|
213
|
+
* // Use in data URL: `data:image/svg+xml;base64,${base64}`
|
|
259
214
|
* ```
|
|
260
215
|
*/
|
|
261
|
-
|
|
216
|
+
declare const svgToBase64: (str: string) => string;
|
|
262
217
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* Properties that exist in either T or U but not in both.
|
|
218
|
+
* Merges multiple refs into a single ref callback.
|
|
266
219
|
*
|
|
267
|
-
* @
|
|
268
|
-
* @
|
|
269
|
-
* @returns Properties unique to T or U
|
|
220
|
+
* @param refs - An array of refs to merge.
|
|
221
|
+
* @returns - A function that updates the merged ref with the provided value.
|
|
270
222
|
*
|
|
271
223
|
* @example
|
|
272
|
-
* ```
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* ```
|
|
277
|
-
*/
|
|
278
|
-
type Diff<T, U$1> = Omit<T, keyof U$1> & Omit<U$1, keyof T>;
|
|
279
|
-
/**
|
|
280
|
-
* Computes the intersection of two object types (properties present in both).
|
|
224
|
+
* ```tsx
|
|
225
|
+
* const MyComponent = () => {
|
|
226
|
+
* const ref1 = useRef<HTMLDivElement>(null);
|
|
227
|
+
* const ref2 = useRef<HTMLDivElement>(null);
|
|
281
228
|
*
|
|
282
|
-
*
|
|
283
|
-
* @template U - Second object type
|
|
284
|
-
* @returns Properties that exist in both T and U
|
|
229
|
+
* const mergedRef = mergeRefs(ref1, ref2);
|
|
285
230
|
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* type A = { x: number; y: string };
|
|
289
|
-
* type B = { y: string; z: boolean };
|
|
290
|
-
* type IntersectionAB = Intersection<A, B>; // { y: string }
|
|
231
|
+
* return <div ref={mergedRef}>Content</div>;
|
|
232
|
+
* };
|
|
291
233
|
* ```
|
|
292
234
|
*/
|
|
293
|
-
type
|
|
235
|
+
type MergeRefs = <T>(...refs: Array<React.Ref<T> | undefined>) => React.RefCallback<T>;
|
|
236
|
+
declare const mergeRefs: MergeRefs;
|
|
294
237
|
/**
|
|
295
|
-
*
|
|
238
|
+
* Navigates to the specified client-side hash without triggering SSR.
|
|
296
239
|
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* @returns A merged object type with properties from both
|
|
240
|
+
* Smoothly scrolls to an element by ID and updates the URL hash.
|
|
241
|
+
* Use `scroll-margin-top` CSS property to add margins for fixed headers.
|
|
300
242
|
*
|
|
301
|
-
* @
|
|
302
|
-
*
|
|
303
|
-
* type A = { x: number; y: string };
|
|
304
|
-
* type B = { y: boolean; z: string };
|
|
305
|
-
* type Merged = Merge<A, B>; // { x: number; y: boolean; z: string }
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
type Merge<T extends object, U$1 extends object, I = Diff<T, U$1> & Intersection<U$1, T> & Diff<U$1, T>> = Pick<I, keyof I>;
|
|
309
|
-
/**
|
|
310
|
-
* Subtracts properties of one object type from another.
|
|
311
|
-
*
|
|
312
|
-
* @template T - The object type to subtract from
|
|
313
|
-
* @template U - The object type whose properties to subtract
|
|
314
|
-
* @returns T without properties that exist in U
|
|
243
|
+
* @param id - The ID of the element (without #) to navigate to.
|
|
244
|
+
* @param opts - Additional options for scrollIntoView.
|
|
315
245
|
*
|
|
316
246
|
* @example
|
|
317
247
|
* ```ts
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* type Subtracted = Substract<A, B>; // { x: number; z: boolean }
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
type Substract<T extends object, U$1 extends object> = Omit<T, keyof U$1>;
|
|
324
|
-
/**
|
|
325
|
-
* Represents either all properties present or none of them.
|
|
248
|
+
* // Navigate to an element
|
|
249
|
+
* goToClientSideHash('section-about');
|
|
326
250
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* @template T - The object type
|
|
330
|
-
* @returns Either the full object or an empty object with optional properties
|
|
331
|
-
*
|
|
332
|
-
* @example
|
|
333
|
-
* ```ts
|
|
334
|
-
* type Config = { host: string; port: number };
|
|
335
|
-
* type AllOrNoneConfig = AllOrNone<Config>;
|
|
336
|
-
* // { host: string; port: number } | {}
|
|
251
|
+
* // With custom scroll behavior
|
|
252
|
+
* goToClientSideHash('contact', { behavior: 'auto', block: 'center' });
|
|
337
253
|
* ```
|
|
338
254
|
*/
|
|
339
|
-
|
|
255
|
+
declare function goToClientSideHash(id: string, opts?: ScrollIntoViewOptions): void;
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/functions/worker.d.ts
|
|
340
258
|
/**
|
|
341
|
-
*
|
|
259
|
+
* Converts a regular function into a workerized version that runs in a Web Worker.
|
|
342
260
|
*
|
|
343
|
-
*
|
|
261
|
+
* This provides the ultimate DX for Web Workers - just write a normal function
|
|
262
|
+
* and "workerize" it to run in the background without blocking the UI.
|
|
344
263
|
*
|
|
345
|
-
* @
|
|
346
|
-
* @returns A
|
|
264
|
+
* @param fn - The function to workerize
|
|
265
|
+
* @returns A function that calls the original function in a worker and returns a Promise
|
|
347
266
|
*
|
|
348
267
|
* @example
|
|
349
268
|
* ```ts
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
|
|
355
|
-
type OneOf<T> = { [K in keyof T]: Pick<T, K> }[keyof T];
|
|
356
|
-
/**
|
|
357
|
-
* Represents exactly two properties from an object type being present.
|
|
358
|
-
*
|
|
359
|
-
* @template T - The object type
|
|
360
|
-
* @returns A union where exactly two properties are present at a time
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* ```ts
|
|
364
|
-
* type Config = { a: number; b: string; c: boolean };
|
|
365
|
-
* type TwoConfig = TwoOf<Config>;
|
|
366
|
-
* // { a: number; b: string } | { a: number; c: boolean } | { b: string; c: boolean }
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
type TwoOf<T> = { [K in keyof T]: { [L in Exclude<keyof T, K>]: Pick<T, K | L> }[Exclude<keyof T, K>] }[keyof T];
|
|
370
|
-
/**
|
|
371
|
-
* Prettifies a complex type by expanding it for better readability in tooltips.
|
|
372
|
-
*
|
|
373
|
-
* This type doesn't change the runtime type but helps with IntelliSense display.
|
|
269
|
+
* // Define a normal function
|
|
270
|
+
* function fibonacci(n: number): number {
|
|
271
|
+
* if (n <= 1) return n;
|
|
272
|
+
* return fibonacci(n - 1) + fibonacci(n - 2);
|
|
273
|
+
* }
|
|
374
274
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
275
|
+
* // Workerize it
|
|
276
|
+
* const workerizedFib = workerize(fibonacci);
|
|
377
277
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
* type PrettyComplex = Prettify<Complex>; // Shows as { a: string; b: number }
|
|
278
|
+
* // Use like a normal async function!
|
|
279
|
+
* const result = await workerizedFib(35);
|
|
280
|
+
* console.log(result); // Works just like the original function
|
|
382
281
|
* ```
|
|
383
|
-
*/
|
|
384
|
-
type Prettify<T> = T extends infer U ? U extends object ? { [K in keyof U]: U[K] } & {} : U : never;
|
|
385
|
-
/**
|
|
386
|
-
* Extracts all nested keys of an object type as dot-separated strings.
|
|
387
|
-
*
|
|
388
|
-
* @template ObjectType - The object type to extract nested keys from
|
|
389
|
-
* @template IgnoreKeys - Keys to ignore during extraction
|
|
390
|
-
* @returns A union of dot-separated string paths
|
|
391
282
|
*
|
|
392
283
|
* @example
|
|
393
284
|
* ```ts
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
* };
|
|
399
|
-
*
|
|
400
|
-
* type UserPaths = NestedKeyOf<User>;
|
|
401
|
-
* // 'name' | 'profile' | 'profile.age' | 'profile.address' | 'profile.address.city' | 'tags'
|
|
402
|
-
* ```
|
|
403
|
-
*/
|
|
404
|
-
type NestedKeyOf<ObjectType extends object, IgnoreKeys extends string = never> = { [Key in keyof ObjectType & string]: Key extends IgnoreKeys ? never : ObjectType[Key] extends object ? ObjectType[Key] extends Array<any> ? Key : `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key], IgnoreKeys>}` : `${Key}` }[keyof ObjectType & string];
|
|
405
|
-
/**
|
|
406
|
-
* Creates a type that excludes properties present in another type.
|
|
407
|
-
*
|
|
408
|
-
* This is useful for creating mutually exclusive types.
|
|
409
|
-
*
|
|
410
|
-
* @template T - The base type
|
|
411
|
-
* @template U - The type whose properties to exclude
|
|
412
|
-
* @returns A type with properties from T that are not in U
|
|
285
|
+
* // Works with any function signature
|
|
286
|
+
* const sumArray = workerize((arr: number[]) =>
|
|
287
|
+
* arr.reduce((a, b) => a + b, 0)
|
|
288
|
+
* );
|
|
413
289
|
*
|
|
414
|
-
*
|
|
415
|
-
* ```ts
|
|
416
|
-
* type A = { x: number; y: string };
|
|
417
|
-
* type B = { y: string };
|
|
418
|
-
* type WithoutB = Without<A, B>; // { x?: never }
|
|
290
|
+
* const result = await sumArray([1, 2, 3, 4, 5]); // 15
|
|
419
291
|
* ```
|
|
420
292
|
*/
|
|
421
|
-
|
|
422
|
-
//#endregion
|
|
423
|
-
//#region src/types/gates.d.ts
|
|
424
|
-
type BUFFER<T> = T;
|
|
425
|
-
type IMPLIES<T, U$1> = T extends U$1 ? true : false;
|
|
426
|
-
type XOR_Binary<T, U$1> = T | U$1 extends object ? (Without<T, U$1> & U$1) | (Without<U$1, T> & T) : T | U$1;
|
|
427
|
-
type XNOR_Binary<T, U$1> = (T & U$1) | (Without<T, U$1> & Without<U$1, T>);
|
|
428
|
-
/**
|
|
429
|
-
* Computes a type-level AND (all must true) for a tuple of types.
|
|
430
|
-
*
|
|
431
|
-
* Truth table for 3 arguments:
|
|
432
|
-
*
|
|
433
|
-
* A B C = AND
|
|
434
|
-
* 1 1 1 = 1
|
|
435
|
-
* 1 1 0 = 0
|
|
436
|
-
* 1 0 1 = 0
|
|
437
|
-
* 1 0 0 = 0
|
|
438
|
-
* 0 1 1 = 0
|
|
439
|
-
* 0 1 0 = 0
|
|
440
|
-
* 0 0 1 = 0
|
|
441
|
-
* 0 0 0 = 0
|
|
442
|
-
*
|
|
443
|
-
* @template T - Tuple of boolean-like types (1/0)
|
|
444
|
-
*/
|
|
445
|
-
type AND<T extends any[]> = T extends [infer F, ...infer R] ? R extends any[] ? F & AND<R> : F : unknown;
|
|
446
|
-
/**
|
|
447
|
-
* Computes a type-level OR (At least one) for a tuple of types.
|
|
448
|
-
*
|
|
449
|
-
* Truth table for 3 arguments:
|
|
450
|
-
*
|
|
451
|
-
* A B C = OR
|
|
452
|
-
* 1 1 1 = 1
|
|
453
|
-
* 1 1 0 = 1
|
|
454
|
-
* 1 0 1 = 1
|
|
455
|
-
* 1 0 0 = 1
|
|
456
|
-
* 0 1 1 = 1
|
|
457
|
-
* 0 1 0 = 1
|
|
458
|
-
* 0 0 1 = 1
|
|
459
|
-
* 0 0 0 = 0
|
|
460
|
-
*
|
|
461
|
-
* @template T - Tuple of boolean-like types (1/0)
|
|
462
|
-
*/
|
|
463
|
-
type OR<T extends any[]> = T extends [infer F, ...infer R] ? R extends any[] ? F | OR<R> : F : never;
|
|
464
|
-
/**
|
|
465
|
-
* Computes a type-level XOR (only one/odd) for a tuple of types.
|
|
466
|
-
*
|
|
467
|
-
* Truth table for 3 arguments:
|
|
468
|
-
*
|
|
469
|
-
* A B C = XOR
|
|
470
|
-
* 1 1 1 = 1
|
|
471
|
-
* 1 1 0 = 0
|
|
472
|
-
* 1 0 1 = 0
|
|
473
|
-
* 1 0 0 = 1
|
|
474
|
-
* 0 1 1 = 0
|
|
475
|
-
* 0 1 0 = 1
|
|
476
|
-
* 0 0 1 = 1
|
|
477
|
-
* 0 0 0 = 0
|
|
478
|
-
*
|
|
479
|
-
* @template T - Tuple of boolean-like types (1/0)
|
|
480
|
-
*/
|
|
481
|
-
type XOR<T extends any[]> = T extends [infer F, ...infer R] ? R extends [infer S, ...infer Rest] ? XOR<[XOR_Binary<F, S>, ...Rest]> : F : never;
|
|
482
|
-
/**
|
|
483
|
-
* Computes a type-level XNOR (All or None true) for a tuple of types.
|
|
484
|
-
*
|
|
485
|
-
* Truth table for 3 arguments:
|
|
486
|
-
*
|
|
487
|
-
* A B C = XNOR
|
|
488
|
-
* 1 1 1 = 0
|
|
489
|
-
* 1 1 0 = 1
|
|
490
|
-
* 1 0 1 = 1
|
|
491
|
-
* 1 0 0 = 0
|
|
492
|
-
* 0 1 1 = 1
|
|
493
|
-
* 0 1 0 = 0
|
|
494
|
-
* 0 0 1 = 0
|
|
495
|
-
* 0 0 0 = 1
|
|
496
|
-
*
|
|
497
|
-
* @template T - Tuple of boolean-like types (1/0)
|
|
498
|
-
*/
|
|
499
|
-
type XNOR<T extends any[]> = T extends [infer F, ...infer R] ? R extends [infer S, ...infer Rest] ? XNOR<[XNOR_Binary<F, S>, ...Rest]> : F : never;
|
|
500
|
-
/**
|
|
501
|
-
* Computes a type-level NOT for a tuple of types.
|
|
502
|
-
*
|
|
503
|
-
* Truth table for 3 arguments:
|
|
504
|
-
*
|
|
505
|
-
* A B C = NOT
|
|
506
|
-
* 1 1 1 = 0
|
|
507
|
-
* 1 1 0 = 0
|
|
508
|
-
* 1 0 1 = 0
|
|
509
|
-
* 1 0 0 = 0
|
|
510
|
-
* 0 1 1 = 0
|
|
511
|
-
* 0 1 0 = 0
|
|
512
|
-
* 0 0 1 = 0
|
|
513
|
-
* 0 0 0 = 1
|
|
514
|
-
*
|
|
515
|
-
* @template T - Tuple of boolean-like types (1/0)
|
|
516
|
-
*/
|
|
517
|
-
type NOT<T> = { [P in keyof T]?: never };
|
|
518
|
-
/**
|
|
519
|
-
* Computes a type-level NAND for a tuple of types.
|
|
520
|
-
*
|
|
521
|
-
* Truth table for 3 arguments:
|
|
522
|
-
*
|
|
523
|
-
* A B C = NAND
|
|
524
|
-
* 1 1 1 = 0
|
|
525
|
-
* 1 1 0 = 1
|
|
526
|
-
* 1 0 1 = 1
|
|
527
|
-
* 1 0 0 = 1
|
|
528
|
-
* 0 1 1 = 1
|
|
529
|
-
* 0 1 0 = 1
|
|
530
|
-
* 0 0 1 = 1
|
|
531
|
-
* 0 0 0 = 1
|
|
532
|
-
*
|
|
533
|
-
* @template T - Tuple of boolean-like types (1/0)
|
|
534
|
-
*/
|
|
535
|
-
type NAND<T extends any[]> = NOT<AND<T>>;
|
|
536
|
-
/**
|
|
537
|
-
* Computes a type-level NOR for a tuple of types.
|
|
538
|
-
*
|
|
539
|
-
* Truth table for 3 arguments:
|
|
540
|
-
*
|
|
541
|
-
* A B C = NOR
|
|
542
|
-
* 1 1 1 = 0
|
|
543
|
-
* 1 1 0 = 0
|
|
544
|
-
* 1 0 1 = 0
|
|
545
|
-
* 1 0 0 = 0
|
|
546
|
-
* 0 1 1 = 0
|
|
547
|
-
* 0 1 0 = 0
|
|
548
|
-
* 0 0 1 = 0
|
|
549
|
-
* 0 0 0 = 1
|
|
550
|
-
*
|
|
551
|
-
* @template T - Tuple of boolean-like types (1/0)
|
|
552
|
-
*/
|
|
553
|
-
type NOR<T extends any[]> = NOT<OR<T>>;
|
|
554
|
-
//#endregion
|
|
555
|
-
//#region src/types/guards.d.ts
|
|
556
|
-
/**
|
|
557
|
-
* Represents primitive JavaScript types including null and undefined.
|
|
558
|
-
*/
|
|
559
|
-
type Primitive = string | number | bigint | boolean | symbol | null | undefined;
|
|
560
|
-
/**
|
|
561
|
-
* Represents all falsy values in JavaScript.
|
|
562
|
-
*/
|
|
563
|
-
type Falsy = false | '' | 0 | null | undefined;
|
|
564
|
-
/**
|
|
565
|
-
* Type guard that checks if a value is falsy.
|
|
566
|
-
*
|
|
567
|
-
* @param val - The value to check
|
|
568
|
-
* @returns True if the value is falsy, false otherwise
|
|
569
|
-
*
|
|
570
|
-
* @example
|
|
571
|
-
* if (isFalsy(value)) {
|
|
572
|
-
* console.log('Value is falsy');
|
|
573
|
-
* }
|
|
574
|
-
*/
|
|
575
|
-
declare const isFalsy: (val: unknown) => val is Falsy;
|
|
576
|
-
/**
|
|
577
|
-
* Type guard that checks if a value is null or undefined.
|
|
578
|
-
*
|
|
579
|
-
* @param val - The value to check
|
|
580
|
-
* @returns True if the value is null or undefined, false otherwise
|
|
581
|
-
*
|
|
582
|
-
* @example
|
|
583
|
-
* if (isNullish(value)) {
|
|
584
|
-
* console.log('Value is null or undefined');
|
|
585
|
-
* }
|
|
586
|
-
*/
|
|
587
|
-
declare const isNullish: (val: unknown) => val is null | undefined;
|
|
588
|
-
/**
|
|
589
|
-
* Type guard that checks if a value is a primitive type.
|
|
590
|
-
*
|
|
591
|
-
* @param val - The value to check
|
|
592
|
-
* @returns True if the value is a primitive, false otherwise
|
|
593
|
-
*
|
|
594
|
-
* @example
|
|
595
|
-
* if (isPrimitive(value)) {
|
|
596
|
-
* console.log('Value is a primitive type');
|
|
597
|
-
* }
|
|
598
|
-
*/
|
|
599
|
-
declare const isPrimitive: (val: unknown) => val is Primitive;
|
|
600
|
-
/**
|
|
601
|
-
* Type guard that checks if a value is a plain object (not an array, function, etc.).
|
|
602
|
-
*
|
|
603
|
-
* @param value - The value to check
|
|
604
|
-
* @returns True if the value is a plain object, false otherwise
|
|
605
|
-
*
|
|
606
|
-
* @example
|
|
607
|
-
* if (isPlainObject(value)) {
|
|
608
|
-
* console.log('Value is a plain object');
|
|
609
|
-
* }
|
|
610
|
-
*/
|
|
611
|
-
declare function isPlainObject(value: unknown): value is Record<string, any>;
|
|
293
|
+
declare function workerize<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => Promise<ReturnType<T>>;
|
|
612
294
|
//#endregion
|
|
613
|
-
export {
|
|
295
|
+
export { MergeRefs, cleanSrc, cn, copyToClipboard, deleteClientSideCookie, getClientSideCookie, goToClientSideHash, hasClientSideCookie, isLinkActive, isNavActive, isSSR, mergeRefs, scrollTo, setClientSideCookie, svgToBase64, workerize };
|