@bgskinner2/ts-utils 1.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/LICENSE +2 -0
- package/README.md +272 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2546 -0
- package/dist/index.d.ts +2546 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2546 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ElementType, ComponentPropsWithoutRef, ReactElement, MouseEvent, ReactNode, ComponentType, ForwardRefExoticComponent, ReactPortal, Ref, RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
/** @see {@link TypeDocs.TStaticMethods} */
|
|
5
|
+
type TStaticMethods<T> = {
|
|
6
|
+
[K in keyof T as T[K] extends (...args: any) => any ? K : never]: T[K];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type TArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | number;
|
|
10
|
+
type TArrayItems<T extends Array<unknown>> = T extends Array<infer TItems> ? TItems : never;
|
|
11
|
+
type TFixedLengthArray<T extends unknown[]> = Pick<T, Exclude<keyof T, TArrayLengthMutationKeys>> & {
|
|
12
|
+
[Symbol.iterator]: () => IterableIterator<TArrayItems<T>>;
|
|
13
|
+
} & {
|
|
14
|
+
length: number;
|
|
15
|
+
};
|
|
16
|
+
type TRGB = readonly [r: number, g: number, b: number];
|
|
17
|
+
type TCssRGB = `rgb(${number}, ${number}, ${number})`;
|
|
18
|
+
|
|
19
|
+
type TWords<S extends string, Acc extends string[] = []> = S extends `${infer First}${infer Rest}` ? First extends '-' | '_' | ' ' ? TWords<Rest, Acc> : Rest extends `${infer NextChar}${infer Remaining}` ? NextChar extends '-' | '_' | ' ' ? TWords<Remaining, [...Acc, First]> : TWords<`${NextChar}${Remaining}`, Acc extends [] ? [First] : [...Acc, First]> : [...Acc, First] : Acc;
|
|
20
|
+
type TDelimiterCaseOptions = {
|
|
21
|
+
/**
|
|
22
|
+
* Whether to preserve consecutive uppercase letters.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
preserveConsecutiveUppercase?: boolean;
|
|
26
|
+
};
|
|
27
|
+
type TDefaultDelimiterCaseOptions = {
|
|
28
|
+
preserveConsecutiveUppercase: true;
|
|
29
|
+
};
|
|
30
|
+
type TMergeDelimiterCaseOptions<Options extends TDelimiterCaseOptions> = {
|
|
31
|
+
preserveConsecutiveUppercase: Options['preserveConsecutiveUppercase'] extends boolean ? Options['preserveConsecutiveUppercase'] : TDefaultDelimiterCaseOptions['preserveConsecutiveUppercase'];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Join an array of words with underscores (_), respecting preserveConsecutiveUppercase
|
|
36
|
+
*/
|
|
37
|
+
type SnakeCaseFromArray<WordsArr extends string[], Options extends {
|
|
38
|
+
preserveConsecutiveUppercase: boolean;
|
|
39
|
+
}, OutputString extends string = ''> = WordsArr extends [
|
|
40
|
+
infer FirstWord extends string,
|
|
41
|
+
...infer Rest extends string[]
|
|
42
|
+
] ? Rest['length'] extends 0 ? Options['preserveConsecutiveUppercase'] extends true ? FirstWord : Lowercase<FirstWord> : Options['preserveConsecutiveUppercase'] extends true ? `${FirstWord}_${SnakeCaseFromArray<Rest, Options>}` : `${Lowercase<FirstWord>}_${SnakeCaseFromArray<Rest, Options>}` : OutputString;
|
|
43
|
+
/**
|
|
44
|
+
* Convert a string literal to snake_case
|
|
45
|
+
*/
|
|
46
|
+
type TSnakeCase<Type, Options extends TDelimiterCaseOptions = object> = Type extends string ? string extends Type ? Type : SnakeCaseFromArray<TWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, TMergeDelimiterCaseOptions<Options>> : Type;
|
|
47
|
+
|
|
48
|
+
type KebabCaseFromArray<WordsArr extends string[], Options extends {
|
|
49
|
+
preserveConsecutiveUppercase: boolean;
|
|
50
|
+
}, OutputString extends string = ''> = WordsArr extends [
|
|
51
|
+
infer FirstWord extends string,
|
|
52
|
+
...infer Rest extends string[]
|
|
53
|
+
] ? Rest['length'] extends 0 ? Options['preserveConsecutiveUppercase'] extends true ? FirstWord : Lowercase<FirstWord> : Options['preserveConsecutiveUppercase'] extends true ? `${FirstWord}-${KebabCaseFromArray<Rest, Options>}` : `${Lowercase<FirstWord>}-${KebabCaseFromArray<Rest, Options>}` : OutputString;
|
|
54
|
+
type TKebabCase<Type, Options extends TDelimiterCaseOptions = object> = Type extends string ? string extends Type ? Type : KebabCaseFromArray<TWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, TMergeDelimiterCaseOptions<Options>> : Type;
|
|
55
|
+
|
|
56
|
+
type CamelCaseFromArray<WordsArr extends string[], Options extends {
|
|
57
|
+
preserveConsecutiveUppercase: boolean;
|
|
58
|
+
}, OutputString extends string = ''> = WordsArr extends [
|
|
59
|
+
infer FirstWord extends string,
|
|
60
|
+
...infer Rest extends string[]
|
|
61
|
+
] ? Options['preserveConsecutiveUppercase'] extends true ? `${Capitalize<FirstWord>}${CamelCaseFromArray<Rest, Options>}` : `${Capitalize<Lowercase<FirstWord>>}${CamelCaseFromArray<Rest, Options>}` : OutputString;
|
|
62
|
+
type TCamelCase<Type, Options extends TDelimiterCaseOptions = object> = Type extends string ? string extends Type ? Type : Uncapitalize<CamelCaseFromArray<TWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, TMergeDelimiterCaseOptions<Options>>> : Type;
|
|
63
|
+
|
|
64
|
+
declare const LOG_TYPES: readonly ["log", "warn", "error", "info", "debug", "table"];
|
|
65
|
+
declare const REGEX_CONSTANTS: {
|
|
66
|
+
readonly isoRegex: RegExp;
|
|
67
|
+
readonly camelCase: RegExp;
|
|
68
|
+
readonly kebabCase: RegExp;
|
|
69
|
+
readonly snakeCase: RegExp;
|
|
70
|
+
readonly hexString: RegExp;
|
|
71
|
+
readonly hexColor: RegExp;
|
|
72
|
+
readonly letterSeparator: RegExp;
|
|
73
|
+
readonly camelCaseBoundary: RegExp;
|
|
74
|
+
readonly kebabCaseBoundary: RegExp;
|
|
75
|
+
readonly whitespace: RegExp;
|
|
76
|
+
readonly wordBoundarySplitter: RegExp;
|
|
77
|
+
readonly USPhoneNumber: RegExp;
|
|
78
|
+
readonly EUPhoneNumber: RegExp;
|
|
79
|
+
readonly genericPhoneNumber: RegExp;
|
|
80
|
+
readonly genericEmail: RegExp;
|
|
81
|
+
readonly emailRegex: RegExp;
|
|
82
|
+
readonly imageSrcRegex: RegExp;
|
|
83
|
+
readonly singleAlphabetChar: RegExp;
|
|
84
|
+
readonly htmlDetection: RegExp;
|
|
85
|
+
readonly stackTracePrefix: RegExp;
|
|
86
|
+
};
|
|
87
|
+
declare const ANSI_COLOR_CODES: {
|
|
88
|
+
readonly reset: "\u001B[0m";
|
|
89
|
+
readonly black: "\u001B[30m";
|
|
90
|
+
readonly red: "\u001B[31m";
|
|
91
|
+
readonly green: "\u001B[32m";
|
|
92
|
+
readonly yellow: "\u001B[33m";
|
|
93
|
+
readonly blue: "\u001B[34m";
|
|
94
|
+
readonly magenta: "\u001B[35m";
|
|
95
|
+
readonly cyan: "\u001B[36m";
|
|
96
|
+
readonly white: "\u001B[37m";
|
|
97
|
+
readonly bold: "\u001B[1m";
|
|
98
|
+
readonly underline: "\u001B[4m";
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
declare const VALID_DOM_PROPS: {
|
|
102
|
+
abbr: true;
|
|
103
|
+
accept: true;
|
|
104
|
+
acceptCharset: true;
|
|
105
|
+
accessKey: true;
|
|
106
|
+
action: true;
|
|
107
|
+
allow: true;
|
|
108
|
+
allowFullScreen: true;
|
|
109
|
+
allowPaymentRequest: true;
|
|
110
|
+
alt: true;
|
|
111
|
+
async: true;
|
|
112
|
+
autoComplete: true;
|
|
113
|
+
autoFocus: true;
|
|
114
|
+
autoPlay: true;
|
|
115
|
+
capture: true;
|
|
116
|
+
cellPadding: true;
|
|
117
|
+
cellSpacing: true;
|
|
118
|
+
challenge: true;
|
|
119
|
+
charSet: true;
|
|
120
|
+
checked: true;
|
|
121
|
+
cite: true;
|
|
122
|
+
classID: true;
|
|
123
|
+
className: true;
|
|
124
|
+
cols: true;
|
|
125
|
+
colSpan: true;
|
|
126
|
+
content: true;
|
|
127
|
+
contentEditable: true;
|
|
128
|
+
contextMenu: true;
|
|
129
|
+
controls: true;
|
|
130
|
+
controlsList: true;
|
|
131
|
+
coords: true;
|
|
132
|
+
crossOrigin: true;
|
|
133
|
+
data: true;
|
|
134
|
+
dateTime: true;
|
|
135
|
+
decoding: true;
|
|
136
|
+
default: true;
|
|
137
|
+
defer: true;
|
|
138
|
+
dir: true;
|
|
139
|
+
disabled: true;
|
|
140
|
+
disablePictureInPicture: true;
|
|
141
|
+
disableRemotePlayback: true;
|
|
142
|
+
download: true;
|
|
143
|
+
draggable: true;
|
|
144
|
+
encType: true;
|
|
145
|
+
enterKeyHint: true;
|
|
146
|
+
form: true;
|
|
147
|
+
formAction: true;
|
|
148
|
+
formEncType: true;
|
|
149
|
+
formMethod: true;
|
|
150
|
+
formNoValidate: true;
|
|
151
|
+
formTarget: true;
|
|
152
|
+
frameBorder: true;
|
|
153
|
+
headers: true;
|
|
154
|
+
height: true;
|
|
155
|
+
hidden: true;
|
|
156
|
+
high: true;
|
|
157
|
+
href: true;
|
|
158
|
+
hrefLang: true;
|
|
159
|
+
htmlFor: true;
|
|
160
|
+
httpEquiv: true;
|
|
161
|
+
id: true;
|
|
162
|
+
inputMode: true;
|
|
163
|
+
integrity: true;
|
|
164
|
+
is: true;
|
|
165
|
+
keyParams: true;
|
|
166
|
+
keyType: true;
|
|
167
|
+
kind: true;
|
|
168
|
+
label: true;
|
|
169
|
+
lang: true;
|
|
170
|
+
list: true;
|
|
171
|
+
loading: true;
|
|
172
|
+
loop: true;
|
|
173
|
+
low: true;
|
|
174
|
+
marginHeight: true;
|
|
175
|
+
marginWidth: true;
|
|
176
|
+
max: true;
|
|
177
|
+
maxLength: true;
|
|
178
|
+
media: true;
|
|
179
|
+
mediaGroup: true;
|
|
180
|
+
method: true;
|
|
181
|
+
min: true;
|
|
182
|
+
minLength: true;
|
|
183
|
+
multiple: true;
|
|
184
|
+
muted: true;
|
|
185
|
+
name: true;
|
|
186
|
+
nonce: true;
|
|
187
|
+
noValidate: true;
|
|
188
|
+
open: true;
|
|
189
|
+
optimum: true;
|
|
190
|
+
pattern: true;
|
|
191
|
+
placeholder: true;
|
|
192
|
+
playsInline: true;
|
|
193
|
+
poster: true;
|
|
194
|
+
preload: true;
|
|
195
|
+
profile: true;
|
|
196
|
+
radioGroup: true;
|
|
197
|
+
readOnly: true;
|
|
198
|
+
referrerPolicy: true;
|
|
199
|
+
rel: true;
|
|
200
|
+
required: true;
|
|
201
|
+
reversed: true;
|
|
202
|
+
role: true;
|
|
203
|
+
rows: true;
|
|
204
|
+
rowSpan: true;
|
|
205
|
+
sandbox: true;
|
|
206
|
+
scope: true;
|
|
207
|
+
scoped: true;
|
|
208
|
+
scrolling: true;
|
|
209
|
+
seamless: true;
|
|
210
|
+
selected: true;
|
|
211
|
+
shape: true;
|
|
212
|
+
size: true;
|
|
213
|
+
sizes: true;
|
|
214
|
+
slot: true;
|
|
215
|
+
span: true;
|
|
216
|
+
spellCheck: true;
|
|
217
|
+
src: true;
|
|
218
|
+
srcDoc: true;
|
|
219
|
+
srcLang: true;
|
|
220
|
+
srcSet: true;
|
|
221
|
+
start: true;
|
|
222
|
+
step: true;
|
|
223
|
+
style: true;
|
|
224
|
+
summary: true;
|
|
225
|
+
tabIndex: true;
|
|
226
|
+
target: true;
|
|
227
|
+
title: true;
|
|
228
|
+
translate: true;
|
|
229
|
+
type: true;
|
|
230
|
+
useMap: true;
|
|
231
|
+
value: true;
|
|
232
|
+
width: true;
|
|
233
|
+
wmode: true;
|
|
234
|
+
wrap: true;
|
|
235
|
+
alignmentBaseline: true;
|
|
236
|
+
baselineShift: true;
|
|
237
|
+
clip: true;
|
|
238
|
+
clipPath: true;
|
|
239
|
+
clipRule: true;
|
|
240
|
+
color: true;
|
|
241
|
+
colorInterpolation: true;
|
|
242
|
+
colorInterpolationFilters: true;
|
|
243
|
+
colorProfile: true;
|
|
244
|
+
colorRendering: true;
|
|
245
|
+
cursor: true;
|
|
246
|
+
direction: true;
|
|
247
|
+
display: true;
|
|
248
|
+
dominantBaseline: true;
|
|
249
|
+
enableBackground: true;
|
|
250
|
+
fill: true;
|
|
251
|
+
fillOpacity: true;
|
|
252
|
+
fillRule: true;
|
|
253
|
+
filter: true;
|
|
254
|
+
floodColor: true;
|
|
255
|
+
floodOpacity: true;
|
|
256
|
+
imageRendering: true;
|
|
257
|
+
lightingColor: true;
|
|
258
|
+
markerEnd: true;
|
|
259
|
+
markerMid: true;
|
|
260
|
+
markerStart: true;
|
|
261
|
+
mask: true;
|
|
262
|
+
opacity: true;
|
|
263
|
+
overflow: true;
|
|
264
|
+
paintOrder: true;
|
|
265
|
+
pointerEvents: true;
|
|
266
|
+
shapeRendering: true;
|
|
267
|
+
stopColor: true;
|
|
268
|
+
stopOpacity: true;
|
|
269
|
+
stroke: true;
|
|
270
|
+
strokeDasharray: true;
|
|
271
|
+
strokeDashoffset: true;
|
|
272
|
+
strokeLinecap: true;
|
|
273
|
+
strokeLinejoin: true;
|
|
274
|
+
strokeMiterlimit: true;
|
|
275
|
+
strokeOpacity: true;
|
|
276
|
+
strokeWidth: true;
|
|
277
|
+
textAnchor: true;
|
|
278
|
+
textDecoration: true;
|
|
279
|
+
textRendering: true;
|
|
280
|
+
unicodeBidi: true;
|
|
281
|
+
vectorEffect: true;
|
|
282
|
+
visibility: true;
|
|
283
|
+
wordSpacing: true;
|
|
284
|
+
writingMode: true;
|
|
285
|
+
cx: true;
|
|
286
|
+
cy: true;
|
|
287
|
+
d: true;
|
|
288
|
+
dx: true;
|
|
289
|
+
dy: true;
|
|
290
|
+
fr: true;
|
|
291
|
+
fx: true;
|
|
292
|
+
fy: true;
|
|
293
|
+
points: true;
|
|
294
|
+
r: true;
|
|
295
|
+
rx: true;
|
|
296
|
+
ry: true;
|
|
297
|
+
transform: true;
|
|
298
|
+
version: true;
|
|
299
|
+
viewBox: true;
|
|
300
|
+
x: true;
|
|
301
|
+
x1: true;
|
|
302
|
+
x2: true;
|
|
303
|
+
y: true;
|
|
304
|
+
y1: true;
|
|
305
|
+
y2: true;
|
|
306
|
+
z: true;
|
|
307
|
+
accumulate: true;
|
|
308
|
+
additive: true;
|
|
309
|
+
allowReorder: true;
|
|
310
|
+
amplitude: true;
|
|
311
|
+
attributeName: true;
|
|
312
|
+
attributeType: true;
|
|
313
|
+
autoReverse: true;
|
|
314
|
+
begin: true;
|
|
315
|
+
bias: true;
|
|
316
|
+
by: true;
|
|
317
|
+
calcMode: true;
|
|
318
|
+
decelerate: true;
|
|
319
|
+
diffuseConstant: true;
|
|
320
|
+
divisor: true;
|
|
321
|
+
dur: true;
|
|
322
|
+
edgeMode: true;
|
|
323
|
+
elevation: true;
|
|
324
|
+
end: true;
|
|
325
|
+
exponent: true;
|
|
326
|
+
externalResourcesRequired: true;
|
|
327
|
+
filterRes: true;
|
|
328
|
+
filterUnits: true;
|
|
329
|
+
from: true;
|
|
330
|
+
in: true;
|
|
331
|
+
in2: true;
|
|
332
|
+
intercept: true;
|
|
333
|
+
k: true;
|
|
334
|
+
k1: true;
|
|
335
|
+
k2: true;
|
|
336
|
+
k3: true;
|
|
337
|
+
k4: true;
|
|
338
|
+
kernelMatrix: true;
|
|
339
|
+
kernelUnitLength: true;
|
|
340
|
+
keyPoints: true;
|
|
341
|
+
keySplines: true;
|
|
342
|
+
keyTimes: true;
|
|
343
|
+
limitingConeAngle: true;
|
|
344
|
+
mode: true;
|
|
345
|
+
numOctaves: true;
|
|
346
|
+
operator: true;
|
|
347
|
+
order: true;
|
|
348
|
+
orient: true;
|
|
349
|
+
orientation: true;
|
|
350
|
+
origin: true;
|
|
351
|
+
pathLength: true;
|
|
352
|
+
primitiveUnits: true;
|
|
353
|
+
repeatCount: true;
|
|
354
|
+
repeatDur: true;
|
|
355
|
+
restart: true;
|
|
356
|
+
result: true;
|
|
357
|
+
rotate: true;
|
|
358
|
+
scale: true;
|
|
359
|
+
seed: true;
|
|
360
|
+
slope: true;
|
|
361
|
+
spacing: true;
|
|
362
|
+
specularConstant: true;
|
|
363
|
+
specularExponent: true;
|
|
364
|
+
speed: true;
|
|
365
|
+
spreadMethod: true;
|
|
366
|
+
startOffset: true;
|
|
367
|
+
stdDeviation: true;
|
|
368
|
+
stitchTiles: true;
|
|
369
|
+
surfaceScale: true;
|
|
370
|
+
targetX: true;
|
|
371
|
+
targetY: true;
|
|
372
|
+
to: true;
|
|
373
|
+
values: true;
|
|
374
|
+
xChannelSelector: true;
|
|
375
|
+
yChannelSelector: true;
|
|
376
|
+
zoomAndPan: true;
|
|
377
|
+
accentHeight: true;
|
|
378
|
+
alphabetic: true;
|
|
379
|
+
arabicForm: true;
|
|
380
|
+
ascent: true;
|
|
381
|
+
bbox: true;
|
|
382
|
+
capHeight: true;
|
|
383
|
+
descent: true;
|
|
384
|
+
fontFamily: true;
|
|
385
|
+
fontSize: true;
|
|
386
|
+
fontSizeAdjust: true;
|
|
387
|
+
fontStretch: true;
|
|
388
|
+
fontStyle: true;
|
|
389
|
+
fontVariant: true;
|
|
390
|
+
fontWeight: true;
|
|
391
|
+
format: true;
|
|
392
|
+
g1: true;
|
|
393
|
+
g2: true;
|
|
394
|
+
glyphName: true;
|
|
395
|
+
glyphOrientationHorizontal: true;
|
|
396
|
+
glyphOrientationVertical: true;
|
|
397
|
+
glyphRef: true;
|
|
398
|
+
hanging: true;
|
|
399
|
+
horizAdvX: true;
|
|
400
|
+
horizOriginX: true;
|
|
401
|
+
ideographic: true;
|
|
402
|
+
kerning: true;
|
|
403
|
+
lengthAdjust: true;
|
|
404
|
+
letterSpacing: true;
|
|
405
|
+
local: true;
|
|
406
|
+
mathematical: true;
|
|
407
|
+
overlinePosition: true;
|
|
408
|
+
overlineThickness: true;
|
|
409
|
+
panose1: true;
|
|
410
|
+
refX: true;
|
|
411
|
+
refY: true;
|
|
412
|
+
renderingIntent: true;
|
|
413
|
+
strikethroughPosition: true;
|
|
414
|
+
strikethroughThickness: true;
|
|
415
|
+
string: true;
|
|
416
|
+
systemLanguage: true;
|
|
417
|
+
tableValues: true;
|
|
418
|
+
textLength: true;
|
|
419
|
+
u1: true;
|
|
420
|
+
u2: true;
|
|
421
|
+
underlinePosition: true;
|
|
422
|
+
underlineThickness: true;
|
|
423
|
+
unicode: true;
|
|
424
|
+
unicodeRange: true;
|
|
425
|
+
unitsPerEm: true;
|
|
426
|
+
vAlphabetic: true;
|
|
427
|
+
vHanging: true;
|
|
428
|
+
vIdeographic: true;
|
|
429
|
+
vMathematical: true;
|
|
430
|
+
vertAdvY: true;
|
|
431
|
+
vertOriginX: true;
|
|
432
|
+
vertOriginY: true;
|
|
433
|
+
widths: true;
|
|
434
|
+
xHeight: true;
|
|
435
|
+
clipPathUnits: true;
|
|
436
|
+
contentScriptType: true;
|
|
437
|
+
contentStyleType: true;
|
|
438
|
+
gradientTransform: true;
|
|
439
|
+
gradientUnits: true;
|
|
440
|
+
markerHeight: true;
|
|
441
|
+
markerUnits: true;
|
|
442
|
+
markerWidth: true;
|
|
443
|
+
maskContentUnits: true;
|
|
444
|
+
maskUnits: true;
|
|
445
|
+
offset: true;
|
|
446
|
+
patternContentUnits: true;
|
|
447
|
+
patternTransform: true;
|
|
448
|
+
patternUnits: true;
|
|
449
|
+
preserveAlpha: true;
|
|
450
|
+
preserveAspectRatio: true;
|
|
451
|
+
requiredExtensions: true;
|
|
452
|
+
requiredFeatures: true;
|
|
453
|
+
viewTarget: true;
|
|
454
|
+
xlinkActuate: true;
|
|
455
|
+
xlinkArcrole: true;
|
|
456
|
+
xlinkHref: true;
|
|
457
|
+
xlinkRole: true;
|
|
458
|
+
xlinkShow: true;
|
|
459
|
+
xlinkTitle: true;
|
|
460
|
+
xlinkType: true;
|
|
461
|
+
xmlBase: true;
|
|
462
|
+
xmlns: true;
|
|
463
|
+
xmlnsXlink: true;
|
|
464
|
+
xmlLang: true;
|
|
465
|
+
xmlSpace: true;
|
|
466
|
+
for: true;
|
|
467
|
+
class: true;
|
|
468
|
+
autofocus: true;
|
|
469
|
+
children: true;
|
|
470
|
+
dangerouslySetInnerHTML: true;
|
|
471
|
+
key: true;
|
|
472
|
+
ref: true;
|
|
473
|
+
defaultValue: true;
|
|
474
|
+
defaultChecked: true;
|
|
475
|
+
innerHTML: true;
|
|
476
|
+
suppressContentEditableWarning: true;
|
|
477
|
+
suppressHydrationWarning: true;
|
|
478
|
+
valueLink: true;
|
|
479
|
+
onCaptured: true;
|
|
480
|
+
precedence: true;
|
|
481
|
+
blocking: true;
|
|
482
|
+
autoCorrect: true;
|
|
483
|
+
autoCapitalize: true;
|
|
484
|
+
popover: true;
|
|
485
|
+
popoverTarget: true;
|
|
486
|
+
popoverTargetAction: true;
|
|
487
|
+
inert: true;
|
|
488
|
+
fetchpriority: true;
|
|
489
|
+
fetchPriority: true;
|
|
490
|
+
shadowRoot: true;
|
|
491
|
+
ariaHasPopup: true;
|
|
492
|
+
ariaLabel: true;
|
|
493
|
+
ariaLabelledBy: true;
|
|
494
|
+
about: true;
|
|
495
|
+
datatype: true;
|
|
496
|
+
inlist: true;
|
|
497
|
+
prefix: true;
|
|
498
|
+
property: true;
|
|
499
|
+
resource: true;
|
|
500
|
+
typeof: true;
|
|
501
|
+
vocab: true;
|
|
502
|
+
itemProp: true;
|
|
503
|
+
itemScope: true;
|
|
504
|
+
itemType: true;
|
|
505
|
+
itemID: true;
|
|
506
|
+
itemRef: true;
|
|
507
|
+
autoSave: true;
|
|
508
|
+
incremental: true;
|
|
509
|
+
results: true;
|
|
510
|
+
security: true;
|
|
511
|
+
unselectable: true;
|
|
512
|
+
on: true;
|
|
513
|
+
option: true;
|
|
514
|
+
fallback: true;
|
|
515
|
+
};
|
|
516
|
+
declare const VALID_DOM_TESTING_KEYS: string[];
|
|
517
|
+
|
|
518
|
+
declare const HTML_TAGS: readonly ["div", "span", "a", "p", "ul", "li"];
|
|
519
|
+
declare const SAFE_HTML_TAGS: readonly ["b", "i", "p", "ul", "li", "a", "span", "div", "br", "strong", "em", "u", "code", "pre", "blockquote"];
|
|
520
|
+
declare const DEFAULT_KEYBOARD_CONFIG: Required<TKeyboardConfig>;
|
|
521
|
+
|
|
522
|
+
declare const __brand: unique symbol;
|
|
523
|
+
type Branded<T, B> = T & {
|
|
524
|
+
[__brand]: B;
|
|
525
|
+
};
|
|
526
|
+
type TBufferLikeObject = Branded<{
|
|
527
|
+
type: 'Buffer';
|
|
528
|
+
data: number[];
|
|
529
|
+
}, 'TBufferLikeObject'>;
|
|
530
|
+
type TAbsoluteURL = Branded<URL, 'TAbsoluteURL'>;
|
|
531
|
+
type TInternalUrl = Branded<string, 'TInternalUrl'>;
|
|
532
|
+
type THexByteString = Branded<string, 'THexByteString'>;
|
|
533
|
+
type TJSONArrayString = Branded<string, 'TJSONArrayString'>;
|
|
534
|
+
type TJSONObjectString = Branded<string, 'TJSONObjectString'>;
|
|
535
|
+
|
|
536
|
+
type TTypeGuard<T> = (value: unknown) => value is T;
|
|
537
|
+
type TAssert<T> = (value: unknown) => asserts value is T;
|
|
538
|
+
type TAnyFunction = (...args: unknown[]) => unknown;
|
|
539
|
+
type TJSONDataString = TJSONObjectString | TJSONArrayString;
|
|
540
|
+
type TElementLike = {
|
|
541
|
+
type: string;
|
|
542
|
+
props: {
|
|
543
|
+
children?: unknown;
|
|
544
|
+
[key: string]: unknown;
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
type THTMLTags = (typeof HTML_TAGS)[number];
|
|
548
|
+
|
|
549
|
+
type TLogType = 'log' | 'warn' | 'error' | 'info' | 'debug' | 'table';
|
|
550
|
+
type THighlighterMap = Record<TLogType, (text: string) => string>;
|
|
551
|
+
type TLogOptions = {
|
|
552
|
+
enabled?: boolean;
|
|
553
|
+
highlighters?: THighlighterMap;
|
|
554
|
+
overrideDev?: boolean;
|
|
555
|
+
};
|
|
556
|
+
type TGetCallerLocationOptions = {
|
|
557
|
+
preferredIndex?: number;
|
|
558
|
+
/** Fallback index if preferredIndex is not available (default: 2) */
|
|
559
|
+
fallbackIndex?: number;
|
|
560
|
+
/** Whether to get the top-level parent function instead of preferredIndex (default: false) */
|
|
561
|
+
topParent?: boolean;
|
|
562
|
+
/** Path prefix to strip from the returned line (default: process.cwd()) */
|
|
563
|
+
stripPathPrefix?: string;
|
|
564
|
+
};
|
|
565
|
+
type TTableItem = {
|
|
566
|
+
key?: string;
|
|
567
|
+
start?: number;
|
|
568
|
+
end?: number;
|
|
569
|
+
};
|
|
570
|
+
type TProcessedTableItem = {
|
|
571
|
+
key: string | number;
|
|
572
|
+
duration: string;
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
type TPropMap = Record<string, boolean>;
|
|
576
|
+
type TPropCategories = {
|
|
577
|
+
readonly [category: string]: TPropMap;
|
|
578
|
+
};
|
|
579
|
+
/**
|
|
580
|
+
* A structural contract for any React component that might have
|
|
581
|
+
* identification metadata.
|
|
582
|
+
*/
|
|
583
|
+
type TNamedComponent = {
|
|
584
|
+
displayName?: string;
|
|
585
|
+
name?: string;
|
|
586
|
+
/** Support for nested types in Memo/ForwardRef */
|
|
587
|
+
type?: TNamedComponent;
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
type TKeyboardActionResult = {
|
|
591
|
+
isPaste: boolean;
|
|
592
|
+
isCopy: boolean;
|
|
593
|
+
isClear: boolean;
|
|
594
|
+
isAllowedKey: boolean;
|
|
595
|
+
shouldBlockTyping: boolean;
|
|
596
|
+
};
|
|
597
|
+
type ModifierKey = 'ctrl' | 'meta' | 'alt' | 'shift';
|
|
598
|
+
type TShortcutDefinition = {
|
|
599
|
+
key: string;
|
|
600
|
+
modifiers: ModifierKey[];
|
|
601
|
+
};
|
|
602
|
+
type TKeyboardConfig = {
|
|
603
|
+
allowedKeys?: string[];
|
|
604
|
+
clearKeys?: string[];
|
|
605
|
+
copyShortcut?: TShortcutDefinition;
|
|
606
|
+
pasteShortcut?: TShortcutDefinition;
|
|
607
|
+
};
|
|
608
|
+
type TBaseImageObject = {
|
|
609
|
+
src: string;
|
|
610
|
+
[key: string]: unknown;
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* Local alias for the native DOM ScrollLogicalPosition.
|
|
614
|
+
* This resolves the ESLint 'no-undef' error and ensures
|
|
615
|
+
* compatibility across different TS configurations.
|
|
616
|
+
*/
|
|
617
|
+
type TScrollLogicalPosition = 'center' | 'end' | 'start' | 'nearest';
|
|
618
|
+
type TScrollBehavior = 'auto' | 'smooth';
|
|
619
|
+
type THashScrollOptions = {
|
|
620
|
+
href: string;
|
|
621
|
+
behavior?: TScrollBehavior;
|
|
622
|
+
block?: TScrollLogicalPosition;
|
|
623
|
+
event?: {
|
|
624
|
+
preventDefault: () => void;
|
|
625
|
+
};
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
type TGenericUrlObject = {
|
|
629
|
+
pathname?: string | null;
|
|
630
|
+
query?: Record<string, string | number | boolean | string[] | undefined> | null;
|
|
631
|
+
hash?: string | null;
|
|
632
|
+
[key: string]: unknown;
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* ## 🧩 Available Methods
|
|
637
|
+
*
|
|
638
|
+
* - `includes` — Type-safe `Array.includes` helper for union narrowing.
|
|
639
|
+
* - `createFixedLengthArray` — Ensures arrays have a fixed compile-time length.
|
|
640
|
+
* - `readAllItems` — Returns a shallow copy of an array.
|
|
641
|
+
* - `map` — Type-safe wrapper around `Array.map`.
|
|
642
|
+
* - `forEachUnion` — Handles arrays with union element types safely.
|
|
643
|
+
* - `forEach` — Standard, type-safe `forEach` wrapper.
|
|
644
|
+
* - `reduce` — Strictly typed reduction helper.
|
|
645
|
+
* - `flat` — One-level flattening helper.
|
|
646
|
+
* - `flatMap` — Safe flatMap alternative with strong typing.
|
|
647
|
+
* - `filter` — Generic and narrowed type-safe filter.
|
|
648
|
+
* - `filterNonNullable` — Removes nullish values safely.
|
|
649
|
+
*
|
|
650
|
+
* ---
|
|
651
|
+
* @see {@link CommonUtilsDocs.ArrayUtils}
|
|
652
|
+
*/
|
|
653
|
+
declare class ArrayUtils {
|
|
654
|
+
/** @see {@link ArrayUtilsDocs.includes} */
|
|
655
|
+
static includes<T extends U, U>(arr: ReadonlyArray<T>, el: U): el is T;
|
|
656
|
+
/** @see {@link ArrayUtilsDocs.createFixedLengthArray} */
|
|
657
|
+
static createFixedLengthArray<T>(items: T[], length: number): TFixedLengthArray<T[]>;
|
|
658
|
+
/**
|
|
659
|
+
* Returns a shallow copy of an array.
|
|
660
|
+
*
|
|
661
|
+
* @typeParam T - Type of array elements.
|
|
662
|
+
* @param arr - Array to copy.
|
|
663
|
+
* @returns A new array containing all items.
|
|
664
|
+
*
|
|
665
|
+
* @example
|
|
666
|
+
* const original = [1, 2, 3];
|
|
667
|
+
* const copy = ArrayUtils.readAllItems(original);
|
|
668
|
+
* copy.push(4); // Does not affect `original`
|
|
669
|
+
*/
|
|
670
|
+
static readAllItems<T>(arr: ReadonlyArray<T>): T[];
|
|
671
|
+
/** 🧠 Safe map wrapper with correct inference */
|
|
672
|
+
static map<T, U>(arr: ReadonlyArray<T>, fn: (value: T, index: number, array: ReadonlyArray<T>) => U): U[];
|
|
673
|
+
/**
|
|
674
|
+
* 🧠 Type-safe forEach for arrays that might be union types.
|
|
675
|
+
* Helps TypeScript narrow union members while iterating.
|
|
676
|
+
*
|
|
677
|
+
* Supports both:
|
|
678
|
+
* - Single arrays: `T[]`
|
|
679
|
+
* - Union of arrays: `T[][]`
|
|
680
|
+
*
|
|
681
|
+
* @typeParam T - The type of array elements.
|
|
682
|
+
*
|
|
683
|
+
* @param arr - The array or array of arrays to iterate over.
|
|
684
|
+
* @param fn - Callback executed for each element.
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* // Single array
|
|
688
|
+
* const numbers = [1, 2, 3];
|
|
689
|
+
* ArrayUtils.forEachUnion(numbers, (num, idx) => {
|
|
690
|
+
* console.log(num * 2, idx);
|
|
691
|
+
* });
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* // Union of arrays
|
|
695
|
+
* const arrays: number[][] = [[1, 2], [3, 4]];
|
|
696
|
+
* ArrayUtils.forEachUnion(arrays, (num, idx) => {
|
|
697
|
+
* console.log(num * 2, idx);
|
|
698
|
+
* });
|
|
699
|
+
*/
|
|
700
|
+
static forEachUnion<T>(arr: T[] | T[][], fn: (item: T, index: number) => void): void;
|
|
701
|
+
/** 🧠 Safe forEach wrapper with correct inference */
|
|
702
|
+
static forEach<T>(arr: ReadonlyArray<T>, fn: (value: T, index: number, array: ReadonlyArray<T>) => void): void;
|
|
703
|
+
static reduce<T, U>(arr: ReadonlyArray<T>, fn: (accumulator: U, current: T, index: number, array: ReadonlyArray<T>) => U, initialValue: U): U;
|
|
704
|
+
/** 🧠 Type-safe flat for 1-level nested arrays */
|
|
705
|
+
static flat<T>(arr: ReadonlyArray<T | T[]>): T[];
|
|
706
|
+
/** 🧠 Type-safe flatMap */
|
|
707
|
+
static flatMap<T, U>(arr: ReadonlyArray<T>, fn: (item: T, index: number) => U | U[]): U[];
|
|
708
|
+
/**
|
|
709
|
+
* 🧠 Type-safe filter wrapper
|
|
710
|
+
* Preserves TypeScript type inference.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* const numbers: (number | null)[] = [1, 2, null, 4];
|
|
714
|
+
* const validNumbers = ArrayUtils.filter(numbers, (n): n is number => n != null);
|
|
715
|
+
*/
|
|
716
|
+
static filter<T, S extends T>(arr: ReadonlyArray<T>, predicate: (value: T, index: number, array: ReadonlyArray<T>) => value is S): S[];
|
|
717
|
+
static filter<T>(arr: ReadonlyArray<T>, predicate: (value: T, index: number, array: ReadonlyArray<T>) => boolean): T[];
|
|
718
|
+
/**
|
|
719
|
+
* Shortcut for filtering out null or undefined values.
|
|
720
|
+
*/
|
|
721
|
+
static filterNonNullable<T>(arr: ReadonlyArray<T | null | undefined>): T[];
|
|
722
|
+
}
|
|
723
|
+
declare const RenamedArrayMethods: {
|
|
724
|
+
arrayIncludes: typeof ArrayUtils.includes;
|
|
725
|
+
arrayMap: typeof ArrayUtils.map;
|
|
726
|
+
arrayFilter: typeof ArrayUtils.filter;
|
|
727
|
+
arrayFlat: typeof ArrayUtils.flat;
|
|
728
|
+
arrayReduce: typeof ArrayUtils.reduce;
|
|
729
|
+
arrayForEach: typeof ArrayUtils.forEach;
|
|
730
|
+
arrayFlatMap: typeof ArrayUtils.flatMap;
|
|
731
|
+
arrayFilterNonNullable: typeof ArrayUtils.filterNonNullable;
|
|
732
|
+
};
|
|
733
|
+
declare const arrayMap: typeof ArrayUtils.map;
|
|
734
|
+
declare const arrayFilter: typeof ArrayUtils.filter;
|
|
735
|
+
declare const arrayIncludes: typeof ArrayUtils.includes;
|
|
736
|
+
declare const arrayReduce: typeof ArrayUtils.reduce;
|
|
737
|
+
declare const arrayFlat: typeof ArrayUtils.flat;
|
|
738
|
+
declare const arrayFlatMap: typeof ArrayUtils.flatMap;
|
|
739
|
+
declare const arrayForEach: typeof ArrayUtils.forEach;
|
|
740
|
+
declare const arrayFilterNonNullable: typeof ArrayUtils.filterNonNullable;
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* ## 🧩 Available Methods
|
|
744
|
+
*
|
|
745
|
+
* - `keys` — Returns the keys of an object with full type inference.
|
|
746
|
+
* - `entries` — Returns typed key-value pairs of an object.
|
|
747
|
+
* - `fromEntries` — Builds a typed object from key-value entry tuples.
|
|
748
|
+
* - `values` — Returns the values of an object with inferred types.
|
|
749
|
+
* - `has` — Checks if a nested property exists via dot notation.
|
|
750
|
+
* - `get` — Safely retrieves a nested property using a dot path.
|
|
751
|
+
* - `set` — Safely sets a nested property using a dot path.
|
|
752
|
+
*
|
|
753
|
+
* ---
|
|
754
|
+
* @see {@link CommonUtilsDocs.ObjectUtils}
|
|
755
|
+
*/
|
|
756
|
+
declare class ObjectUtils {
|
|
757
|
+
/**
|
|
758
|
+
* Returns the keys of an object while protecting key inference.
|
|
759
|
+
*
|
|
760
|
+
* @template Obj - The object type
|
|
761
|
+
* @param {Obj} obj - The object to extract keys from
|
|
762
|
+
*/
|
|
763
|
+
static keys<Obj extends object>(obj: Obj): (keyof Obj)[];
|
|
764
|
+
/**
|
|
765
|
+
* Returns the key-value pairs of an object while protecting type inference.
|
|
766
|
+
*
|
|
767
|
+
* @template T - The object type
|
|
768
|
+
* @param {T} obj - The object to extract key-value pairs from
|
|
769
|
+
*/
|
|
770
|
+
static entries<T extends Record<string, unknown>>(obj: T): [keyof T, T[keyof T]][];
|
|
771
|
+
/**
|
|
772
|
+
* Constructs an object from an array of entries with type safety.
|
|
773
|
+
*/
|
|
774
|
+
static fromEntries<K extends string | number | symbol = string, // default key type
|
|
775
|
+
V = unknown>(entries: [K, V][]): Record<K, V>;
|
|
776
|
+
/**
|
|
777
|
+
* Returns the values of an object while protecting type inference.
|
|
778
|
+
*
|
|
779
|
+
* @template Obj - The object type
|
|
780
|
+
* @param {Obj} obj - The object to extract values from
|
|
781
|
+
*/
|
|
782
|
+
static values<Obj extends object>(obj: Obj): Obj[keyof Obj][];
|
|
783
|
+
/**
|
|
784
|
+
* Checks if a nested property exists in an object using dot notation.
|
|
785
|
+
* @param obj - The object to check.
|
|
786
|
+
* @param path - Dot-separated path like 'user.profile.name'
|
|
787
|
+
*/
|
|
788
|
+
static has<Obj extends object>(obj: Obj, path: string): boolean;
|
|
789
|
+
/**
|
|
790
|
+
* Safely gets a nested property from an object using dot notation.
|
|
791
|
+
* @param obj - The object to access.
|
|
792
|
+
* @param path - Dot-separated path like 'user.profile.name'
|
|
793
|
+
*/
|
|
794
|
+
static get<Obj extends object, Path extends string>(obj: Obj, path: Path): unknown;
|
|
795
|
+
/**
|
|
796
|
+
* Safely sets a nested property on an object using dot notation.
|
|
797
|
+
* Creates intermediate objects as needed.
|
|
798
|
+
* @param obj - The object to modify.
|
|
799
|
+
* @param path - Dot-separated path like 'user.profile.name'
|
|
800
|
+
* @param value - The value to set
|
|
801
|
+
*/
|
|
802
|
+
static set<Obj extends object>(obj: Obj, path: string, value: unknown): void;
|
|
803
|
+
}
|
|
804
|
+
declare const RenamedObjectMethods: {
|
|
805
|
+
objectKeys: typeof ObjectUtils.keys;
|
|
806
|
+
objectEntries: typeof ObjectUtils.entries;
|
|
807
|
+
objectFromEntries: typeof ObjectUtils.fromEntries;
|
|
808
|
+
objectValues: typeof ObjectUtils.values;
|
|
809
|
+
objectHas: typeof ObjectUtils.has;
|
|
810
|
+
objectGet: typeof ObjectUtils.get;
|
|
811
|
+
objectSet: typeof ObjectUtils.set;
|
|
812
|
+
};
|
|
813
|
+
declare const objectKeys: typeof ObjectUtils.keys;
|
|
814
|
+
declare const objectEntries: typeof ObjectUtils.entries;
|
|
815
|
+
declare const objectFromEntries: typeof ObjectUtils.fromEntries;
|
|
816
|
+
declare const objectValues: typeof ObjectUtils.values;
|
|
817
|
+
declare const objectHas: typeof ObjectUtils.has;
|
|
818
|
+
declare const objectGet: typeof ObjectUtils.get;
|
|
819
|
+
declare const objectSet: typeof ObjectUtils.set;
|
|
820
|
+
|
|
821
|
+
declare const isNull: TTypeGuard<null>;
|
|
822
|
+
declare const isUndefined: TTypeGuard<undefined>;
|
|
823
|
+
declare const isDefined: TTypeGuard<unknown>;
|
|
824
|
+
declare const isNil: TTypeGuard<null | undefined>;
|
|
825
|
+
declare const isFunction: TTypeGuard<TAnyFunction>;
|
|
826
|
+
declare const isObject: TTypeGuard<object>;
|
|
827
|
+
declare const isArray: TTypeGuard<unknown[]>;
|
|
828
|
+
declare const isMap: TTypeGuard<Map<unknown, unknown>>;
|
|
829
|
+
declare const isSet: TTypeGuard<Set<unknown>>;
|
|
830
|
+
/**
|
|
831
|
+
* Checks if the given value is an instance of `WeakMap`.
|
|
832
|
+
*
|
|
833
|
+
* A **WeakMap** is a special kind of `Map` where:
|
|
834
|
+
* - **Keys must be objects** (not primitives)
|
|
835
|
+
* - Keys are **held weakly**, meaning if there are no other references to the key object,
|
|
836
|
+
* it can be garbage-collected automatically
|
|
837
|
+
* - It does **not** support iteration (`.keys()`, `.values()`, `.entries()` are not available)
|
|
838
|
+
* - It is ideal for **storing private metadata** about objects without preventing cleanup
|
|
839
|
+
*
|
|
840
|
+
* 🧠 Useful for:
|
|
841
|
+
* - Caching computed data for objects
|
|
842
|
+
* - Associating data with DOM elements without memory leaks
|
|
843
|
+
*
|
|
844
|
+
* 📚 **Learn more:**
|
|
845
|
+
* - [MDN — WeakMap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* ```ts
|
|
849
|
+
* const weakMap = new WeakMap<object, number>();
|
|
850
|
+
* const obj = {};
|
|
851
|
+
*
|
|
852
|
+
* weakMap.set(obj, 42);
|
|
853
|
+
*
|
|
854
|
+
* ReferenceTypeGuards.isWeakMap(weakMap); // true
|
|
855
|
+
* ReferenceTypeGuards.isWeakMap(new Map()); // false
|
|
856
|
+
* ReferenceTypeGuards.isWeakMap({}); // false
|
|
857
|
+
* ```
|
|
858
|
+
*/
|
|
859
|
+
declare const isWeakMap: TTypeGuard<WeakMap<object, unknown>>;
|
|
860
|
+
/**
|
|
861
|
+
* Checks if the given value is an instance of `WeakSet`.
|
|
862
|
+
*
|
|
863
|
+
* A **WeakSet** is a special kind of `Set` where:
|
|
864
|
+
* - It can only store **object values** (no primitives)
|
|
865
|
+
* - Objects are **held weakly**, meaning if there are no other references to an object,
|
|
866
|
+
* it can be garbage-collected automatically
|
|
867
|
+
* - It is **not iterable** — you can’t get its contents or size
|
|
868
|
+
* - Commonly used to track object presence without memory leaks
|
|
869
|
+
*
|
|
870
|
+
* 🧠 Useful for:
|
|
871
|
+
* - Tracking which objects have been processed
|
|
872
|
+
* - Marking objects as “seen” in caches or graph traversals
|
|
873
|
+
*
|
|
874
|
+
* 📚 **Learn more:**
|
|
875
|
+
* - [MDN — WeakSet](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
* ```ts
|
|
879
|
+
* const weakSet = new WeakSet<object>();
|
|
880
|
+
* const obj = {};
|
|
881
|
+
*
|
|
882
|
+
* weakSet.add(obj);
|
|
883
|
+
*
|
|
884
|
+
* ReferenceTypeGuards.isWeakSet(weakSet); // true
|
|
885
|
+
* ReferenceTypeGuards.isWeakSet(new Set()); // false
|
|
886
|
+
* ReferenceTypeGuards.isWeakSet([]); // false
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
declare const isWeakSet: TTypeGuard<WeakSet<object>>;
|
|
890
|
+
declare function isInstanceOf<T extends object, Args extends unknown[]>(value: unknown, constructor: new (...args: Args) => T): value is T;
|
|
891
|
+
|
|
892
|
+
declare const isNumber: TTypeGuard<number>;
|
|
893
|
+
declare const isInteger: TTypeGuard<number>;
|
|
894
|
+
declare const isString: TTypeGuard<string>;
|
|
895
|
+
declare const isNonEmptyString: TTypeGuard<string>;
|
|
896
|
+
declare const isBoolean: TTypeGuard<boolean>;
|
|
897
|
+
/**
|
|
898
|
+
* Checks if the value is a bigint.
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```ts
|
|
902
|
+
* PrimitiveTypeGuards.isBigInt(123n); // true
|
|
903
|
+
* PrimitiveTypeGuards.isBigInt(123); // false
|
|
904
|
+
* ```
|
|
905
|
+
*/
|
|
906
|
+
declare const isBigInt: TTypeGuard<bigint>;
|
|
907
|
+
/**
|
|
908
|
+
* Checks whether a value is a `symbol`.
|
|
909
|
+
*
|
|
910
|
+
* In JavaScript, a `symbol` is a unique and immutable primitive value that can be used as a key
|
|
911
|
+
* for object properties. Each symbol is guaranteed to be unique, even if two symbols have the same
|
|
912
|
+
* description.
|
|
913
|
+
*
|
|
914
|
+
* Key points:
|
|
915
|
+
* - Symbols are often used to add unique property keys to objects without risk of name collisions.
|
|
916
|
+
* - `typeof value === 'symbol'` is used to check if a value is a symbol.
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```ts
|
|
920
|
+
* const sym1 = Symbol('foo');
|
|
921
|
+
* const sym2 = Symbol('foo');
|
|
922
|
+
*
|
|
923
|
+
* isSymbol(sym1); // true
|
|
924
|
+
* isSymbol(sym2); // true
|
|
925
|
+
* isSymbol('foo'); // false
|
|
926
|
+
*
|
|
927
|
+
* const obj = { [sym1]: 123 };
|
|
928
|
+
* console.log(obj[sym1]); // 123
|
|
929
|
+
* ```
|
|
930
|
+
*/
|
|
931
|
+
declare const isSymbol: TTypeGuard<symbol>;
|
|
932
|
+
declare const isPrimitive: (value: unknown) => value is string | number | boolean;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* ## 🧩 isInArray — Type Guard Factory for Array Membership
|
|
936
|
+
*
|
|
937
|
+
* Creates a **type guard** that checks whether a value exists in a given array.
|
|
938
|
+
* Internally, it uses a `Set` for **O(1) lookup**, making repeated checks more efficient.
|
|
939
|
+
*
|
|
940
|
+
* ---
|
|
941
|
+
*
|
|
942
|
+
* ### ⚙️ Core Purpose
|
|
943
|
+
* - 🔹 Verify that a value is included in a predefined array of allowed values.
|
|
944
|
+
* - 🔹 Provide a **TypeScript type guard** so that the compiler can narrow types.
|
|
945
|
+
* - 🔹 Optimized for repeated checks by creating a `Set` once per factory call.
|
|
946
|
+
*
|
|
947
|
+
* ---
|
|
948
|
+
*
|
|
949
|
+
* ### 📘 Example Usage
|
|
950
|
+
* ```ts
|
|
951
|
+
* // Store the returned type guard for repeated checks
|
|
952
|
+
* const isAllowedColor = isInArray(['red', 'green', 'blue'] as const);
|
|
953
|
+
* isAllowedColor('red'); // true
|
|
954
|
+
* isAllowedColor('yellow'); // false
|
|
955
|
+
*
|
|
956
|
+
* const isAllowedNumber = isInArray([1, 2, 3] as const);
|
|
957
|
+
* isAllowedNumber(2); // true
|
|
958
|
+
* isAllowedNumber(4); // false
|
|
959
|
+
*
|
|
960
|
+
* // Or invoke inline without storing the guard
|
|
961
|
+
* isInArray(['red', 'green', 'blue'] as const)('green'); // true
|
|
962
|
+
* ```
|
|
963
|
+
*
|
|
964
|
+
*
|
|
965
|
+
* ---
|
|
966
|
+
*
|
|
967
|
+
* ### 📌 Notes
|
|
968
|
+
* - This is a **factory function**: you first pass the array, then use the returned function as a type guard.
|
|
969
|
+
* - The returned guard checks for `undefined` and only returns `true` if the value exists in the array.
|
|
970
|
+
* - Use this guard when you need **repeated membership checks** on a fixed array of values.
|
|
971
|
+
*
|
|
972
|
+
* @typeParam T - The type of elements in the target array.
|
|
973
|
+
* @param target - The array of allowed values.
|
|
974
|
+
* @returns A type guard function that narrows `unknown` to `T | undefined`.
|
|
975
|
+
*/
|
|
976
|
+
declare const isInArray: <T>(target: readonly T[]) => TTypeGuard<T | undefined>;
|
|
977
|
+
/**
|
|
978
|
+
* Checks whether a value is a valid key of a given object.
|
|
979
|
+
*
|
|
980
|
+
* This function returns a **TypeScript type guard**, allowing you to safely
|
|
981
|
+
* access object properties with dynamic keys while retaining full type safety.
|
|
982
|
+
*
|
|
983
|
+
* Key points:
|
|
984
|
+
* - Works with `string`, `number`, and `symbol` keys.
|
|
985
|
+
* - Returns a type guard `(key: unknown) => key is keyof T`.
|
|
986
|
+
* - Useful for runtime checks before accessing object properties dynamically.
|
|
987
|
+
*
|
|
988
|
+
* @typeParam T - The type of the target object.
|
|
989
|
+
* @param obj - The object whose keys should be checked against.
|
|
990
|
+
* @param key - The value to check if it is a valid key of `obj`.
|
|
991
|
+
* @returns `true` if `key` exists in `obj`; otherwise `false`.
|
|
992
|
+
*
|
|
993
|
+
* @example
|
|
994
|
+
* ```ts
|
|
995
|
+
* const user = { id: 1, name: 'Alice', email: 'alice@example.com' };
|
|
996
|
+
*
|
|
997
|
+
* isKeyOfObject(user, 'name'); // true ✅ 'name' is a valid key
|
|
998
|
+
* isKeyOfObject(user, 'password'); // false ❌ 'password' is not a valid key
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
declare const isKeyOfObject: <T extends object>(obj: T) => TTypeGuard<keyof T>;
|
|
1002
|
+
/**
|
|
1003
|
+
* Type guard that checks whether a given unknown value is an object
|
|
1004
|
+
* and contains a specific property key.
|
|
1005
|
+
*
|
|
1006
|
+
* Unlike `isKeyOfObject(obj)(key)` which only narrows the *key* type,
|
|
1007
|
+
* this guard narrows the *object* itself. After calling this function,
|
|
1008
|
+
* TypeScript knows that:
|
|
1009
|
+
*
|
|
1010
|
+
* - `obj` is a non-null object
|
|
1011
|
+
* - `obj` contains the property `key`
|
|
1012
|
+
* - you can safely access `obj[key]`
|
|
1013
|
+
*
|
|
1014
|
+
* This is the preferred guard to use when you need to safely access
|
|
1015
|
+
* dynamic or unknown object properties, such as when validating
|
|
1016
|
+
* external or untyped data (e.g., errors from Supabase or fetch APIs).
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* if (isKeyInObject("message")(err)) {
|
|
1020
|
+
* console.log(err.message); // fully typed and safe
|
|
1021
|
+
* }
|
|
1022
|
+
*
|
|
1023
|
+
* @param key - The property key to check for.
|
|
1024
|
+
* @returns A type guard that checks if an unknown value is an object
|
|
1025
|
+
* containing the specified key.
|
|
1026
|
+
*/
|
|
1027
|
+
declare const isKeyInObject: <K extends PropertyKey>(key: K) => (obj: unknown) => obj is Record<K, unknown>;
|
|
1028
|
+
/**
|
|
1029
|
+
* ## 🧩 isKeyOfArray — Type Guard for Allowed Primitive Keys
|
|
1030
|
+
*
|
|
1031
|
+
* Checks if a value is one of the keys in a given readonly array of allowed keys.
|
|
1032
|
+
* This is a **type-safe type guard** for primitive keys (`string | number | symbol`)
|
|
1033
|
+
* that exist in a known array. It is useful for narrowing a value to a specific set
|
|
1034
|
+
* of literal keys at runtime.
|
|
1035
|
+
*
|
|
1036
|
+
* ---
|
|
1037
|
+
*
|
|
1038
|
+
* ### ⚙️ Core Purpose
|
|
1039
|
+
* - 🔹 Only works with **primitive keys**: `string`, `number`, or `symbol`.
|
|
1040
|
+
* - 🔹 Returns a **TypeScript type guard** (`key is T[number]`) for type inference.
|
|
1041
|
+
* - 🔹 Uses `Array.includes` to check for membership in the allowed keys array.
|
|
1042
|
+
*
|
|
1043
|
+
* ---
|
|
1044
|
+
*
|
|
1045
|
+
* ### 📘 Example Usage
|
|
1046
|
+
* ```ts
|
|
1047
|
+
* const allowedKeys = ['id', 'name', 'age'] as const;
|
|
1048
|
+
* const key: unknown = 'name';
|
|
1049
|
+
*
|
|
1050
|
+
* if (isKeyOfArray(allowedKeys)(key)) {
|
|
1051
|
+
* // ✅ TypeScript now knows `key` is 'id' | 'name' | 'age'
|
|
1052
|
+
* console.log(key); // 'name'
|
|
1053
|
+
* }
|
|
1054
|
+
*
|
|
1055
|
+
* const invalidKey: unknown = 'email';
|
|
1056
|
+
* isKeyOfArray(allowedKeys)(invalidKey); // false
|
|
1057
|
+
*
|
|
1058
|
+
* // Inline usage
|
|
1059
|
+
* isKeyOfArray(['x', 'y', 'z'] as const)('x'); // true
|
|
1060
|
+
* isKeyOfArray(['x', 'y', 'z'] as const)('a'); // false
|
|
1061
|
+
* ```
|
|
1062
|
+
*
|
|
1063
|
+
* ---
|
|
1064
|
+
*
|
|
1065
|
+
* @typeParam T - A readonly tuple or array of allowed keys.
|
|
1066
|
+
* @param keys - The array of valid keys.
|
|
1067
|
+
* @returns A type guard function that returns `true` if the value is included in `keys`.
|
|
1068
|
+
*/
|
|
1069
|
+
declare const isKeyOfArray: <T extends readonly (string | number | symbol)[]>(keys: T) => TTypeGuard<T[number]>;
|
|
1070
|
+
/**
|
|
1071
|
+
* ## 🧩 isArrayOf — Type Guard for Arrays of Specific Types
|
|
1072
|
+
*
|
|
1073
|
+
* Checks if a value is an array where **all elements satisfy a given type guard**.
|
|
1074
|
+
* This allows TypeScript to narrow types safely and perform runtime validation.
|
|
1075
|
+
*
|
|
1076
|
+
* ---
|
|
1077
|
+
*
|
|
1078
|
+
* ### ⚙️ Core Purpose
|
|
1079
|
+
* - 🔹 Verify that a value is an array.
|
|
1080
|
+
* - 🔹 Ensure that **every element** matches a specific type guard.
|
|
1081
|
+
* - 🔹 Enable **type-safe operations** on arrays after the check.
|
|
1082
|
+
*
|
|
1083
|
+
* ---
|
|
1084
|
+
*
|
|
1085
|
+
* ### 📘 Example Usage
|
|
1086
|
+
* ```ts
|
|
1087
|
+
* import { isArrayOf, isNumber, isString } from '@/utils/guards/composite';
|
|
1088
|
+
*
|
|
1089
|
+
* const arr1: unknown = [1, 2, 3];
|
|
1090
|
+
* if (isArrayOf(isNumber, arr1)) {
|
|
1091
|
+
* // ✅ arr1 is now typed as number[]
|
|
1092
|
+
* const sum = arr1.reduce((a, b) => a + b, 0);
|
|
1093
|
+
* }
|
|
1094
|
+
*
|
|
1095
|
+
* const arr2: unknown = ['a', 'b', 3];
|
|
1096
|
+
* isArrayOf(isString, arr2); // false
|
|
1097
|
+
* ```
|
|
1098
|
+
*
|
|
1099
|
+
* ---
|
|
1100
|
+
*
|
|
1101
|
+
* ### 📌 Notes
|
|
1102
|
+
* - The **type guard is passed as a parameter**, making this function highly composable.
|
|
1103
|
+
* - Use for arrays of primitives or arrays of objects validated by another type guard.
|
|
1104
|
+
*
|
|
1105
|
+
* @typeParam T - Type of array elements.
|
|
1106
|
+
* @param typeGuard - Type guard function for the array elements.
|
|
1107
|
+
* @param value - Value to validate.
|
|
1108
|
+
* @returns `true` if `value` is an array and all elements pass the type guard.
|
|
1109
|
+
*/
|
|
1110
|
+
declare const isArrayOf: <T>(typeGuard: TTypeGuard<T>, value: unknown) => value is T[];
|
|
1111
|
+
/**
|
|
1112
|
+
* ## 🧩 isRecordOf — Type Guard for Objects with Uniform Value Types
|
|
1113
|
+
*
|
|
1114
|
+
* Checks if a value is an object where **all property values satisfy a given type guard**.
|
|
1115
|
+
* Useful for ensuring that a record has uniform value types and for type-safe access.
|
|
1116
|
+
*
|
|
1117
|
+
* ---
|
|
1118
|
+
*
|
|
1119
|
+
* ### ⚙️ Core Purpose
|
|
1120
|
+
* - 🔹 Verify that a value is an object (non-null).
|
|
1121
|
+
* - 🔹 Ensure that every property value passes a provided type guard.
|
|
1122
|
+
* - 🔹 Enable **type-safe operations** on objects with consistent value types.
|
|
1123
|
+
*
|
|
1124
|
+
* ---
|
|
1125
|
+
*
|
|
1126
|
+
* ### 📘 Example Usage
|
|
1127
|
+
* ```ts
|
|
1128
|
+
* import { isRecordOf, isNumber, isBoolean } from '@/utils/guards/composite';
|
|
1129
|
+
*
|
|
1130
|
+
* const obj1: unknown = { a: 1, b: 2 };
|
|
1131
|
+
* if (isRecordOf(obj1, isNumber)) {
|
|
1132
|
+
* // ✅ obj1 is now typed as Record<string, number>
|
|
1133
|
+
* const sum = Object.values(obj1).reduce((a, b) => a + b, 0);
|
|
1134
|
+
* }
|
|
1135
|
+
*
|
|
1136
|
+
* const obj2: unknown = { a: 1, b: '2' };
|
|
1137
|
+
* isRecordOf(obj2, isNumber); // false
|
|
1138
|
+
*
|
|
1139
|
+
* const obj3: unknown = { foo: true, bar: false };
|
|
1140
|
+
* isRecordOf(obj3, isBoolean); // true
|
|
1141
|
+
* ```
|
|
1142
|
+
*
|
|
1143
|
+
* ---
|
|
1144
|
+
*
|
|
1145
|
+
* ### 📌 Notes
|
|
1146
|
+
* - Works only with **plain objects** (non-null) and string keys.
|
|
1147
|
+
* - Supports composability by accepting any type guard for property values.
|
|
1148
|
+
*
|
|
1149
|
+
* @typeParam V - Type of the values in the record.
|
|
1150
|
+
* @param value - Value to check.
|
|
1151
|
+
* @param typeGuard - Type guard function applied to each property value.
|
|
1152
|
+
* @returns `true` if `value` is an object and all property values pass the type guard.
|
|
1153
|
+
*/
|
|
1154
|
+
declare const isRecordOf: <V>(value: unknown, typeGuard: TTypeGuard<V>) => value is Record<string, V>;
|
|
1155
|
+
/**
|
|
1156
|
+
* ## 🔑 hasDefinedKeys — Type Guard Factory for Required Object Properties
|
|
1157
|
+
*
|
|
1158
|
+
* Creates a type guard that ensures an object contains a specific set of **required keys**
|
|
1159
|
+
* and that their values are **defined** (not `undefined`).
|
|
1160
|
+
*
|
|
1161
|
+
* ---
|
|
1162
|
+
*
|
|
1163
|
+
* ### ⚙️ Core Purpose
|
|
1164
|
+
* - 🔹 Validate that an object implements a specific interface or shape.
|
|
1165
|
+
* - 🔹 Ensure critical properties exist and are not `undefined`.
|
|
1166
|
+
* - 🔹 Narrow an `unknown` object to a specific type `T` for safe property access.
|
|
1167
|
+
*
|
|
1168
|
+
* ---
|
|
1169
|
+
*
|
|
1170
|
+
* ### 📘 Example Usage
|
|
1171
|
+
* ```ts
|
|
1172
|
+
* import { hasDefinedKeys } from '@/utils/guards/composite';
|
|
1173
|
+
*
|
|
1174
|
+
* interface User { id: string; name: string; age?: number; }
|
|
1175
|
+
*
|
|
1176
|
+
* // Create a guard for required fields
|
|
1177
|
+
* const isUser = hasDefinedKeys<User>(['id', 'name']);
|
|
1178
|
+
*
|
|
1179
|
+
* const data: unknown = { id: 'u1', name: 'Alice' };
|
|
1180
|
+
*
|
|
1181
|
+
* if (isUser(data)) {
|
|
1182
|
+
* // ✅ data is now typed as User
|
|
1183
|
+
* console.log(data.id, data.name);
|
|
1184
|
+
* }
|
|
1185
|
+
*
|
|
1186
|
+
* const invalid: unknown = { id: 'u2' };
|
|
1187
|
+
* isUser(invalid); // false (missing 'name')
|
|
1188
|
+
* ```
|
|
1189
|
+
*
|
|
1190
|
+
* ---
|
|
1191
|
+
*
|
|
1192
|
+
* ### 📌 Notes
|
|
1193
|
+
* - This is a **factory function**; it returns a new type guard function.
|
|
1194
|
+
* - It checks for the existence of the key *and* that the value is not `undefined`.
|
|
1195
|
+
* - Ideal for validating API responses or configuration objects.
|
|
1196
|
+
*
|
|
1197
|
+
* @typeParam T - The target object type to validate against.
|
|
1198
|
+
* @param requiredKeys - An array of keys from type `T` that must be present and defined.
|
|
1199
|
+
* @returns A type guard function that returns `true` if all `requiredKeys` are found and defined.
|
|
1200
|
+
*/
|
|
1201
|
+
declare const hasDefinedKeys: <T extends object>(requiredKeys: (keyof T)[]) => ((value: unknown) => value is T);
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Checks if a value is a **Buffer-like object**.
|
|
1205
|
+
*
|
|
1206
|
+
* A Buffer-like object is an object with the following shape:
|
|
1207
|
+
* ```ts
|
|
1208
|
+
* {
|
|
1209
|
+
* type: 'Buffer';
|
|
1210
|
+
* data: number[];
|
|
1211
|
+
* }
|
|
1212
|
+
* ```
|
|
1213
|
+
*
|
|
1214
|
+
* This guard validates:
|
|
1215
|
+
* - ✅ The value is a non-null object
|
|
1216
|
+
* - ✅ The `type` property exists and is exactly `'Buffer'`
|
|
1217
|
+
* - ✅ The `data` property exists and is an array of numbers
|
|
1218
|
+
*
|
|
1219
|
+
* ---
|
|
1220
|
+
* ### Key Points
|
|
1221
|
+
* - Uses `isObject` to ensure the value is an object
|
|
1222
|
+
* - Uses `isArrayOf(isNumber)` to check that `data` contains only numbers
|
|
1223
|
+
* - This is a **composite type guard** because it combines multiple primitive/reference checks
|
|
1224
|
+
*
|
|
1225
|
+
* ---
|
|
1226
|
+
* ### Example Usage
|
|
1227
|
+
* ```ts
|
|
1228
|
+
* const buf = { type: 'Buffer', data: [1, 2, 3] };
|
|
1229
|
+
* const notBuf = { type: 'Buffer', data: ['a', 'b'] };
|
|
1230
|
+
*
|
|
1231
|
+
* isBufferLikeObject(buf); // true
|
|
1232
|
+
* isBufferLikeObject(notBuf); // false
|
|
1233
|
+
* ```
|
|
1234
|
+
*
|
|
1235
|
+
* ---
|
|
1236
|
+
* @param value - The value to check
|
|
1237
|
+
* @returns `true` if the value is a Buffer-like object, otherwise `false`
|
|
1238
|
+
*/
|
|
1239
|
+
declare const isBufferLikeObject: TTypeGuard<TBufferLikeObject>;
|
|
1240
|
+
/**
|
|
1241
|
+
* ## 🎨 isRGBTuple — Type Guard for Color Values
|
|
1242
|
+
*
|
|
1243
|
+
* Validates if a value is an array of exactly three numbers, each representing
|
|
1244
|
+
* a standard 8-bit color channel (0-255).
|
|
1245
|
+
*
|
|
1246
|
+
* ---
|
|
1247
|
+
*
|
|
1248
|
+
* ### ⚙️ Core Purpose
|
|
1249
|
+
* - 🔹 Verify the value is an array with a `length` of 3.
|
|
1250
|
+
* - 🔹 Ensure every element is a number within the range [0, 255].
|
|
1251
|
+
* - 🔹 Provide a **TypeScript type guard** (`TRGB`) for safe tuple access.
|
|
1252
|
+
*
|
|
1253
|
+
* ---
|
|
1254
|
+
*
|
|
1255
|
+
* ### 📘 Example Usage
|
|
1256
|
+
* ```ts
|
|
1257
|
+
* isRGBTuple([255, 0, 0]); // true (Red)
|
|
1258
|
+
* isRGBTuple([0, 256, 0]); // false (Out of range)
|
|
1259
|
+
* isRGBTuple([128, 128]); // false (Wrong length)
|
|
1260
|
+
* ```
|
|
1261
|
+
*/
|
|
1262
|
+
declare const isRGBTuple: TTypeGuard<TRGB>;
|
|
1263
|
+
/**
|
|
1264
|
+
* ## 📞 isPhoneNumber — Type Guard for International Formats
|
|
1265
|
+
*
|
|
1266
|
+
* Validates whether a string matches common phone number patterns, including
|
|
1267
|
+
* US, EU, and generic international formats.
|
|
1268
|
+
*
|
|
1269
|
+
* ---
|
|
1270
|
+
*
|
|
1271
|
+
* ### ⚙️ Core Purpose
|
|
1272
|
+
* - 🔹 Test strings against a set of optimized regular expressions.
|
|
1273
|
+
* - 🔹 Support multiple geographical formats (US/EU/Global).
|
|
1274
|
+
* - 🔹 Ensure the value is a non-empty string before testing.
|
|
1275
|
+
*
|
|
1276
|
+
* ---
|
|
1277
|
+
*
|
|
1278
|
+
* ### 📘 Example Usage
|
|
1279
|
+
* ```ts
|
|
1280
|
+
* isPhoneNumber('+1-202-555-0101'); // true
|
|
1281
|
+
* isPhoneNumber('06 12 34 56 78'); // true
|
|
1282
|
+
* isPhoneNumber('123-abc'); // false
|
|
1283
|
+
* ```
|
|
1284
|
+
*/
|
|
1285
|
+
declare const isPhoneNumber: TTypeGuard<string>;
|
|
1286
|
+
/**
|
|
1287
|
+
* ## 📧 isEmail — Type Guard for Email Addresses
|
|
1288
|
+
*
|
|
1289
|
+
* Validates if a string conforms to a standard email address format using
|
|
1290
|
+
* a robust regular expression.
|
|
1291
|
+
*
|
|
1292
|
+
* ---
|
|
1293
|
+
*
|
|
1294
|
+
* ### ⚙️ Core Purpose
|
|
1295
|
+
* - 🔹 Verify the string contains a valid local part, '@' symbol, and domain.
|
|
1296
|
+
* - 🔹 Perform a high-speed check suitable for form validation or data cleaning.
|
|
1297
|
+
*
|
|
1298
|
+
* ---
|
|
1299
|
+
*
|
|
1300
|
+
* ### 📘 Example Usage
|
|
1301
|
+
* ```ts
|
|
1302
|
+
* isEmail('hello@world.com'); // true
|
|
1303
|
+
* isEmail('invalid-email@'); // false
|
|
1304
|
+
* isEmail(12345); // false
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
declare const isEmail: TTypeGuard<string>;
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* ## 🧩 isValidUrl — Type Guard for Absolute URLs
|
|
1311
|
+
*
|
|
1312
|
+
* Checks whether a given string is a valid absolute URL according to the
|
|
1313
|
+
* browser's `URL` constructor. Returns `true` if the string can be parsed
|
|
1314
|
+
* as a valid URL, otherwise `false`.
|
|
1315
|
+
*
|
|
1316
|
+
* ---
|
|
1317
|
+
*
|
|
1318
|
+
* ### ⚙️ Core Purpose
|
|
1319
|
+
* - 🔹 Ensures the string is non-empty and a valid URL.
|
|
1320
|
+
* - 🔹 Provides a **TypeScript type guard** (`url is string`) for safe narrowing.
|
|
1321
|
+
*
|
|
1322
|
+
* ---
|
|
1323
|
+
*
|
|
1324
|
+
* ### 📘 Example Usage
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* isValidUrl('https://example.com'); // true
|
|
1327
|
+
* isValidUrl('ftp://example.com'); // true
|
|
1328
|
+
* isValidUrl('not a url'); // false
|
|
1329
|
+
* isValidUrl(''); // false
|
|
1330
|
+
* ```
|
|
1331
|
+
*
|
|
1332
|
+
* ---
|
|
1333
|
+
*
|
|
1334
|
+
* @param url - The value to validate as a URL.
|
|
1335
|
+
* @returns `true` if `url` is a non-empty valid absolute URL string.
|
|
1336
|
+
*/
|
|
1337
|
+
declare const isAbsoluteUrl: TTypeGuard<TAbsoluteURL>;
|
|
1338
|
+
/**
|
|
1339
|
+
* ## 🏠 isInternalUrl — Type Guard for Same-Origin or Relative Links
|
|
1340
|
+
*
|
|
1341
|
+
* Checks if a value is a valid internal URL. A URL is considered "internal" if it
|
|
1342
|
+
* is a relative path (starts with `/`) or an absolute URL that matches the
|
|
1343
|
+
* current window's origin (same domain).
|
|
1344
|
+
*
|
|
1345
|
+
* ---
|
|
1346
|
+
*
|
|
1347
|
+
* ### ⚙️ Core Purpose
|
|
1348
|
+
* - 🔹 Distinguish between internal navigation and external outbound links.
|
|
1349
|
+
* - 🔹 Validate relative paths for client-side routing.
|
|
1350
|
+
* - 🔹 Ensure a URL belongs to the current application's hostname.
|
|
1351
|
+
*
|
|
1352
|
+
* ---
|
|
1353
|
+
*
|
|
1354
|
+
* ### 📘 Example Usage
|
|
1355
|
+
* ```ts
|
|
1356
|
+
* // Assuming current origin is 'https://myapp.com'
|
|
1357
|
+
* isInternalUrl('/dashboard'); // true
|
|
1358
|
+
* isInternalUrl('https://myapp.com'); // true
|
|
1359
|
+
* isInternalUrl('https://google.com'); // false
|
|
1360
|
+
* isInternalUrl('mailto:test@test.com'); // false
|
|
1361
|
+
* ```
|
|
1362
|
+
*
|
|
1363
|
+
* ---
|
|
1364
|
+
*
|
|
1365
|
+
* ### ⚠️ Environment Note
|
|
1366
|
+
* - This guard requires a **browser environment** (`window.location`).
|
|
1367
|
+
* - In SSR or Node.js environments, it will consistently return `false`.
|
|
1368
|
+
*
|
|
1369
|
+
* ---
|
|
1370
|
+
*
|
|
1371
|
+
* @param url - The value to validate as an internal link.
|
|
1372
|
+
* @returns `true` if `url` is a non-empty string belonging to the current origin.
|
|
1373
|
+
*/
|
|
1374
|
+
declare const isInternalUrl: TTypeGuard<TInternalUrl>;
|
|
1375
|
+
|
|
1376
|
+
/**
|
|
1377
|
+
* Checks if the value is a camelCase string.
|
|
1378
|
+
*
|
|
1379
|
+
* By default, this checks that:
|
|
1380
|
+
* - The string starts with a lowercase letter
|
|
1381
|
+
* - Only contains alphanumeric characters
|
|
1382
|
+
* - No separators like `_`, `-`, or spaces
|
|
1383
|
+
*
|
|
1384
|
+
* You can think of this in terms of the `TCamelCase` type:
|
|
1385
|
+
* ```ts
|
|
1386
|
+
* type Example = TCamelCase<'my-variable'>; // 'myVariable'
|
|
1387
|
+
* ```
|
|
1388
|
+
*
|
|
1389
|
+
* Optionally, camelCase strings may preserve consecutive uppercase letters
|
|
1390
|
+
* using `TCamelCaseOptions['preserveConsecutiveUppercase']`. For example:
|
|
1391
|
+
* ```ts
|
|
1392
|
+
* type Example1 = TCamelCase<'FOO-BAR'>; // 'fooBAR' if preserveConsecutiveUppercase = true
|
|
1393
|
+
* type Example2 = TCamelCase<'FOO-BAR', { preserveConsecutiveUppercase: false }>; // 'fooBar'
|
|
1394
|
+
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```ts
|
|
1398
|
+
* TypeGuardUtils.isCamelCase('myVariable'); // true
|
|
1399
|
+
* TypeGuardUtils.isCamelCase('myVariable2'); // true
|
|
1400
|
+
* TypeGuardUtils.isCamelCase('MyVariable'); // false (starts with uppercase)
|
|
1401
|
+
* TypeGuardUtils.isCamelCase('my_variable'); // false (contains underscore)
|
|
1402
|
+
* TypeGuardUtils.isCamelCase('fooBAR'); // true if preserveConsecutiveUppercase is considered
|
|
1403
|
+
* ```
|
|
1404
|
+
*/
|
|
1405
|
+
declare const isCamelCase: TTypeGuard<TCamelCase<string>>;
|
|
1406
|
+
declare const isSnakeCase: TTypeGuard<TSnakeCase<string>>;
|
|
1407
|
+
declare const isKebabCase: TTypeGuard<TKebabCase<string>>;
|
|
1408
|
+
declare const isJSONArrayString: TTypeGuard<TJSONArrayString>;
|
|
1409
|
+
declare const isJSONObjectString: TTypeGuard<TJSONObjectString>;
|
|
1410
|
+
declare const isHTMLString: TTypeGuard<string>;
|
|
1411
|
+
/**
|
|
1412
|
+
* Checks whether a string is a valid hexadecimal representation.
|
|
1413
|
+
*
|
|
1414
|
+
* A hexadecimal string consists of characters 0–9, a–f, or A–F,
|
|
1415
|
+
* and is often used for binary data encoding, color codes, cryptographic hashes, etc.
|
|
1416
|
+
*
|
|
1417
|
+
* Key points:
|
|
1418
|
+
* - The value must be a non-empty string.
|
|
1419
|
+
* - Only characters `[0-9a-fA-F]` are allowed.
|
|
1420
|
+
* - The length must be even, unless `expectedLength` is provided.
|
|
1421
|
+
* - If `expectedLength` is specified, the string must match that exact length.
|
|
1422
|
+
* - Returns a TypeScript type guard, so it narrows the type to `string` when used.
|
|
1423
|
+
*
|
|
1424
|
+
* Example usage:
|
|
1425
|
+
* ```ts
|
|
1426
|
+
* isHexString("0a1b2c"); // true
|
|
1427
|
+
* isHexString("0a1b2z"); // false (invalid character 'z')
|
|
1428
|
+
* isHexString("0a1b2c", 6); // true
|
|
1429
|
+
* isHexString("0a1b2c", 8); // false (length mismatch)
|
|
1430
|
+
* ```
|
|
1431
|
+
*
|
|
1432
|
+
* Use case:
|
|
1433
|
+
* - Validating inputs for cryptographic functions.
|
|
1434
|
+
* - Ensuring a string is a valid hex color code.
|
|
1435
|
+
* - Checking serialized binary data in hexadecimal format.
|
|
1436
|
+
*
|
|
1437
|
+
* @param value - The value to check.
|
|
1438
|
+
* @param expectedLength - Optional length the hex string must match exactly.
|
|
1439
|
+
* @returns `true` if `value` is a valid hexadecimal string; otherwise `false`.
|
|
1440
|
+
*
|
|
1441
|
+
* @typeParam T - N/A
|
|
1442
|
+
*/
|
|
1443
|
+
declare const isHexByteString: (expectedLength?: number) => TTypeGuard<THexByteString>;
|
|
1444
|
+
/**
|
|
1445
|
+
* Checks whether a string contains valid JSON.
|
|
1446
|
+
*
|
|
1447
|
+
* This type guard ensures that:
|
|
1448
|
+
* - The value is a non-empty string.
|
|
1449
|
+
* - The string can be parsed successfully using `JSON.parse()`.
|
|
1450
|
+
*
|
|
1451
|
+
* Key points:
|
|
1452
|
+
* - Returns a TypeScript type guard, narrowing the type to `string`.
|
|
1453
|
+
* - Invalid JSON or non-string values return `false`.
|
|
1454
|
+
* - Useful for validating dynamic input or API responses.
|
|
1455
|
+
*
|
|
1456
|
+
* Example usage:
|
|
1457
|
+
* ```ts
|
|
1458
|
+
* isJsonString('{"foo": 1}'); // true
|
|
1459
|
+
* isJsonString('["a", "b"]'); // true
|
|
1460
|
+
* isJsonString('not json'); // false
|
|
1461
|
+
* isJsonString(''); // false
|
|
1462
|
+
* ```
|
|
1463
|
+
*
|
|
1464
|
+
* Use case:
|
|
1465
|
+
* - Safely validate strings before parsing them as JSON.
|
|
1466
|
+
* - Guard input data in APIs, configuration files, or user inputs.
|
|
1467
|
+
*
|
|
1468
|
+
* @param value - The value to validate.
|
|
1469
|
+
* @returns `true` if `value` is a string containing valid JSON; otherwise `false`.
|
|
1470
|
+
*/
|
|
1471
|
+
declare const isJsonString: TTypeGuard<TJSONDataString>;
|
|
1472
|
+
|
|
1473
|
+
declare const CoreTypeGuards: {
|
|
1474
|
+
readonly isString: TTypeGuard<string>;
|
|
1475
|
+
readonly isNumber: TTypeGuard<number>;
|
|
1476
|
+
readonly isBoolean: TTypeGuard<boolean>;
|
|
1477
|
+
readonly isBigInt: TTypeGuard<bigint>;
|
|
1478
|
+
readonly isNil: TTypeGuard<null | undefined>;
|
|
1479
|
+
readonly isDefined: TTypeGuard<unknown>;
|
|
1480
|
+
readonly isInteger: TTypeGuard<number>;
|
|
1481
|
+
readonly isNonEmptyString: TTypeGuard<string>;
|
|
1482
|
+
readonly isSymbol: TTypeGuard<symbol>;
|
|
1483
|
+
readonly isPrimitive: (value: unknown) => value is string | number | boolean;
|
|
1484
|
+
readonly isNull: TTypeGuard<null>;
|
|
1485
|
+
readonly isFunction: TTypeGuard<TAnyFunction>;
|
|
1486
|
+
readonly isObject: TTypeGuard<object>;
|
|
1487
|
+
readonly isArray: TTypeGuard<unknown[]>;
|
|
1488
|
+
readonly isMap: TTypeGuard<Map<unknown, unknown>>;
|
|
1489
|
+
readonly isSet: TTypeGuard<Set<unknown>>;
|
|
1490
|
+
readonly isWeakMap: TTypeGuard<WeakMap<object, unknown>>;
|
|
1491
|
+
readonly isWeakSet: TTypeGuard<WeakSet<object>>;
|
|
1492
|
+
readonly isUndefined: TTypeGuard<undefined>;
|
|
1493
|
+
readonly isInstanceOf: typeof isInstanceOf;
|
|
1494
|
+
};
|
|
1495
|
+
declare const FormatTypeGuards: {
|
|
1496
|
+
readonly isEmail: TTypeGuard<string>;
|
|
1497
|
+
readonly isPhone: TTypeGuard<string>;
|
|
1498
|
+
readonly isUrlAbsolute: TTypeGuard<TAbsoluteURL>;
|
|
1499
|
+
readonly isUrlInternal: TTypeGuard<TInternalUrl>;
|
|
1500
|
+
readonly isJsonString: TTypeGuard<TJSONDataString>;
|
|
1501
|
+
readonly isHTMLString: TTypeGuard<string>;
|
|
1502
|
+
readonly isCamelCase: TTypeGuard<string>;
|
|
1503
|
+
readonly isSnakeCase: TTypeGuard<string>;
|
|
1504
|
+
readonly isKebabCase: TTypeGuard<string>;
|
|
1505
|
+
readonly isHexByteString: (expectedLength?: number) => TTypeGuard<THexByteString>;
|
|
1506
|
+
readonly isJSONObjectString: TTypeGuard<TJSONObjectString>;
|
|
1507
|
+
readonly isJSONArrayString: TTypeGuard<TJSONArrayString>;
|
|
1508
|
+
readonly isRGBTuple: TTypeGuard<TRGB>;
|
|
1509
|
+
readonly isBufferLikeObject: TTypeGuard<TBufferLikeObject>;
|
|
1510
|
+
};
|
|
1511
|
+
declare const CollectionTypeGuards: {
|
|
1512
|
+
readonly isArrayOf: <T>(typeGuard: TTypeGuard<T>, value: unknown) => value is T[];
|
|
1513
|
+
readonly isRecordOf: <V>(value: unknown, typeGuard: TTypeGuard<V>) => value is Record<string, V>;
|
|
1514
|
+
readonly isKeyOfObject: <T extends object>(obj: T) => TTypeGuard<keyof T>;
|
|
1515
|
+
readonly isKeyInObject: <K extends PropertyKey>(key: K) => (obj: unknown) => obj is Record<K, unknown>;
|
|
1516
|
+
readonly isKeyOfArray: <T extends readonly (string | number | symbol)[]>(keys: T) => TTypeGuard<T[number]>;
|
|
1517
|
+
readonly isInArray: <T>(target: readonly T[]) => TTypeGuard<T | undefined>;
|
|
1518
|
+
readonly hasKeys: <T extends object>(requiredKeys: (keyof T)[]) => ((value: unknown) => value is T);
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* Validates if a property is a standard DOM/SVG attribute or event handler.
|
|
1523
|
+
* Memoized to ensure O(1) lookups after the first check.
|
|
1524
|
+
*/
|
|
1525
|
+
declare const isPropValid: (arg: string) => boolean;
|
|
1526
|
+
/**
|
|
1527
|
+
* Type guard to check if a value is a valid DOM property string.
|
|
1528
|
+
*/
|
|
1529
|
+
declare const isDOMPropKey: TTypeGuard<string>;
|
|
1530
|
+
/**
|
|
1531
|
+
* Checks if a key-value entry represents a valid DOM property for a specific element.
|
|
1532
|
+
*/
|
|
1533
|
+
declare const isDOMEntry: <TElement extends ElementType>(entry: [PropertyKey, unknown]) => entry is [Extract<keyof ComponentPropsWithoutRef<TElement>, string>, unknown];
|
|
1534
|
+
|
|
1535
|
+
/**
|
|
1536
|
+
* ## 🌳 isValidReactNode — Type Guard for all Renderable Content
|
|
1537
|
+
*
|
|
1538
|
+
* Validates if a value is a valid `ReactNode` (anything React can render).
|
|
1539
|
+
* This includes primitives, JSX elements, Portals, and recursive arrays of nodes.
|
|
1540
|
+
*/
|
|
1541
|
+
declare const isValidReactNode: TTypeGuard<ReactNode>;
|
|
1542
|
+
/**
|
|
1543
|
+
* ## 🌳 isReactElement — Type Guard for JSX Elements
|
|
1544
|
+
*
|
|
1545
|
+
* Validates if a value is a `ReactElement` (JSX).
|
|
1546
|
+
* Uses React's internal security checks to ensure the object is a legitimate element.
|
|
1547
|
+
*/
|
|
1548
|
+
declare const isReactElement: TTypeGuard<ReactElement>;
|
|
1549
|
+
/**
|
|
1550
|
+
* ## 🌳 isFragment — Type Guard for React Fragments
|
|
1551
|
+
*
|
|
1552
|
+
* Narrow check to determine if a React Element is specifically a `<React.Fragment>`.
|
|
1553
|
+
*/
|
|
1554
|
+
declare const isFragment: TTypeGuard<ReactElement>;
|
|
1555
|
+
/**
|
|
1556
|
+
* ## 🌳 hasOnClick — Type Guard for Interactive Elements
|
|
1557
|
+
*
|
|
1558
|
+
* Checks if a React Element has a valid `onClick` function in its props.
|
|
1559
|
+
* Useful for safely injecting behavior during `React.cloneElement`.
|
|
1560
|
+
*
|
|
1561
|
+
* ---
|
|
1562
|
+
* ### 📘 Example Usage
|
|
1563
|
+
* ```ts
|
|
1564
|
+
* if (hasOnClick(child)) {
|
|
1565
|
+
* return React.cloneElement(child, {
|
|
1566
|
+
* onClick: (e) => { console.log('Clicked!'); child.props.onClick(e); }
|
|
1567
|
+
* });
|
|
1568
|
+
* }
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
declare const hasOnClick: TTypeGuard<ReactElement<{
|
|
1572
|
+
onClick?: (e: MouseEvent<HTMLElement>) => void;
|
|
1573
|
+
}>>;
|
|
1574
|
+
/**
|
|
1575
|
+
* ## 🌳 isElementLike — Type Guard for Duck-Typed Elements
|
|
1576
|
+
*
|
|
1577
|
+
* Checks if an object "looks like" a React element (has type and props).
|
|
1578
|
+
* Useful for processing JSON-serialized components or objects from other environments.
|
|
1579
|
+
*/
|
|
1580
|
+
declare const isElementLike: TTypeGuard<TElementLike>;
|
|
1581
|
+
/**
|
|
1582
|
+
* ## 🌳 isElementOfType — Type Guard for Specific HTML Tags
|
|
1583
|
+
*
|
|
1584
|
+
* Validates if an element-like object matches a specific set of allowed HTML tags.
|
|
1585
|
+
*
|
|
1586
|
+
* @param allowedTypes - An array or string of tags to validate against (e.g., 'div' or ['a', 'button']).
|
|
1587
|
+
*/
|
|
1588
|
+
declare const isElementOfType: <T extends THTMLTags>(element: unknown, allowedTypes: THTMLTags) => element is {
|
|
1589
|
+
type: THTMLTags;
|
|
1590
|
+
props: object;
|
|
1591
|
+
};
|
|
1592
|
+
/**
|
|
1593
|
+
* ## 🌳 hasNameMetadata — Type Guard for Named Components
|
|
1594
|
+
*
|
|
1595
|
+
* Checks if a React component type has identifying metadata like `displayName` or `name`.
|
|
1596
|
+
* Essential for debugging utilities or logging component names.
|
|
1597
|
+
*/
|
|
1598
|
+
declare const hasNameMetadata: (type: unknown) => type is TNamedComponent;
|
|
1599
|
+
|
|
1600
|
+
/**
|
|
1601
|
+
* ## 🧩 isRef — Type Guard for React Refs
|
|
1602
|
+
*
|
|
1603
|
+
* Validates if a value is a valid React Ref, covering both **Functional (Callback) Refs**
|
|
1604
|
+
* and **Object Refs** (created via `useRef` or `createRef`).
|
|
1605
|
+
*
|
|
1606
|
+
* ---
|
|
1607
|
+
*
|
|
1608
|
+
* ### 📘 Example Usage
|
|
1609
|
+
* ```ts
|
|
1610
|
+
* isRef((el) => { console.log(el) }); // true (Callback Ref)
|
|
1611
|
+
* isRef({ current: document.createElement('div') }); // true (Object Ref)
|
|
1612
|
+
* ```
|
|
1613
|
+
*
|
|
1614
|
+
* @template T - The type of the element or value being referenced.
|
|
1615
|
+
*/
|
|
1616
|
+
declare const isRef: <T>(value: unknown) => value is Ref<T>;
|
|
1617
|
+
/**
|
|
1618
|
+
* ## 🧩 isRefObject — Type Guard for Persistent Ref Objects
|
|
1619
|
+
*
|
|
1620
|
+
* Specifically checks if a value is a `RefObject` (an object containing a `.current` property).
|
|
1621
|
+
* This effectively narrows the type away from Callback Refs.
|
|
1622
|
+
*
|
|
1623
|
+
* ---
|
|
1624
|
+
*
|
|
1625
|
+
* ### 📘 Example Usage
|
|
1626
|
+
* ```ts
|
|
1627
|
+
* const myRef = useRef(null);
|
|
1628
|
+
* if (isRefObject(myRef)) {
|
|
1629
|
+
* // ✅ Safely access myRef.current
|
|
1630
|
+
* }
|
|
1631
|
+
* ```
|
|
1632
|
+
*/
|
|
1633
|
+
declare const isRefObject: <T>(ref: Ref<T>) => ref is RefObject<T | null>;
|
|
1634
|
+
/**
|
|
1635
|
+
* ## 🧩 isPromise — Type Guard for Async Thenables
|
|
1636
|
+
*
|
|
1637
|
+
* Checks if a value is a `Promise` or a "Thenable" object by validating
|
|
1638
|
+
* the existence of a `.then()` method.
|
|
1639
|
+
*
|
|
1640
|
+
* ---
|
|
1641
|
+
*
|
|
1642
|
+
* ### 📘 Example Usage
|
|
1643
|
+
* ```ts
|
|
1644
|
+
* if (isPromise(data)) {
|
|
1645
|
+
* data.then((res) => console.log(res));
|
|
1646
|
+
* }
|
|
1647
|
+
* ```
|
|
1648
|
+
*/
|
|
1649
|
+
declare const isPromise: <T>(value: unknown) => value is Promise<T>;
|
|
1650
|
+
/**
|
|
1651
|
+
* ## 🧩 isReactPortal — Type Guard for Portals
|
|
1652
|
+
*
|
|
1653
|
+
* Checks if a value is a `ReactPortal` created via `ReactDOM.createPortal`.
|
|
1654
|
+
* Validates the existence of the internal `containerInfo` property.
|
|
1655
|
+
*/
|
|
1656
|
+
declare const isReactPortal: TTypeGuard<ReactPortal>;
|
|
1657
|
+
/**
|
|
1658
|
+
* ## 🧩 hasChildren — Type Guard for Prop Objects with Children
|
|
1659
|
+
*
|
|
1660
|
+
* Validates if an object contains a defined `children` property.
|
|
1661
|
+
* Useful for verifying props in HOCs or wrapper components.
|
|
1662
|
+
*/
|
|
1663
|
+
declare const hasChildren: (value: unknown) => value is {
|
|
1664
|
+
children: ReactNode;
|
|
1665
|
+
};
|
|
1666
|
+
/**
|
|
1667
|
+
* ## 🧩 isComponentType — Type Guard for React Components
|
|
1668
|
+
*
|
|
1669
|
+
* Determines if a value is a valid React Component (Function Component or Class Component).
|
|
1670
|
+
* For classes, it validates the existence of a `render` method on the prototype.
|
|
1671
|
+
*/
|
|
1672
|
+
declare const isComponentType: TTypeGuard<ComponentType<unknown>>;
|
|
1673
|
+
/**
|
|
1674
|
+
* ## 🧩 isForwardRef — Type Guard for ForwardRef Components
|
|
1675
|
+
*
|
|
1676
|
+
* Validates if a component is wrapped in `React.forwardRef` by checking
|
|
1677
|
+
* the internal `$$typeof` symbol.
|
|
1678
|
+
*/
|
|
1679
|
+
declare const isForwardRef: TTypeGuard<ForwardRefExoticComponent<object>>;
|
|
1680
|
+
|
|
1681
|
+
declare const ReactTypeGuards: {
|
|
1682
|
+
readonly isRef: <T>(value: unknown) => value is react.Ref<T>;
|
|
1683
|
+
readonly isRefObject: <T>(ref: react.Ref<T>) => ref is react.RefObject<T | null>;
|
|
1684
|
+
readonly isPromise: <T>(value: unknown) => value is Promise<T>;
|
|
1685
|
+
readonly isReactPortal: TTypeGuard<react.ReactPortal>;
|
|
1686
|
+
readonly hasChildren: (value: unknown) => value is {
|
|
1687
|
+
children: react.ReactNode;
|
|
1688
|
+
};
|
|
1689
|
+
readonly isComponentType: TTypeGuard<react.ComponentType<unknown>>;
|
|
1690
|
+
readonly isForwardRef: TTypeGuard<react.ForwardRefExoticComponent<object>>;
|
|
1691
|
+
readonly isValidReactNode: TTypeGuard<react.ReactNode>;
|
|
1692
|
+
readonly isReactElement: TTypeGuard<react.ReactElement<unknown, string | react.JSXElementConstructor<any>>>;
|
|
1693
|
+
readonly isFragment: TTypeGuard<react.ReactElement<unknown, string | react.JSXElementConstructor<any>>>;
|
|
1694
|
+
readonly hasOnClick: TTypeGuard<react.ReactElement<{
|
|
1695
|
+
onClick?: (e: react.MouseEvent<HTMLElement>) => void;
|
|
1696
|
+
}, string | react.JSXElementConstructor<any>>>;
|
|
1697
|
+
readonly isElementLike: TTypeGuard<TElementLike>;
|
|
1698
|
+
readonly isElementOfType: <T extends THTMLTags>(element: unknown, allowedTypes: THTMLTags) => element is {
|
|
1699
|
+
type: THTMLTags;
|
|
1700
|
+
props: object;
|
|
1701
|
+
};
|
|
1702
|
+
readonly hasNameMetadata: (type: unknown) => type is TNamedComponent;
|
|
1703
|
+
readonly isDOMPropKey: TTypeGuard<string>;
|
|
1704
|
+
readonly isDOMEntry: <TElement extends react.ElementType>(entry: [PropertyKey, unknown]) => entry is [Extract<keyof react.ComponentPropsWithoutRef<TElement>, string>, unknown];
|
|
1705
|
+
readonly isPropValid: (arg: string) => boolean;
|
|
1706
|
+
};
|
|
1707
|
+
|
|
1708
|
+
declare const assertIsNumber: TAssert<number>;
|
|
1709
|
+
declare const assertIsInteger: TAssert<number>;
|
|
1710
|
+
declare const assertIsString: TAssert<string>;
|
|
1711
|
+
declare const assertIsNonEmptyString: TAssert<string>;
|
|
1712
|
+
declare const assertIsBoolean: TAssert<boolean>;
|
|
1713
|
+
declare const assertIsBigInt: TAssert<bigint>;
|
|
1714
|
+
declare const assertIsSymbol: TAssert<symbol>;
|
|
1715
|
+
declare const assertIsNull: TAssert<null>;
|
|
1716
|
+
declare const assertIsUndefined: TAssert<undefined>;
|
|
1717
|
+
declare const assertIsDefined: TAssert<NonNullable<unknown>>;
|
|
1718
|
+
declare const assertIsNil: TAssert<null | undefined>;
|
|
1719
|
+
declare const assertIsFunction: TAssert<TAnyFunction>;
|
|
1720
|
+
declare const assertObject: TAssert<object>;
|
|
1721
|
+
declare const assertIsArray: TAssert<unknown[]>;
|
|
1722
|
+
declare const assertIsMap: TAssert<Map<unknown, unknown>>;
|
|
1723
|
+
declare const assertIsSet: TAssert<Set<unknown>>;
|
|
1724
|
+
declare const assertIsWeakMap: TAssert<WeakMap<object, unknown>>;
|
|
1725
|
+
declare const assertIsWeakSet: TAssert<WeakSet<object>>;
|
|
1726
|
+
declare const assertIsCamelCase: TAssert<string>;
|
|
1727
|
+
declare const assertIsBufferLikeObject: TAssert<TBufferLikeObject>;
|
|
1728
|
+
declare const assertIsJSONArrayString: TAssert<TJSONArrayString>;
|
|
1729
|
+
declare const assertIsJSONObjectString: TAssert<TJSONObjectString>;
|
|
1730
|
+
declare const assertIsJsonString: TAssert<TJSONDataString>;
|
|
1731
|
+
declare const assertIsAbsoluteUrl: TAssert<TAbsoluteURL>;
|
|
1732
|
+
declare const assertIsInternalUrl: TAssert<TInternalUrl>;
|
|
1733
|
+
declare const assertIsRGBTuple: TAssert<TRGB>;
|
|
1734
|
+
declare const AssertionUtils: {
|
|
1735
|
+
readonly assertValue: <T>(value: unknown, typeGuard: TTypeGuard<T>, message?: string) => asserts value is T;
|
|
1736
|
+
readonly makeAssert: <T>(guard: TTypeGuard<T>, _key: string) => TAssert<T>;
|
|
1737
|
+
readonly assertIsNumber: TAssert<number>;
|
|
1738
|
+
readonly assertIsInteger: TAssert<number>;
|
|
1739
|
+
readonly assertIsString: TAssert<string>;
|
|
1740
|
+
readonly assertIsNonEmptyString: TAssert<string>;
|
|
1741
|
+
readonly assertIsBoolean: TAssert<boolean>;
|
|
1742
|
+
readonly assertIsBigInt: TAssert<bigint>;
|
|
1743
|
+
readonly assertIsSymbol: TAssert<symbol>;
|
|
1744
|
+
readonly assertIsNull: TAssert<null>;
|
|
1745
|
+
readonly assertIsUndefined: TAssert<undefined>;
|
|
1746
|
+
readonly assertIsDefined: TAssert<{}>;
|
|
1747
|
+
readonly assertIsNil: TAssert<null | undefined>;
|
|
1748
|
+
readonly assertIsFunction: TAssert<TAnyFunction>;
|
|
1749
|
+
readonly assertObject: TAssert<object>;
|
|
1750
|
+
readonly assertIsArray: TAssert<unknown[]>;
|
|
1751
|
+
readonly assertIsMap: TAssert<Map<unknown, unknown>>;
|
|
1752
|
+
readonly assertIsSet: TAssert<Set<unknown>>;
|
|
1753
|
+
readonly assertIsWeakMap: TAssert<WeakMap<object, unknown>>;
|
|
1754
|
+
readonly assertIsWeakSet: TAssert<WeakSet<object>>;
|
|
1755
|
+
readonly assertIsCamelCase: TAssert<string>;
|
|
1756
|
+
readonly assertIsBufferLikeObject: TAssert<TBufferLikeObject>;
|
|
1757
|
+
readonly assertIsJSONArrayString: TAssert<TJSONArrayString>;
|
|
1758
|
+
readonly assertIsJSONObjectString: TAssert<TJSONObjectString>;
|
|
1759
|
+
readonly assertIsJsonString: TAssert<TJSONDataString>;
|
|
1760
|
+
readonly assertIsAbsoluteUrl: TAssert<TAbsoluteURL>;
|
|
1761
|
+
readonly assertIsInternalUrl: TAssert<TInternalUrl>;
|
|
1762
|
+
readonly assertIsRGBTuple: TAssert<TRGB>;
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1765
|
+
/**
|
|
1766
|
+
* ## 🔠 capitalizeString — Capitalize First Letter
|
|
1767
|
+
*
|
|
1768
|
+
* Converts the first character of a string to uppercase while preserving
|
|
1769
|
+
* the rest of the string.
|
|
1770
|
+
*
|
|
1771
|
+
* This utility also preserves **TypeScript literal inference**
|
|
1772
|
+
* using the built-in `Capitalize<T>` type.
|
|
1773
|
+
*
|
|
1774
|
+
* ---
|
|
1775
|
+
*
|
|
1776
|
+
* ### Example
|
|
1777
|
+
*
|
|
1778
|
+
* ```ts
|
|
1779
|
+
* capitalizeString('hello'); // "Hello"
|
|
1780
|
+
* capitalizeString('userName'); // "UserName"
|
|
1781
|
+
* ```
|
|
1782
|
+
*
|
|
1783
|
+
* @param str - String to capitalize
|
|
1784
|
+
* @returns String with first letter capitalized
|
|
1785
|
+
*/
|
|
1786
|
+
declare const capitalizeString: <S extends string>(str: S) => Capitalize<S>;
|
|
1787
|
+
/**
|
|
1788
|
+
* ## 🐪 toCamelCase — Convert String to camelCase
|
|
1789
|
+
*
|
|
1790
|
+
* Converts a string from various formats (`snake_case`, `kebab-case`,
|
|
1791
|
+
* space-separated, etc.) into **camelCase**.
|
|
1792
|
+
*
|
|
1793
|
+
* This utility:
|
|
1794
|
+
* - Normalizes separators (`-`, `_`, spaces)
|
|
1795
|
+
* - Converts word boundaries to camel casing
|
|
1796
|
+
* - Returns an empty string if the value is invalid
|
|
1797
|
+
*
|
|
1798
|
+
* ---
|
|
1799
|
+
*
|
|
1800
|
+
* ### Example
|
|
1801
|
+
*
|
|
1802
|
+
* ```ts
|
|
1803
|
+
* toCamelCase('hello-world'); // "helloWorld"
|
|
1804
|
+
* toCamelCase('user_name'); // "userName"
|
|
1805
|
+
* toCamelCase('Hello World'); // "helloWorld"
|
|
1806
|
+
* ```
|
|
1807
|
+
*
|
|
1808
|
+
* @param value - String to transform
|
|
1809
|
+
*/
|
|
1810
|
+
declare const toCamelCase: <T extends TCamelCase<string>>(value: T | string) => TCamelCase<T | string>;
|
|
1811
|
+
/**
|
|
1812
|
+
* ## 🧵 toKebabCase — Convert String to kebab-case
|
|
1813
|
+
*
|
|
1814
|
+
* Converts a string into **kebab-case**, commonly used for
|
|
1815
|
+
* URLs, CSS class names, and HTML attributes.
|
|
1816
|
+
*
|
|
1817
|
+
* The function:
|
|
1818
|
+
* - Normalizes camelCase boundaries
|
|
1819
|
+
* - Splits words by separators
|
|
1820
|
+
* - Joins them using `-`
|
|
1821
|
+
*
|
|
1822
|
+
* ---
|
|
1823
|
+
*
|
|
1824
|
+
* ### Example
|
|
1825
|
+
*
|
|
1826
|
+
* ```ts
|
|
1827
|
+
* toKebabCase('helloWorld'); // "hello-world"
|
|
1828
|
+
* toKebabCase('User Name'); // "user-name"
|
|
1829
|
+
* toKebabCase('user_name'); // "user-name"
|
|
1830
|
+
* ```
|
|
1831
|
+
*
|
|
1832
|
+
* @param value - String to transform
|
|
1833
|
+
*/
|
|
1834
|
+
declare const toKebabCase: <T extends string>(value: T | string) => TKebabCase<T | string>;
|
|
1835
|
+
/**
|
|
1836
|
+
* ## 🐍 toSnakeCase — Convert String to snake_case
|
|
1837
|
+
*
|
|
1838
|
+
* Converts a string into **snake_case**, commonly used for
|
|
1839
|
+
* database fields, environment variables, and backend APIs.
|
|
1840
|
+
*
|
|
1841
|
+
* The function:
|
|
1842
|
+
* - Splits words by separators and camelCase boundaries
|
|
1843
|
+
* - Joins them using `_`
|
|
1844
|
+
*
|
|
1845
|
+
* ---
|
|
1846
|
+
*
|
|
1847
|
+
* ### Example
|
|
1848
|
+
*
|
|
1849
|
+
* ```ts
|
|
1850
|
+
* toSnakeCase('helloWorld'); // "hello_world"
|
|
1851
|
+
* toSnakeCase('User Name'); // "user_name"
|
|
1852
|
+
* toSnakeCase('user-name'); // "user_name"
|
|
1853
|
+
* ```
|
|
1854
|
+
*
|
|
1855
|
+
* @param value - String to transform
|
|
1856
|
+
*/
|
|
1857
|
+
declare const toSnakeCase: <T extends string>(value: T | string) => TSnakeCase<T | string>;
|
|
1858
|
+
|
|
1859
|
+
/**
|
|
1860
|
+
* ## 🔑 generateKeyMap — Create a Typed Key Transformation Map
|
|
1861
|
+
*
|
|
1862
|
+
* Generates an object mapping original keys to transformed string values
|
|
1863
|
+
* using an optional **prefix** and required **suffix**.
|
|
1864
|
+
*
|
|
1865
|
+
* This is useful when generating standardized property names such as
|
|
1866
|
+
* getter/setter names, CSS class maps, or API field mappings.
|
|
1867
|
+
*
|
|
1868
|
+
* ---
|
|
1869
|
+
*
|
|
1870
|
+
* ### ⚙️ Behavior
|
|
1871
|
+
* - Iterates through the provided `keys` array.
|
|
1872
|
+
* - Builds a new string for each key using:
|
|
1873
|
+
* - Optional `prefix`
|
|
1874
|
+
* - Capitalized original key
|
|
1875
|
+
* - Required `suffix`
|
|
1876
|
+
* - Returns a **fully typed mapping object** where:
|
|
1877
|
+
*
|
|
1878
|
+
* ```
|
|
1879
|
+
* key -> transformedValue
|
|
1880
|
+
* ```
|
|
1881
|
+
*
|
|
1882
|
+
* ---
|
|
1883
|
+
*
|
|
1884
|
+
* ### 📘 Example
|
|
1885
|
+
*
|
|
1886
|
+
* ```ts
|
|
1887
|
+
* const map = generateKeyMap({
|
|
1888
|
+
* keys: ['name', 'email'] as const,
|
|
1889
|
+
* prefix: 'get',
|
|
1890
|
+
* suffix: 'Value',
|
|
1891
|
+
* });
|
|
1892
|
+
*
|
|
1893
|
+
* // Result:
|
|
1894
|
+
* // {
|
|
1895
|
+
* // name: "getNameValue",
|
|
1896
|
+
* // email: "getEmailValue"
|
|
1897
|
+
* // }
|
|
1898
|
+
* ```
|
|
1899
|
+
*
|
|
1900
|
+
* ---
|
|
1901
|
+
*
|
|
1902
|
+
* @typeParam K - Keys to transform
|
|
1903
|
+
* @typeParam P - Optional prefix string
|
|
1904
|
+
* @typeParam S - Required suffix string
|
|
1905
|
+
*/
|
|
1906
|
+
declare const generateKeyMap: <K extends string, P extends string | undefined = undefined, S extends string = string>(data: {
|
|
1907
|
+
keys: readonly K[];
|
|
1908
|
+
prefix?: P;
|
|
1909
|
+
suffix: S;
|
|
1910
|
+
}) => Record<K, P extends string ? `${P}${Capitalize<K>}${S}` : `${K}${S}`>;
|
|
1911
|
+
/**
|
|
1912
|
+
* ## 🗂️ toKeyByField — Convert Array to Keyed Object
|
|
1913
|
+
*
|
|
1914
|
+
* Converts an array of objects into a **record keyed by a specific field**.
|
|
1915
|
+
*
|
|
1916
|
+
* The specified key field becomes the **object key**, and the remaining
|
|
1917
|
+
* properties are preserved as the value.
|
|
1918
|
+
*
|
|
1919
|
+
* This is useful for quickly creating lookup tables from API responses
|
|
1920
|
+
* or normalized datasets.
|
|
1921
|
+
*
|
|
1922
|
+
* ---
|
|
1923
|
+
*
|
|
1924
|
+
* ### 📘 Example
|
|
1925
|
+
*
|
|
1926
|
+
* ```ts
|
|
1927
|
+
* const users = [
|
|
1928
|
+
* { id: 1, name: 'Alice' },
|
|
1929
|
+
* { id: 2, name: 'Bob' },
|
|
1930
|
+
* ];
|
|
1931
|
+
*
|
|
1932
|
+
* const map = toKeyByField(users, 'id');
|
|
1933
|
+
*
|
|
1934
|
+
* // Result:
|
|
1935
|
+
* // {
|
|
1936
|
+
* // 1: { name: 'Alice' },
|
|
1937
|
+
* // 2: { name: 'Bob' }
|
|
1938
|
+
* // }
|
|
1939
|
+
* ```
|
|
1940
|
+
*
|
|
1941
|
+
* ---
|
|
1942
|
+
*
|
|
1943
|
+
* @param rows - Array of objects to transform
|
|
1944
|
+
* @param keyField - Property used as the object key
|
|
1945
|
+
*/
|
|
1946
|
+
declare const toKeyByField: <RowType extends Record<Key, string | number | symbol>, Key extends keyof RowType>(rows: RowType[], keyField: Key) => Record<RowType[Key], Omit<RowType, Key>>;
|
|
1947
|
+
/**
|
|
1948
|
+
* ## 🔠 capitalizeArray — Capitalize All Strings in an Array
|
|
1949
|
+
*
|
|
1950
|
+
* Transforms every string in an array so that the **first letter is capitalized**.
|
|
1951
|
+
*
|
|
1952
|
+
* Uses the `capitalizeString` utility internally and preserves the
|
|
1953
|
+
* literal type relationship using `Capitalize<T>`.
|
|
1954
|
+
*
|
|
1955
|
+
* ---
|
|
1956
|
+
*
|
|
1957
|
+
* ### 📘 Example
|
|
1958
|
+
*
|
|
1959
|
+
* ```ts
|
|
1960
|
+
* capitalizeArray(['name', 'email']);
|
|
1961
|
+
*
|
|
1962
|
+
* // Result:
|
|
1963
|
+
* // ['Name', 'Email']
|
|
1964
|
+
* ```
|
|
1965
|
+
*
|
|
1966
|
+
* ---
|
|
1967
|
+
*
|
|
1968
|
+
* @param arr - Array of strings to capitalize
|
|
1969
|
+
*/
|
|
1970
|
+
declare const capitalizeArray: <T extends string>(arr: readonly T[]) => Capitalize<T>[];
|
|
1971
|
+
/**
|
|
1972
|
+
* ## 🔠 capitalizedKeys — Get Capitalized Object Keys
|
|
1973
|
+
*
|
|
1974
|
+
* Extracts keys from an object and returns them as an array of
|
|
1975
|
+
* **capitalized strings**.
|
|
1976
|
+
*
|
|
1977
|
+
* Only keys that **start with a letter** are included.
|
|
1978
|
+
*
|
|
1979
|
+
* This is useful when generating UI labels, enum-like lists,
|
|
1980
|
+
* or metadata from object shapes.
|
|
1981
|
+
*
|
|
1982
|
+
* ---
|
|
1983
|
+
*
|
|
1984
|
+
* ### 📘 Example
|
|
1985
|
+
*
|
|
1986
|
+
* ```ts
|
|
1987
|
+
* const user = {
|
|
1988
|
+
* id: 1,
|
|
1989
|
+
* name: 'Alice',
|
|
1990
|
+
* };
|
|
1991
|
+
*
|
|
1992
|
+
* capitalizedKeys(user);
|
|
1993
|
+
*
|
|
1994
|
+
* // Result:
|
|
1995
|
+
* // ['Id', 'Name']
|
|
1996
|
+
* ```
|
|
1997
|
+
*
|
|
1998
|
+
* ---
|
|
1999
|
+
*
|
|
2000
|
+
* @param obj - Object whose keys should be capitalized
|
|
2001
|
+
*/
|
|
2002
|
+
declare const capitalizedKeys: <T extends Record<string, unknown>>(obj: T) => Capitalize<keyof T & string>[];
|
|
2003
|
+
|
|
2004
|
+
declare const TransformersUtils: {
|
|
2005
|
+
readonly capitalizedKeys: <T extends Record<string, unknown>>(obj: T) => Capitalize<keyof T & string>[];
|
|
2006
|
+
readonly capitalizeArray: <T extends string>(arr: readonly T[]) => Capitalize<T>[];
|
|
2007
|
+
readonly toKeyByField: <RowType extends Record<Key, string | number | symbol>, Key extends keyof RowType>(rows: RowType[], keyField: Key) => Record<RowType[Key], Omit<RowType, Key>>;
|
|
2008
|
+
readonly generateKeyMap: <K extends string, P extends string | undefined = undefined, S extends string = string>(data: {
|
|
2009
|
+
keys: readonly K[];
|
|
2010
|
+
prefix?: P;
|
|
2011
|
+
suffix: S;
|
|
2012
|
+
}) => Record<K, P extends string ? `${P}${Capitalize<K>}${S}` : `${K}${S}`>;
|
|
2013
|
+
readonly toSnakeCase: <T extends string>(value: T | string) => TSnakeCase<T | string>;
|
|
2014
|
+
readonly toKebabCase: <T extends string>(value: T | string) => TKebabCase<T | string>;
|
|
2015
|
+
readonly toCamelCase: <T extends TCamelCase<string>>(value: T | string) => TCamelCase<T | string>;
|
|
2016
|
+
readonly capitalizeString: <S extends string>(str: S) => Capitalize<S>;
|
|
2017
|
+
};
|
|
2018
|
+
|
|
2019
|
+
declare function highlight(text: string, colorCode?: keyof typeof ANSI_COLOR_CODES): string;
|
|
2020
|
+
/**
|
|
2021
|
+
* Safely serializes any value into a readable string.
|
|
2022
|
+
*
|
|
2023
|
+
* - Handles objects, BigInts, and circular structures gracefully.
|
|
2024
|
+
* - Pretty-prints JSON for readability.
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* ```ts
|
|
2028
|
+
* DebugUtils.serialize({ foo: 'bar' });
|
|
2029
|
+
* // => "{\n \"foo\": \"bar\"\n}"
|
|
2030
|
+
* ```
|
|
2031
|
+
*/
|
|
2032
|
+
declare const serialize: (data: unknown) => string;
|
|
2033
|
+
/**
|
|
2034
|
+
* UTIL LOCATION: DEBUG UTILS
|
|
2035
|
+
*
|
|
2036
|
+
*
|
|
2037
|
+
* Retrieves the caller's location (file, line, and column) from the stack trace.
|
|
2038
|
+
*
|
|
2039
|
+
* Useful for logging, debugging, and tracing where a function was called from.
|
|
2040
|
+
*
|
|
2041
|
+
* It works by inspecting `Error().stack` and extracting relevant frames.
|
|
2042
|
+
*
|
|
2043
|
+
* @param preferredIndex - The zero-based stack frame index to prioritize (default: 3).
|
|
2044
|
+
* @param fallbackIndex - The fallback frame index if the preferred frame doesn’t exist (default: 2).
|
|
2045
|
+
* @param topParent - If `true`, returns the top-most relevant stack frame in your code (skipping `node_modules`).
|
|
2046
|
+
* @param stripPathPrefix - If provided, removes this prefix (e.g., your project root path) from the returned string.
|
|
2047
|
+
*
|
|
2048
|
+
* @returns A string describing the caller’s location, e.g. `"src/utils/core/debug.ts:42:15"`.
|
|
2049
|
+
*
|
|
2050
|
+
* @example
|
|
2051
|
+
* ```ts
|
|
2052
|
+
* import { DebugUtils } from '@/utils/core/debug';
|
|
2053
|
+
*
|
|
2054
|
+
* function exampleFunction() {
|
|
2055
|
+
* console.log(DebugUtils.getCallerLocation());
|
|
2056
|
+
* }
|
|
2057
|
+
*
|
|
2058
|
+
* exampleFunction();
|
|
2059
|
+
* // Example output:
|
|
2060
|
+
* // "src/utils/core/debug.ts:12:5"
|
|
2061
|
+
* ```
|
|
2062
|
+
*
|
|
2063
|
+
* @example
|
|
2064
|
+
* ```ts
|
|
2065
|
+
* // Get the top-most relevant frame (ignoring node_modules)
|
|
2066
|
+
* console.log(DebugUtils.getCallerLocation(3, 2, true));
|
|
2067
|
+
* // Example output:
|
|
2068
|
+
* // "src/server/api/user.ts:88:17"
|
|
2069
|
+
* ```
|
|
2070
|
+
*
|
|
2071
|
+
* @example
|
|
2072
|
+
* ```ts
|
|
2073
|
+
* // Strip out the absolute path prefix for cleaner logs
|
|
2074
|
+
* console.log(DebugUtils.getCallerLocation(3, 2, false, process.cwd()));
|
|
2075
|
+
* // Example output:
|
|
2076
|
+
* // "/src/services/logger.ts:54:9"
|
|
2077
|
+
* ```
|
|
2078
|
+
*/
|
|
2079
|
+
declare const getCallerLocation: (options: TGetCallerLocationOptions) => string;
|
|
2080
|
+
/**
|
|
2081
|
+
* Logs messages to the console **only in development environment** unless overridden.
|
|
2082
|
+
* Supports standard log types ('log', 'warn', 'error', 'info', 'debug') as well as
|
|
2083
|
+
* table logging for structured data.
|
|
2084
|
+
*
|
|
2085
|
+
* @remarks
|
|
2086
|
+
* - If the first argument matches a log type in `LOG_TYPES`, it is treated as the type.
|
|
2087
|
+
* - Table logs are automatically formatted if the items contain a `current` array of objects.
|
|
2088
|
+
* - Each message is stringified if it is an object.
|
|
2089
|
+
* - Optional highlighters can be applied via `logTypeHighlighters`.
|
|
2090
|
+
*
|
|
2091
|
+
* @param options - Configuration options for this log call
|
|
2092
|
+
* @param options.enabled - Whether this log should be enabled (default: true)
|
|
2093
|
+
* @param options.overrideDev - Force logging even in production (default: false)
|
|
2094
|
+
* @param args - Messages to log. If the first item is a log type string, it is used as the type.
|
|
2095
|
+
*
|
|
2096
|
+
* @example
|
|
2097
|
+
* ```ts
|
|
2098
|
+
* logDev({}, 'info', 'Server started on port', 3000);
|
|
2099
|
+
*
|
|
2100
|
+
* logDev({ overrideDev: true }, 'error', new Error('Something failed'));
|
|
2101
|
+
*
|
|
2102
|
+
* logDev({}, 'table', { current: [{ key: 'task1', start: 0, end: 120 }] });
|
|
2103
|
+
* ```
|
|
2104
|
+
*
|
|
2105
|
+
*/
|
|
2106
|
+
declare const logDev: (options: TLogOptions, ...args: unknown[]) => void;
|
|
2107
|
+
|
|
2108
|
+
declare class DebugUtils {
|
|
2109
|
+
static readonly highlight: typeof highlight;
|
|
2110
|
+
static readonly serialize: (data: unknown) => string;
|
|
2111
|
+
static readonly getCallerLocation: (options: TGetCallerLocationOptions) => string;
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
/**
|
|
2115
|
+
* Interprets a keyboard event and returns semantic information about the user's intent.
|
|
2116
|
+
*
|
|
2117
|
+
* This utility analyzes a `KeyboardEvent` and classifies it into meaningful actions
|
|
2118
|
+
* such as copy, paste, clear, or typing, based on a configurable keyboard policy.
|
|
2119
|
+
*
|
|
2120
|
+
* It is framework-agnostic (works with native DOM or React keyboard events) and
|
|
2121
|
+
* performs **no side effects**. Consumers decide how to respond to the result.
|
|
2122
|
+
*
|
|
2123
|
+
* ### Features
|
|
2124
|
+
* - Detects copy and paste shortcuts across platforms (Mac / Windows).
|
|
2125
|
+
* - Supports configurable allowed keys and clear keys.
|
|
2126
|
+
* - Fully data-driven via `TKeyboardConfig`.
|
|
2127
|
+
* - Pure and easily unit-testable.
|
|
2128
|
+
*
|
|
2129
|
+
* ### Example
|
|
2130
|
+
* ```ts
|
|
2131
|
+
* const action = getKeyboardAction(event, {
|
|
2132
|
+
* allowedKeys: ['tab', 'enter'],
|
|
2133
|
+
* clearKeys: ['escape'],
|
|
2134
|
+
* });
|
|
2135
|
+
*
|
|
2136
|
+
* if (action.isPaste) {
|
|
2137
|
+
* updateWorkflow({ source: 'paste' });
|
|
2138
|
+
* }
|
|
2139
|
+
*
|
|
2140
|
+
* if (action.shouldBlockTyping) {
|
|
2141
|
+
* event.preventDefault();
|
|
2142
|
+
* }
|
|
2143
|
+
* ```
|
|
2144
|
+
*
|
|
2145
|
+
* ### Default Behavior
|
|
2146
|
+
* When no config is provided, the function uses `DEFAULT_KEYBOARD_CONFIG`,
|
|
2147
|
+
* which includes standard navigation keys, copy/paste shortcuts, and
|
|
2148
|
+
* backspace/delete as clear actions.
|
|
2149
|
+
*
|
|
2150
|
+
* @param event - The keyboard event to interpret (native or React keyboard event).
|
|
2151
|
+
* @param config - Optional configuration to customize allowed keys, shortcuts, and clear behavior.
|
|
2152
|
+
* @returns An object describing the interpreted keyboard action.
|
|
2153
|
+
*/
|
|
2154
|
+
declare function getKeyboardAction(event: KeyboardEvent, config?: TKeyboardConfig): TKeyboardActionResult;
|
|
2155
|
+
|
|
2156
|
+
/**
|
|
2157
|
+
* Preloads images with PRELOAD caching.
|
|
2158
|
+
*
|
|
2159
|
+
* This utility:
|
|
2160
|
+
* - Uses `Image.decode()` if supported by the browser for faster, async decoding.
|
|
2161
|
+
* - Falls back to `onload` / `onerror` events if `decode()` is not available.
|
|
2162
|
+
* - Skips URLs that are already cached in the LRU cache.
|
|
2163
|
+
*
|
|
2164
|
+
* This is useful for preloading images in a performant way, avoiding repeated network requests
|
|
2165
|
+
* and controlling memory usage with an LRU cache.
|
|
2166
|
+
*
|
|
2167
|
+
* @param urls - Array of image URLs to preload
|
|
2168
|
+
* @returns A promise that resolves when all images have been preloaded
|
|
2169
|
+
*
|
|
2170
|
+
* @example
|
|
2171
|
+
* ```ts
|
|
2172
|
+
* import { preloadImages } from './lib/network/images';
|
|
2173
|
+
*
|
|
2174
|
+
* const images = [
|
|
2175
|
+
* '/images/photo1.jpg',
|
|
2176
|
+
* '/images/photo2.jpg',
|
|
2177
|
+
* '/images/photo3.jpg',
|
|
2178
|
+
* ];
|
|
2179
|
+
*
|
|
2180
|
+
* // Preload images before rendering a gallery
|
|
2181
|
+
* await preloadImages(images);
|
|
2182
|
+
* console.log('All images are preloaded and cached!');
|
|
2183
|
+
* ```
|
|
2184
|
+
*/
|
|
2185
|
+
declare function preloadImages(urls: string | string[], options?: {
|
|
2186
|
+
fetchPriority?: HTMLImageElement['fetchPriority'];
|
|
2187
|
+
}): Promise<void>;
|
|
2188
|
+
/**
|
|
2189
|
+
* Normalizes a variety of image sources into a plain string URL.
|
|
2190
|
+
* @template T - The shape of the image object, defaulting to our base structure.
|
|
2191
|
+
*/
|
|
2192
|
+
declare function normalizeImageSrc<T extends TBaseImageObject>(src: string | T | {
|
|
2193
|
+
default: T;
|
|
2194
|
+
} | null | undefined): string;
|
|
2195
|
+
|
|
2196
|
+
declare const DomUtils: {
|
|
2197
|
+
readonly getKeyboardAction: typeof getKeyboardAction;
|
|
2198
|
+
readonly preloadImages: typeof preloadImages;
|
|
2199
|
+
readonly normalizeImageSrc: typeof normalizeImageSrc;
|
|
2200
|
+
};
|
|
2201
|
+
|
|
2202
|
+
type TWelfordState = {
|
|
2203
|
+
count: number;
|
|
2204
|
+
mean: number;
|
|
2205
|
+
squaredDeviationSum: number;
|
|
2206
|
+
};
|
|
2207
|
+
declare class ComputationUtils {
|
|
2208
|
+
private static toNum;
|
|
2209
|
+
static round(value: number, decimals?: number): number;
|
|
2210
|
+
/** forces a number to stay within a specific range */
|
|
2211
|
+
static clamp(val: number, min: number, max: number): number;
|
|
2212
|
+
static getPercentage(value: number | bigint, total: number | bigint, decimals?: number): number;
|
|
2213
|
+
static computeMean(arr: (number | bigint)[]): number;
|
|
2214
|
+
/**
|
|
2215
|
+
* Determines if a value is a statistical outlier based on standard deviations.
|
|
2216
|
+
* Useful for performance alerting (e.g., test duration spikes).
|
|
2217
|
+
*/
|
|
2218
|
+
static isAnomaly(value: number, mean: number, stdDev: number, threshold?: number): boolean;
|
|
2219
|
+
/**
|
|
2220
|
+
* Generates a pass/fail ratio as a human-readable percentage.
|
|
2221
|
+
* Leverages getPercentage for BigInt safety and consistent rounding.
|
|
2222
|
+
*/
|
|
2223
|
+
static computeRatio(achieved: number | bigint, total: number | bigint, decimals?: number): number;
|
|
2224
|
+
/**
|
|
2225
|
+
* Incrementally updates Welford's running mean and variance.
|
|
2226
|
+
*
|
|
2227
|
+
* High-level:
|
|
2228
|
+
* - Efficiently calculates running mean and variance without storing all samples.
|
|
2229
|
+
* - Perfect for streaming data like oracle price feeds.
|
|
2230
|
+
*
|
|
2231
|
+
* https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
|
|
2232
|
+
*
|
|
2233
|
+
* @param state - Previous Welford state, or undefined if this is the first sample
|
|
2234
|
+
* @param newValue - The new data point to incorporate
|
|
2235
|
+
* @returns Object containing:
|
|
2236
|
+
* - welford: updated state (count, mean, squaredDeviationSum)
|
|
2237
|
+
* - stdDev: current standard deviation based on updated state
|
|
2238
|
+
*/
|
|
2239
|
+
static welfordUpdate(state: TWelfordState | undefined, newValue: number): {
|
|
2240
|
+
welford: TWelfordState;
|
|
2241
|
+
stdDev: number;
|
|
2242
|
+
};
|
|
2243
|
+
static computeDelta(current: bigint, past: bigint): {
|
|
2244
|
+
netDelta: bigint;
|
|
2245
|
+
absDelta: bigint;
|
|
2246
|
+
};
|
|
2247
|
+
static computeDelta(current: number, past: number): {
|
|
2248
|
+
netDelta: number;
|
|
2249
|
+
absDelta: number;
|
|
2250
|
+
};
|
|
2251
|
+
static computePercentageChange(current: number | bigint, past: number | bigint, scale?: bigint): number;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
declare const hexToRGB: (hex: string) => TRGB;
|
|
2255
|
+
declare const validateRGB: (input: TRGB | string) => TRGB;
|
|
2256
|
+
declare const getLuminance: (rgb: TRGB | string) => number;
|
|
2257
|
+
/**
|
|
2258
|
+
* ## 🌗 isLumLessThan — Check if a Color’s Luminance is Below a Threshold
|
|
2259
|
+
*
|
|
2260
|
+
* Determines whether the luminance of a color (in RGB array or HEX format)
|
|
2261
|
+
* is less than the specified threshold. Uses `getLuminance()` internally.
|
|
2262
|
+
*
|
|
2263
|
+
* @param color - RGB tuple or HEX color string (e.g. `[255,255,255]` or `"#ffffff"`)
|
|
2264
|
+
* @param threshold - A number between 0 and 1 representing the luminance cutoff.
|
|
2265
|
+
* @returns `true` if the color’s luminance is less than the threshold.
|
|
2266
|
+
*
|
|
2267
|
+
* @example
|
|
2268
|
+
* ```ts
|
|
2269
|
+
* isLumLessThan('#000000', 0.2); // true
|
|
2270
|
+
* isLumLessThan([255,255,255], 0.2); // false
|
|
2271
|
+
* ```
|
|
2272
|
+
*/
|
|
2273
|
+
declare const isLumLessThan: (color: TRGB | string, threshold: number) => boolean;
|
|
2274
|
+
/**
|
|
2275
|
+
* ## 🌑 isDarkColor — Check if a Color is Perceptually Dark
|
|
2276
|
+
*
|
|
2277
|
+
* Determines whether a color is "dark" based on a standard WCAG-inspired
|
|
2278
|
+
* luminance threshold (0.179). Works with both HEX and RGB formats.
|
|
2279
|
+
*
|
|
2280
|
+
* @param color - RGB tuple or HEX color string.
|
|
2281
|
+
* @returns `true` if the color is considered dark.
|
|
2282
|
+
*
|
|
2283
|
+
* @example
|
|
2284
|
+
* ```ts
|
|
2285
|
+
* isDarkColor('#000000'); // true
|
|
2286
|
+
* isDarkColor('#ffffff'); // false
|
|
2287
|
+
* ```
|
|
2288
|
+
*/
|
|
2289
|
+
declare const isDarkColor: (color: TRGB | string) => boolean;
|
|
2290
|
+
/**
|
|
2291
|
+
* ## ☀️ isLumGreaterThan — Check if a Color’s Luminance Exceeds a Threshold
|
|
2292
|
+
*
|
|
2293
|
+
* Determines whether the luminance of a color is above the given threshold.
|
|
2294
|
+
*
|
|
2295
|
+
* @param color - RGB tuple or HEX color string.
|
|
2296
|
+
* @param threshold - A number between 0 and 1 representing the luminance cutoff.
|
|
2297
|
+
* @returns `true` if the color’s luminance is greater than the threshold.
|
|
2298
|
+
*
|
|
2299
|
+
* @example
|
|
2300
|
+
* ```ts
|
|
2301
|
+
* isLumGreaterThan('#ffffff', 0.2); // true
|
|
2302
|
+
* isLumGreaterThan('#222222', 0.2); // false
|
|
2303
|
+
* ```
|
|
2304
|
+
*/
|
|
2305
|
+
declare const isLumGreaterThan: (color: TRGB | string, threshold: number) => boolean;
|
|
2306
|
+
/**
|
|
2307
|
+
* ## 🎨 contrastTextColor — Returns an Accessible Text Color Based on Background
|
|
2308
|
+
*
|
|
2309
|
+
* Dynamically selects a readable text color (`black` or `white`) depending on
|
|
2310
|
+
* the background color’s luminance.
|
|
2311
|
+
*
|
|
2312
|
+
* The function can return:
|
|
2313
|
+
* - **Tailwind classes** (e.g. `'text-black'` / `'text-white'`)
|
|
2314
|
+
* - **CSS color values** (e.g. `'#000000'` / `'#ffffff'`)
|
|
2315
|
+
*
|
|
2316
|
+
* ---
|
|
2317
|
+
*
|
|
2318
|
+
* @param color - RGB tuple or HEX color string.
|
|
2319
|
+
* @param options - Optional configuration for return format and threshold.
|
|
2320
|
+
* @returns A string representing the contrasting text color (Tailwind or CSS).
|
|
2321
|
+
*
|
|
2322
|
+
* ---
|
|
2323
|
+
*
|
|
2324
|
+
* @example
|
|
2325
|
+
* ```ts
|
|
2326
|
+
* // Tailwind mode (default)
|
|
2327
|
+
* contrastTextColor('#000000');
|
|
2328
|
+
* // → 'text-white'
|
|
2329
|
+
*
|
|
2330
|
+
* // CSS mode
|
|
2331
|
+
* contrastTextColor('#ffffff', { mode: 'css' });
|
|
2332
|
+
* // → '#000000'
|
|
2333
|
+
*
|
|
2334
|
+
* // Custom threshold
|
|
2335
|
+
* contrastTextColor([120,120,120], { threshold: 0.2 });
|
|
2336
|
+
* // → 'text-white'
|
|
2337
|
+
* ```
|
|
2338
|
+
*/
|
|
2339
|
+
declare const contrastTextColor: (color: TRGB | string, options?: {
|
|
2340
|
+
mode?: "tailwind" | "css";
|
|
2341
|
+
threshold?: number;
|
|
2342
|
+
}) => string;
|
|
2343
|
+
/**
|
|
2344
|
+
* ## 🎨 hexToRGBShorthand — Convert Hex Color to RGB Array
|
|
2345
|
+
*
|
|
2346
|
+
* Converts a **hex color string** into an RGB array `[r, g, b]`.
|
|
2347
|
+
* Supports both **3-character shorthand** (e.g., `#abc`) and **6-character hex** (e.g., `#aabbcc`).
|
|
2348
|
+
*
|
|
2349
|
+
* ---
|
|
2350
|
+
*
|
|
2351
|
+
* ### ⚙️ Core Purpose
|
|
2352
|
+
* - Convert a user-friendly or CSS hex color into a numeric RGB array.
|
|
2353
|
+
* - Handles shorthand hex and expands it automatically.
|
|
2354
|
+
* - Returns `null` for invalid hex strings.
|
|
2355
|
+
*
|
|
2356
|
+
* ---
|
|
2357
|
+
*
|
|
2358
|
+
* ### 📘 Example Usage
|
|
2359
|
+
* ```ts
|
|
2360
|
+
* hexToRGBShorthand('#abc'); // [170, 187, 204]
|
|
2361
|
+
* hexToRGBShorthand('#aabbcc'); // [170, 187, 204]
|
|
2362
|
+
* hexToRGBShorthand('invalid'); // null
|
|
2363
|
+
* ```
|
|
2364
|
+
*
|
|
2365
|
+
* ---
|
|
2366
|
+
*
|
|
2367
|
+
* ### 📌 Notes
|
|
2368
|
+
* - Input must be a valid 3- or 6-character hex string (case-insensitive).
|
|
2369
|
+
* - Output is always a `[number, number, number]` array if valid.
|
|
2370
|
+
*/
|
|
2371
|
+
declare const hexToRGBShorthand: (hex: string) => [number, number, number] | null;
|
|
2372
|
+
/**
|
|
2373
|
+
* ## 🎨 interpolateColor — Linear Interpolation Between Two RGB Colors
|
|
2374
|
+
*
|
|
2375
|
+
* Interpolates between two RGB colors based on a `factor` and returns a **CSS rgb() string**.
|
|
2376
|
+
*
|
|
2377
|
+
* ---
|
|
2378
|
+
*
|
|
2379
|
+
* ### ⚙️ Core Purpose
|
|
2380
|
+
* - Blend two colors linearly using a numeric factor between `0` and `1`.
|
|
2381
|
+
* - `factor = 0` returns the `start` color.
|
|
2382
|
+
* - `factor = 1` returns the `end` color.
|
|
2383
|
+
* - Any value in-between returns the proportional mix.
|
|
2384
|
+
*
|
|
2385
|
+
* ---
|
|
2386
|
+
*
|
|
2387
|
+
* ### 📘 Example Usage
|
|
2388
|
+
* ```ts
|
|
2389
|
+
* interpolateColor(
|
|
2390
|
+
* { r: 255, g: 0, b: 0 },
|
|
2391
|
+
* { r: 0, g: 0, b: 255 },
|
|
2392
|
+
* 0.5
|
|
2393
|
+
* );
|
|
2394
|
+
* // → "rgb(128, 0, 128)"
|
|
2395
|
+
*
|
|
2396
|
+
* interpolateColor(
|
|
2397
|
+
* { r: 0, g: 255, b: 0 },
|
|
2398
|
+
* { r: 0, g: 0, b: 0 },
|
|
2399
|
+
* 0.25
|
|
2400
|
+
* );
|
|
2401
|
+
* // → "rgb(0, 191, 0)"
|
|
2402
|
+
* ```
|
|
2403
|
+
*
|
|
2404
|
+
* ---
|
|
2405
|
+
*
|
|
2406
|
+
* ### 📌 Notes
|
|
2407
|
+
* - `start` and `end` colors must have `r`, `g`, `b` values as numbers.
|
|
2408
|
+
* - `factor` should ideally be in `[0, 1]`, but values outside will extrapolate.
|
|
2409
|
+
* - Returns a **valid CSS rgb() string** ready to use in style properties.
|
|
2410
|
+
*/
|
|
2411
|
+
declare const interpolateColor: (start: {
|
|
2412
|
+
r: number;
|
|
2413
|
+
g: number;
|
|
2414
|
+
b: number;
|
|
2415
|
+
}, end: {
|
|
2416
|
+
r: number;
|
|
2417
|
+
g: number;
|
|
2418
|
+
b: number;
|
|
2419
|
+
}, factor: number) => TCssRGB;
|
|
2420
|
+
/**
|
|
2421
|
+
* Converts a hex color string to an HSL (Hue, Saturation, Lightness) object.
|
|
2422
|
+
*
|
|
2423
|
+
* @param hex - A hexadecimal color string (e.g., "#ff0000" or "ff0000")
|
|
2424
|
+
* @returns An object with:
|
|
2425
|
+
* - h: hue in degrees [0, 360)
|
|
2426
|
+
* - s: saturation [0, 1]
|
|
2427
|
+
* - l: lightness [0, 1]
|
|
2428
|
+
*
|
|
2429
|
+
* @example
|
|
2430
|
+
* hexToHSL("#ff0000") // { h: 0, s: 1, l: 0.5 }
|
|
2431
|
+
*/
|
|
2432
|
+
declare function hexToHSL(hex: string): {
|
|
2433
|
+
h: number;
|
|
2434
|
+
s: number;
|
|
2435
|
+
l: number;
|
|
2436
|
+
};
|
|
2437
|
+
/**
|
|
2438
|
+
* Converts a hexadecimal color string to a normalized RGB tuple.
|
|
2439
|
+
*
|
|
2440
|
+
* This function takes a standard hex color (like `#ff0000` or `ff0000`) and
|
|
2441
|
+
* converts it to an RGB representation where each channel is a decimal number
|
|
2442
|
+
* between 0 and 1 instead of 0–255. This format is commonly used in graphics
|
|
2443
|
+
* and WebGL contexts (like Three.js or shaders) that expect normalized RGB values.
|
|
2444
|
+
*
|
|
2445
|
+
* @param hex - A hexadecimal color string, either in 3-digit shorthand (`#f00`)
|
|
2446
|
+
* or 6-digit full form (`#ff0000`). The leading `#` is optional.
|
|
2447
|
+
*
|
|
2448
|
+
* @returns A tuple `[r, g, b]` where each component is a number between 0 and 1:
|
|
2449
|
+
* - `r` = red channel normalized (0–1)
|
|
2450
|
+
* - `g` = green channel normalized (0–1)
|
|
2451
|
+
* - `b` = blue channel normalized (0–1)
|
|
2452
|
+
*
|
|
2453
|
+
* @example
|
|
2454
|
+
* hexToNormalizedRGB("#ff0000"); // [1, 0, 0] → pure red
|
|
2455
|
+
* hexToNormalizedRGB("00ff00"); // [0, 1, 0] → pure green
|
|
2456
|
+
* hexToNormalizedRGB("#0000ff"); // [0, 0, 1] → pure blue
|
|
2457
|
+
*/
|
|
2458
|
+
declare const hexToNormalizedRGB: (hex: string) => [number, number, number];
|
|
2459
|
+
|
|
2460
|
+
declare const ColorUtils: {
|
|
2461
|
+
readonly hexToNormalizedRGB: (hex: string) => [number, number, number];
|
|
2462
|
+
readonly hexToHSL: typeof hexToHSL;
|
|
2463
|
+
readonly interpolateColor: (start: {
|
|
2464
|
+
r: number;
|
|
2465
|
+
g: number;
|
|
2466
|
+
b: number;
|
|
2467
|
+
}, end: {
|
|
2468
|
+
r: number;
|
|
2469
|
+
g: number;
|
|
2470
|
+
b: number;
|
|
2471
|
+
}, factor: number) => TCssRGB;
|
|
2472
|
+
readonly hexToRGBShorthand: (hex: string) => [number, number, number] | null;
|
|
2473
|
+
readonly contrastTextColor: (color: TRGB | string, options?: {
|
|
2474
|
+
mode?: "tailwind" | "css";
|
|
2475
|
+
threshold?: number;
|
|
2476
|
+
}) => string;
|
|
2477
|
+
readonly isLumGreaterThan: (color: TRGB | string, threshold: number) => boolean;
|
|
2478
|
+
readonly isDarkColor: (color: TRGB | string) => boolean;
|
|
2479
|
+
readonly isLumLessThan: (color: TRGB | string, threshold: number) => boolean;
|
|
2480
|
+
readonly getLuminance: (rgb: TRGB | string) => number;
|
|
2481
|
+
readonly validateRGB: (input: TRGB | string) => TRGB;
|
|
2482
|
+
readonly hexToRGB: (hex: string) => TRGB;
|
|
2483
|
+
};
|
|
2484
|
+
|
|
2485
|
+
/**
|
|
2486
|
+
* Normalize various URL inputs to a string.
|
|
2487
|
+
*
|
|
2488
|
+
* @param href - The input URL, which can be a string, URL instance, or object with pathname/query/hash.
|
|
2489
|
+
* @returns A normalized string URL.
|
|
2490
|
+
*
|
|
2491
|
+
* @example
|
|
2492
|
+
* LinkUtils.normalizeUrl('https://example.com/path?query=1#hash');
|
|
2493
|
+
* // 'https://example.com/path?query=1#hash'
|
|
2494
|
+
*
|
|
2495
|
+
* @example
|
|
2496
|
+
* LinkUtils.normalizeUrl({ pathname: '/path', query: { q: '1' }, hash: '#section' });
|
|
2497
|
+
* // '/path?q=1#section'
|
|
2498
|
+
*/
|
|
2499
|
+
declare function normalizeUrl(href?: string | URL | TGenericUrlObject | null): string;
|
|
2500
|
+
/**
|
|
2501
|
+
* ## 🧩 extractRelativePath — Extracts Relative Paths
|
|
2502
|
+
*
|
|
2503
|
+
* Extracts the relative path from an internal URL or absolute URL pointing
|
|
2504
|
+
* to the same origin. Ensures that the returned path always starts with `/`.
|
|
2505
|
+
*
|
|
2506
|
+
* ---
|
|
2507
|
+
*
|
|
2508
|
+
* ### ⚙️ Core Purpose
|
|
2509
|
+
* - 🔹 Converts internal absolute URLs to relative paths.
|
|
2510
|
+
* - 🔹 Preserves already relative paths.
|
|
2511
|
+
* - 🔹 Safely handles invalid or external URLs by returning `/`.
|
|
2512
|
+
*
|
|
2513
|
+
* ---
|
|
2514
|
+
*
|
|
2515
|
+
* ### 📘 Example Usage
|
|
2516
|
+
* ```ts
|
|
2517
|
+
* LinkUtils.extractRelativePath('/about');
|
|
2518
|
+
* // '/about'
|
|
2519
|
+
*
|
|
2520
|
+
* LinkUtils.extractRelativePath('https://example.com/about?query=1');
|
|
2521
|
+
* // '/about'
|
|
2522
|
+
*
|
|
2523
|
+
* LinkUtils.extractRelativePath('https://external.com/page');
|
|
2524
|
+
* // '/'
|
|
2525
|
+
* ```
|
|
2526
|
+
*
|
|
2527
|
+
* ---
|
|
2528
|
+
*
|
|
2529
|
+
* @param url - The input URL string or unknown value.
|
|
2530
|
+
* @returns A string representing the relative path, always starting with `/`.
|
|
2531
|
+
*/
|
|
2532
|
+
declare const extractRelativePath: (url?: unknown) => string;
|
|
2533
|
+
/**
|
|
2534
|
+
* Removes the hash fragment from a URL string while preserving path and query.
|
|
2535
|
+
*/
|
|
2536
|
+
declare const stripHash: (url?: string) => string;
|
|
2537
|
+
declare const handleInternalHashScroll: ({ event, href, behavior, block, }: THashScrollOptions) => boolean;
|
|
2538
|
+
|
|
2539
|
+
declare class LinkUtils {
|
|
2540
|
+
static readonly normalize: typeof normalizeUrl;
|
|
2541
|
+
static readonly extractRelativePath: (url?: unknown) => string;
|
|
2542
|
+
static readonly stripHash: (url?: string) => string;
|
|
2543
|
+
static readonly handleHashScroll: ({ event, href, behavior, block, }: THashScrollOptions) => boolean;
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
export { ANSI_COLOR_CODES, ArrayUtils, AssertionUtils, type Branded, CollectionTypeGuards, ColorUtils, ComputationUtils, CoreTypeGuards, DEFAULT_KEYBOARD_CONFIG, DebugUtils, DomUtils, FormatTypeGuards, HTML_TAGS, LOG_TYPES, LinkUtils, type ModifierKey, ObjectUtils, REGEX_CONSTANTS, ReactTypeGuards, RenamedArrayMethods, RenamedObjectMethods, SAFE_HTML_TAGS, type TAbsoluteURL, type TAnyFunction, type TArrayItems, type TArrayLengthMutationKeys, type TAssert, type TBaseImageObject, type TBufferLikeObject, type TCamelCase, type TCssRGB, type TElementLike, type TFixedLengthArray, type TGenericUrlObject, type TGetCallerLocationOptions, type THTMLTags, type THashScrollOptions, type THexByteString, type THighlighterMap, type TInternalUrl, type TJSONArrayString, type TJSONDataString, type TJSONObjectString, type TKebabCase, type TKeyboardActionResult, type TKeyboardConfig, type TLogOptions, type TLogType, type TNamedComponent, type TProcessedTableItem, type TPropCategories, type TPropMap, type TRGB, type TShortcutDefinition, type TSnakeCase, type TStaticMethods, type TTableItem, type TTypeGuard, TransformersUtils, VALID_DOM_PROPS, VALID_DOM_TESTING_KEYS, arrayFilter, arrayFilterNonNullable, arrayFlat, arrayFlatMap, arrayForEach, arrayIncludes, arrayMap, arrayReduce, assertIsAbsoluteUrl, assertIsArray, assertIsBigInt, assertIsBoolean, assertIsBufferLikeObject, assertIsCamelCase, assertIsDefined, assertIsFunction, assertIsInteger, assertIsInternalUrl, assertIsJSONArrayString, assertIsJSONObjectString, assertIsJsonString, assertIsMap, assertIsNil, assertIsNonEmptyString, assertIsNull, assertIsNumber, assertIsRGBTuple, assertIsSet, assertIsString, assertIsSymbol, assertIsUndefined, assertIsWeakMap, assertIsWeakSet, assertObject, capitalizeArray, capitalizeString, capitalizedKeys, contrastTextColor, extractRelativePath, generateKeyMap, getCallerLocation, getKeyboardAction, getLuminance, handleInternalHashScroll, hasChildren, hasDefinedKeys, hasNameMetadata, hasOnClick, hexToHSL, hexToNormalizedRGB, hexToRGB, hexToRGBShorthand, highlight, interpolateColor, isAbsoluteUrl, isArray, isArrayOf, isBigInt, isBoolean, isBufferLikeObject, isCamelCase, isComponentType, isDOMEntry, isDOMPropKey, isDarkColor, isDefined, isElementLike, isElementOfType, isEmail, isForwardRef, isFragment, isFunction, isHTMLString, isHexByteString, isInArray, isInstanceOf, isInteger, isInternalUrl, isJSONArrayString, isJSONObjectString, isJsonString, isKebabCase, isKeyInObject, isKeyOfArray, isKeyOfObject, isLumGreaterThan, isLumLessThan, isMap, isNil, isNonEmptyString, isNull, isNumber, isObject, isPhoneNumber, isPrimitive, isPromise, isPropValid, isRGBTuple, isReactElement, isReactPortal, isRecordOf, isRef, isRefObject, isSet, isSnakeCase, isString, isSymbol, isUndefined, isValidReactNode, isWeakMap, isWeakSet, logDev, normalizeImageSrc, normalizeUrl, objectEntries, objectFromEntries, objectGet, objectHas, objectKeys, objectSet, objectValues, preloadImages, serialize, stripHash, toCamelCase, toKebabCase, toKeyByField, toSnakeCase, validateRGB };
|