@pivanov/utils 0.0.3-rc.1 → 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.
Files changed (40) hide show
  1. package/README.md +101 -306
  2. package/dist/cjs/assertion/index.js +7 -0
  3. package/dist/cjs/index.js +3 -3
  4. package/dist/cjs/object/index.js +7 -0
  5. package/dist/cjs/package.json +3 -0
  6. package/dist/cjs/promise/index.js +7 -0
  7. package/dist/cjs/string/index.js +7 -0
  8. package/dist/cjs/tools/index.js +7 -0
  9. package/dist/cjs/types/index.js +7 -0
  10. package/dist/esm/assertion/index.js +7 -0
  11. package/dist/esm/chunk-1rn730je.js +7 -0
  12. package/dist/esm/chunk-5nmphgya.js +8 -0
  13. package/dist/esm/chunk-bqewq152.js +8 -0
  14. package/dist/esm/chunk-f1nddzrj.js +6 -0
  15. package/dist/esm/chunk-hksj0qca.js +8 -0
  16. package/dist/esm/chunk-tdt3f0jc.js +8 -0
  17. package/dist/esm/index.js +3 -3
  18. package/dist/esm/object/index.js +7 -0
  19. package/dist/esm/package.json +3 -0
  20. package/dist/esm/promise/index.js +7 -0
  21. package/dist/esm/string/index.js +7 -0
  22. package/dist/esm/tools/index.js +7 -0
  23. package/dist/esm/types/index.js +7 -0
  24. package/dist/types/assertion/index.d.ts +145 -0
  25. package/dist/types/index.d.ts +6 -0
  26. package/dist/types/object/index.d.ts +118 -0
  27. package/dist/types/promise/index.d.ts +81 -0
  28. package/dist/types/string/index.d.ts +127 -0
  29. package/dist/types/tools/cache-api/index.d.ts +75 -0
  30. package/dist/types/tools/deepClone.d.ts +2 -0
  31. package/dist/types/tools/dom.d.ts +82 -0
  32. package/dist/types/tools/eventBus/eventBus.d.ts +37 -0
  33. package/dist/types/tools/eventBus/index.d.ts +3 -0
  34. package/dist/types/tools/eventBus/types.d.ts +47 -0
  35. package/dist/types/tools/eventBus/useEventBus.d.ts +3 -0
  36. package/dist/types/tools/index.d.ts +5 -0
  37. package/dist/types/tools/isEqual.d.ts +21 -0
  38. package/dist/types/types/index.d.ts +61 -0
  39. package/package.json +64 -36
  40. package/dist/index.d.ts +0 -817
package/dist/index.d.ts DELETED
@@ -1,817 +0,0 @@
1
- /*!
2
- * @pivanov/utils v0.0.3-rc.1
3
- * (c) 2024-present Pavel Ivanov
4
- * Released under the MIT License.
5
- * https://github.com/pivanov/utils
6
- */
7
-
8
- import { DependencyList, DetailedHTMLProps, HTMLAttributes, ComponentType } from 'react';
9
- import * as react_jsx_runtime from 'react/jsx-runtime';
10
-
11
- /**
12
- * Type guard to check if a value is a boolean
13
- * @param value - The value to check
14
- * @returns True if the value is a boolean, false otherwise
15
- * @example
16
- * ```ts
17
- * isBoolean(true) // true
18
- * isBoolean(false) // true
19
- * isBoolean(0) // false
20
- * isBoolean('true') // false
21
- * ```
22
- */
23
- declare const isBoolean: (value: unknown) => value is boolean;
24
- /**
25
- * Type guard to check if a value is a number
26
- * @param value - The value to check
27
- * @returns True if the value is a number, false otherwise
28
- * @example
29
- * ```ts
30
- * isNumber(42) // true
31
- * isNumber(3.14) // true
32
- * isNumber(NaN) // true
33
- * isNumber('42') // false
34
- * isNumber(null) // false
35
- * ```
36
- */
37
- declare const isNumber: (value: unknown) => value is number;
38
- /**
39
- * Type guard to check if a value is a string
40
- * @param value - The value to check
41
- * @returns True if the value is a string, false otherwise
42
- * @example
43
- * ```ts
44
- * isString('hello') // true
45
- * isString('') // true
46
- * isString(42) // false
47
- * isString(null) // false
48
- * ```
49
- */
50
- declare const isString: (value: unknown) => value is string;
51
- /**
52
- * Type guard to check if a value is a function
53
- * @param value - The value to check
54
- * @returns True if the value is a callable function, false otherwise
55
- * @example
56
- * ```ts
57
- * isFunction(() => {}) // true
58
- * isFunction(function(){}) // true
59
- * isFunction(Math.max) // true
60
- * isFunction({}) // false
61
- * isFunction(null) // false
62
- * ```
63
- */
64
- declare const isFunction: (value: unknown) => value is CallableFunction;
65
- /**
66
- * Type guard to check if a value is a plain object
67
- * @param value - The value to check
68
- * @returns True if the value is a non-null object and not an array, false otherwise
69
- * @example
70
- * ```ts
71
- * isObject({}) // true
72
- * isObject({ foo: 'bar' }) // true
73
- * isObject([]) // false
74
- * isObject(null) // false
75
- * isObject(42) // false
76
- * isObject('string') // false
77
- * ```
78
- */
79
- declare const isObject: (value: unknown) => value is Record<string, unknown>;
80
- /**
81
- * Type guard to check if a value is undefined
82
- * @param value - The value to check
83
- * @returns True if the value is undefined, false otherwise
84
- * @example
85
- * ```ts
86
- * isUndefined(undefined) // true
87
- * isUndefined(null) // false
88
- * isUndefined(0) // false
89
- * ```
90
- */
91
- declare const isUndefined: (value: unknown) => value is undefined;
92
- /**
93
- * Type guard to check if a value is null
94
- * @param value - The value to check
95
- * @returns True if the value is null, false otherwise
96
- * @example
97
- * ```ts
98
- * isNull(null) // true
99
- * isNull(undefined) // false
100
- * isNull(0) // false
101
- * ```
102
- */
103
- declare const isNull: (value: unknown) => value is null;
104
-
105
- /**
106
- * Represents a boolean value that can be either a boolean or the string 'true' or 'false'
107
- * @example
108
- * const isEnabled: TBooleanish = 'true';
109
- * const isDisabled: TBooleanish = false;
110
- */
111
- type TBooleanish = boolean | 'true' | 'false';
112
- /**
113
- * A dictionary type with string keys and values of type T
114
- * @example
115
- * const users: TDict<string> = {
116
- * user1: 'John',
117
- * user2: 'Jane'
118
- * };
119
- *
120
- * const scores: TDict<number> = {
121
- * math: 95,
122
- * science: 87
123
- * };
124
- */
125
- type TDict<T = unknown> = Record<string, T>;
126
- /**
127
- * Type for objects with string or number keys and values of type T
128
- * @example
129
- * const numberDict: TObjType<number> = {
130
- * age: 25,
131
- * score: 100,
132
- * 1: 50
133
- * };
134
- *
135
- * const mixedDict: TObjType = {
136
- * name: 'John',
137
- * 1: true,
138
- * score: 42
139
- * };
140
- */
141
- type TObjType<T = unknown> = {
142
- [key: string | number]: T;
143
- };
144
-
145
- /**
146
- * Creates a new object with the specified keys removed.
147
- *
148
- * @param object - The source object
149
- * @param keys - Array of keys to remove from the object
150
- * @returns A new object without the specified keys
151
- *
152
- * @example
153
- * ```ts
154
- * const user = { name: 'John', age: 30, email: 'john@example.com' };
155
- *
156
- * omit(user, ['email', 'age'])
157
- * // { name: 'John' }
158
- *
159
- * // Preserves original object
160
- * omit(user, ['email'])
161
- * // { name: 'John', age: 30 }
162
- * // user is unchanged
163
- *
164
- * // Handles non-existent keys
165
- * omit(user, ['nonexistent'])
166
- * // { name: 'John', age: 30, email: 'john@example.com' }
167
- * ```
168
- *
169
- * @bestPractice
170
- * - Use when you need to create a new object without certain properties
171
- * - Prefer this over manually deleting properties when immutability is needed
172
- * - Consider using TypeScript's Omit utility type with this function
173
- * - For picking specific properties, use the pick function instead
174
- */
175
- declare const omit: <T extends TDict, K extends keyof T>(object: T, keys: K[]) => Omit<T, K>;
176
- /**
177
- * Creates a new object with only the specified keys.
178
- *
179
- * @param object - The source object
180
- * @param keys - Array of keys to keep in the new object
181
- * @returns A new object containing only the specified keys
182
- *
183
- * @example
184
- * ```ts
185
- * const user = { name: 'John', age: 30, email: 'john@example.com' };
186
- *
187
- * pick(user, ['name', 'email'])
188
- * // { name: 'John', email: 'john@example.com' }
189
- *
190
- * // Handles missing keys
191
- * pick(user, ['name', 'nonexistent'])
192
- * // { name: 'John' }
193
- *
194
- * // Empty keys array
195
- * pick(user, [])
196
- * // {}
197
- * ```
198
- *
199
- * @bestPractice
200
- * - Use when you need to create a new object with only specific properties
201
- * - Useful for API responses where you only want to expose certain fields
202
- * - Consider using TypeScript's Pick utility type with this function
203
- * - For removing specific properties, use the omit function instead
204
- */
205
- declare const pick: <T extends TDict, K extends keyof T>(object: T, keys: K[]) => { [P in K]: T[P]; };
206
- /**
207
- * Merges multiple objects into a target object.
208
- * Performs a shallow merge.
209
- *
210
- * @param target - The target object to merge into
211
- * @param sources - The source objects to merge from
212
- * @returns The merged object (same reference as target)
213
- *
214
- * @example
215
- * ```ts
216
- * // Basic merge
217
- * merge({ a: 1 }, { b: 2 })
218
- * // { a: 1, b: 2 }
219
- *
220
- * // Multiple sources
221
- * merge({ a: 1 }, { b: 2 }, { c: 3 })
222
- * // { a: 1, b: 2, c: 3 }
223
- *
224
- * // Property override
225
- * merge({ a: 1, b: 1 }, { b: 2 }, { b: 3 })
226
- * // { a: 1, b: 3 }
227
- *
228
- * // Shallow merge (nested objects are referenced)
229
- * const obj = { nested: { a: 1 } };
230
- * merge({ x: 1 }, obj).nested === obj.nested
231
- * // true
232
- * ```
233
- *
234
- * @bestPractice
235
- * - Use for simple object merging where nested objects don't need to be cloned
236
- * - Be aware that nested objects are shared by reference
237
- * - For deep merging, use the deepMerge function instead
238
- * - Consider using the spread operator (...) for simpler cases
239
- */
240
- declare const merge: <T extends object>(target: T, ...sources: Partial<T>[]) => T;
241
- /**
242
- * Deep merges multiple objects into a target object.
243
- * Recursively merges nested objects and arrays.
244
- *
245
- * @param target - The target object to merge into
246
- * @param sources - The source objects to merge from
247
- * @returns The deep merged object (same reference as target)
248
- *
249
- * @example
250
- * ```ts
251
- * // Deep merge nested objects
252
- * deepMerge(
253
- * { a: { b: 1, c: 2 } },
254
- * { a: { d: 3 } },
255
- * { a: { e: 4 } }
256
- * )
257
- * // { a: { b: 1, c: 2, d: 3, e: 4 } }
258
- *
259
- * // Handles nested property override
260
- * deepMerge(
261
- * { a: { b: 1 } },
262
- * { a: { b: 2 } }
263
- * )
264
- * // { a: { b: 2 } }
265
- *
266
- * // Mixed nested and top-level properties
267
- * deepMerge(
268
- * { a: 1, b: { c: 2 } },
269
- * { b: { d: 3 }, e: 4 }
270
- * )
271
- * // { a: 1, b: { c: 2, d: 3 }, e: 4 }
272
- *
273
- * // Handles undefined sources
274
- * deepMerge({ a: 1 }, undefined)
275
- * // { a: 1 }
276
- * ```
277
- *
278
- * @bestPractice
279
- * - Use when you need to merge objects with nested structures
280
- * - Be aware that this creates new objects for nested properties
281
- * - For simple flat objects, use the merge function instead
282
- * - Consider performance implications for deeply nested objects
283
- * - Handle circular references if they might occur in your data
284
- */
285
- declare const deepMerge: <T extends object>(target: T, ...sources: Partial<T>[]) => T;
286
-
287
- /**
288
- * sleep - Asynchronously waits for the specified number of milliseconds.
289
- *
290
- * @param {number} ms - The number of milliseconds to wait before resolving the Promise.
291
- * @returns {Promise<null>} - A Promise that resolves after the specified number of milliseconds.
292
- */
293
- declare const sleep: (ms: number) => Promise<null>;
294
-
295
- /**
296
- * Converts a string to camelCase format.
297
- *
298
- * @param str - The input string to convert
299
- * @returns The string in camelCase format
300
- *
301
- * @example
302
- * ```ts
303
- * camelCase('foo-bar') // 'fooBar'
304
- * camelCase('FOO_BAR') // 'fooBar'
305
- * camelCase('Foo Bar') // 'fooBar'
306
- * camelCase('foo bar baz') // 'fooBarBaz'
307
- * camelCase(' foo bar ') // 'fooBar'
308
- *
309
- * // Handles special cases
310
- * camelCase('') // ''
311
- * camelCase('123') // '123'
312
- * camelCase('foo--bar') // 'fooBar'
313
- * ```
314
- *
315
- * @bestPractice
316
- * - Use for JavaScript/TypeScript variable and property names
317
- * - Ideal for internal object properties and method names
318
- * - Avoid using with user-facing text or URLs (use kebab-case instead)
319
- */
320
- declare const camelCase: (str: string) => string;
321
- /**
322
- * Converts a string to PascalCase format.
323
- *
324
- * @param str - The input string to convert
325
- * @returns The string in PascalCase format
326
- *
327
- * @example
328
- * ```ts
329
- * pascalCase('foo-bar') // 'FooBar'
330
- * pascalCase('foo_bar') // 'FooBar'
331
- * pascalCase('foo bar') // 'FooBar'
332
- * pascalCase('foo123bar') // 'Foo123Bar'
333
- *
334
- * // Handles numbers and special cases
335
- * pascalCase('123foo') // '123Foo'
336
- * pascalCase('FOO_BAR_BAZ') // 'FooBarBaz'
337
- * pascalCase('') // ''
338
- * ```
339
- *
340
- * @bestPractice
341
- * - Use for TypeScript/JavaScript class names
342
- * - Use for React component names
343
- * - Use for type and interface names in TypeScript
344
- * - Avoid for variable names or object properties (use camelCase instead)
345
- */
346
- declare const pascalCase: (str: string) => string;
347
- /**
348
- * Capitalizes the first letter of a string.
349
- *
350
- * @param string - The input string to capitalize
351
- * @returns The string with its first letter capitalized
352
- *
353
- * @example
354
- * ```ts
355
- * capitalizeFirstLetter('hello') // 'Hello'
356
- * capitalizeFirstLetter('hello world') // 'Hello world'
357
- * capitalizeFirstLetter('already Capitalized') // 'Already Capitalized'
358
- * capitalizeFirstLetter('') // ''
359
- * ```
360
- *
361
- * @bestPractice
362
- * - Use for simple text formatting where only the first letter needs capitalization
363
- * - For title formatting, consider creating a separate titleCase function
364
- * - For component or class names, use pascalCase instead
365
- */
366
- declare const capitalizeFirstLetter: (string: string) => string;
367
- /**
368
- * Converts a string to kebab-case format.
369
- *
370
- * @param str - The input string to convert
371
- * @returns The string in kebab-case format, or the original input if null/undefined
372
- *
373
- * @example
374
- * ```ts
375
- * kebabCase('fooBar') // 'foo-bar'
376
- * kebabCase('XMLHttpRequest') // 'xml-http-request'
377
- * kebabCase('AAABBBCcc') // 'aaabbb-ccc'
378
- *
379
- * // Handles special characters and accents
380
- * kebabCase('é è à ù') // 'e-e-a-u'
381
- * kebabCase('foo@#$%bar&*^baz') // 'foo-bar-baz'
382
- *
383
- * // Special cases
384
- * kebabCase('') // ''
385
- * kebabCase(null) // null
386
- * kebabCase(undefined) // undefined
387
- * ```
388
- *
389
- * @bestPractice
390
- * - Use for URL slugs and routes
391
- * - Use for CSS class names and HTML attributes
392
- * - Use for file names in web projects
393
- * - Consider using slugify for full URL-safe string conversion
394
- */
395
- declare const kebabCase: (str: string) => string;
396
- /**
397
- * Converts a string into a URL-friendly slug.
398
- * More aggressive than kebabCase, removing all special characters.
399
- *
400
- * @param str - The input string to convert
401
- * @returns A URL-safe lowercase string with:
402
- * - Unicode characters normalized and diacritics removed
403
- * - Special characters removed
404
- * - Spaces, underscores, and multiple hyphens converted to single hyphens
405
- * - Leading and trailing hyphens removed
406
- *
407
- * @example
408
- * ```ts
409
- * slugify('Hello World!') // 'hello-world'
410
- * slugify('Über Café') // 'uber-cafe'
411
- * slugify('__FOO--BAR ') // 'foo-bar'
412
- * slugify('Complex@#$%^&* String') // 'complex-string'
413
- *
414
- * // Special cases
415
- * slugify('한글') // '' (removes non-Latin characters)
416
- * slugify('foo@#$%bar&*^baz') // 'foobarbaz'
417
- * slugify('') // ''
418
- * ```
419
- *
420
- * @bestPractice
421
- * - Use for generating URL-safe slugs
422
- * - Use when you need to remove all special characters
423
- * - For CSS classes or less strict conversions, use kebabCase instead
424
- * - Consider the target audience when handling non-Latin characters
425
- */
426
- declare const slugify: (str: string) => string;
427
- /**
428
- * Capitalizes the first character of a string, maintaining TypeScript's type inference.
429
- *
430
- * @param str - The input string to capitalize
431
- * @returns The string with its first character capitalized
432
- *
433
- * @example
434
- * ```ts
435
- * capitalize('hello') // 'Hello'
436
- * capitalize('world') // 'World'
437
- * capitalize('') // ''
438
- *
439
- * // TypeScript type inference
440
- * const str: 'hello' = 'hello';
441
- * const capitalized = capitalize(str); // Type is Capitalize<'hello'>
442
- * ```
443
- *
444
- * @bestPractice
445
- * - Use when you need to preserve TypeScript's literal types
446
- * - For runtime-only capitalization, use capitalizeFirstLetter instead
447
- * - Consider creating a separate titleCase function for more complex capitalizations
448
- */
449
- declare const capitalize: <S extends string>(str: S) => Capitalize<S>;
450
- /**
451
- * Uncapitalizes the first character of a string, maintaining TypeScript's type inference.
452
- *
453
- * @param str - The input string to uncapitalize
454
- * @returns The string with its first character in lowercase
455
- *
456
- * @example
457
- * ```ts
458
- * uncapitalize('Hello') // 'hello'
459
- * uncapitalize('World') // 'world'
460
- * uncapitalize('') // ''
461
- *
462
- * // TypeScript type inference
463
- * const str: 'Hello' = 'Hello';
464
- * const uncapitalized = uncapitalize(str); // Type is Uncapitalize<'Hello'>
465
- * ```
466
- *
467
- * @bestPractice
468
- * - Use when you need to preserve TypeScript's literal types
469
- * - For runtime-only uncapitalization, consider creating a simpler function
470
- * - Useful for converting PascalCase to camelCase while maintaining type information
471
- */
472
- declare const uncapitalize: <S extends string>(str: S) => Uncapitalize<S>;
473
-
474
- /**
475
- * stringifyBigIntValues - A replacer function for JSON.stringify that converts BigInt values to strings.
476
- *
477
- * @param {string} _key - The key of the property being stringified.
478
- * @param {unknown} value - The value of the property being stringified.
479
- * @returns {unknown} - The value of the property being stringified.
480
- */
481
- declare const stringifyBigIntValues: (_key: string, value: unknown) => unknown;
482
- /**
483
- * Set a value in Cache API
484
- * @param cacheName The name of the cache
485
- * @param key The key under which the value will be stored
486
- * @param value The value to store
487
- * @throws Will throw an error if the operation fails
488
- */
489
- declare const storageSetItem: (cacheName: string, key: string, value: unknown) => Promise<void>;
490
- /**
491
- * Get a value from Cache API
492
- * @param cacheName The name of the cache
493
- * @param key The key of the value to retrieve
494
- * @returns The retrieved value, or null if not found
495
- * @throws Will throw an error if the operation fails
496
- */
497
- declare const storageGetItem: <T>(cacheName: string, key: string) => Promise<T | null>;
498
- /**
499
- * Remove a value from Cache API
500
- * @param cacheName The name of the cache
501
- * @param key The key of the value to remove
502
- * @returns True if the key was found and deleted, false if the key wasn't found
503
- * @throws Will throw an error if the operation fails
504
- */
505
- declare const storageRemoveItem: (cacheName: string, key: string) => Promise<boolean>;
506
- /**
507
- * Clear all values from Cache API
508
- * @param cacheName The name of the cache
509
- * @throws Will throw an error if the operation fails
510
- */
511
- declare const storageClear: (cacheName: string) => Promise<void>;
512
- /**
513
- * Clear values from Cache API by prefix or suffix
514
- * @param cacheName The name of the cache
515
- * @param str The prefix or suffix to match keys against
516
- * @param isPrefix If true, match keys that start with `str`. If false, match keys that end with `str`.
517
- * @throws Will throw an error if the operation fails
518
- */
519
- declare const storageClearByPrefixOrSuffix: (cacheName: string, str: string, isPrefix?: boolean) => Promise<void>;
520
- /**
521
- * Check if a key exists in Cache API
522
- * @param cacheName The name of the cache
523
- * @param key The key to check
524
- * @returns True if the key exists, false otherwise
525
- * @throws Will throw an error if the operation fails
526
- */
527
- declare const storageExists: (cacheName: string, key: string) => Promise<boolean>;
528
- /**
529
- * Get all keys from Cache API
530
- * @param cacheName The name of the cache
531
- * @returns An array of all keys in Cache API
532
- * @throws Will throw an error if the operation fails
533
- */
534
- declare const storageGetAllKeys: (cacheName: string) => Promise<string[]>;
535
- /**
536
- * Calculate the size of the Cache API for a given cacheName.
537
- * If cacheKey is provided, calculate the size of the specific cache entry.
538
- *
539
- * @param cacheName The name of the cache
540
- * @param cacheKey Optional. The key of the specific cache entry to calculate size for.
541
- * @returns The total size of the cache or the specific cache entry in bytes
542
- * @throws Will throw an error if the operation fails
543
- */
544
- declare const storageCalculateSize: (cacheName: string, cacheKey?: string) => Promise<number>;
545
-
546
- /**
547
- * Generic event bus interface for communication between components
548
- * @template T - The type of the message payload
549
- */
550
- interface IEventBus<T = unknown> {
551
- /** The topic/channel name for the event */
552
- topic: string;
553
- /** The message payload */
554
- message: T;
555
- }
556
- /**
557
- * Event bus listener function type
558
- * @template T - The type of the message payload
559
- */
560
- type TEventBusListener<T = unknown> = (message: T) => void;
561
- /**
562
- * Function returned by event bus subscription that can be called to unsubscribe
563
- */
564
- type TEventBusUnsubscribe = () => void;
565
-
566
- /**
567
- * Dispatches a message to all listeners subscribed to the given topic
568
- *
569
- * @template T - The type of the message payload
570
- * @param topic - The topic/channel to dispatch to
571
- * @param message - The message payload to send
572
- *
573
- * @example
574
- * ```ts
575
- * busDispatch('user-updated', { id: 1, name: 'John' });
576
- * ```
577
- */
578
- declare const busDispatch: <T extends IEventBus>(topic: T["topic"], message: T["message"]) => void;
579
- /**
580
- * Subscribes to messages on a specific topic
581
- *
582
- * @template T - The type of the message payload
583
- * @param topic - The topic/channel to subscribe to
584
- * @param listener - Callback function that will be called with the message payload
585
- * @returns An unsubscribe function that can be called to remove the subscription
586
- *
587
- * @example
588
- * ```ts
589
- * const unsubscribe = busSubscribe('user-updated', (message) => {
590
- * console.log('User updated:', message);
591
- * });
592
- *
593
- * // Later when you want to unsubscribe
594
- * unsubscribe();
595
- * ```
596
- */
597
- declare const busSubscribe: <T extends IEventBus>(topic: IEventBus["topic"], listener: TEventBusListener<T["message"]>) => TEventBusUnsubscribe;
598
-
599
- declare const useEventBus: <T extends IEventBus>(topic: T["topic"], listener: TEventBusListener<T["message"]>, deps?: DependencyList) => void;
600
-
601
- declare global {
602
- interface HTMLElement {
603
- uuid?: string;
604
- }
605
- interface ISharedValues {
606
- baseStoreUI: unknown;
607
- }
608
- interface Window {
609
- pivanov?: unknown;
610
- }
611
- interface Navigator {
612
- [key: string | symbol]: unknown;
613
- }
614
- interface Document {
615
- [key: string | symbol]: unknown;
616
- }
617
- namespace JSX {
618
- interface IntrinsicElements {
619
- [elementName: `${string}-${string}`]: DetailedHTMLProps<HTMLAttributes<HTMLElement> & {
620
- [key: string]: unknown;
621
- }, HTMLElement>;
622
- }
623
- }
624
- }
625
- interface IR2WCOptions {
626
- shadow?: 'open' | 'closed';
627
- }
628
- interface IR2WCBaseProps {
629
- container?: HTMLElement;
630
- }
631
-
632
- /**
633
- * Converts a React component into a Web Component (Custom Element)
634
- *
635
- * @template Props - The props type for the React component, must extend IR2WCBaseProps
636
- * @param ReactComponent - The React component to convert
637
- * @param options - Configuration options for the Web Component
638
- * @param styles - Optional array of CSS styles to be injected into the shadow DOM
639
- * @returns A Custom Element constructor that can be registered with customElements.define
640
- *
641
- * @example
642
- * ```tsx
643
- * const MyWebComponent = r2wc(MyReactComponent, {
644
- * shadow: 'open',
645
- * });
646
- *
647
- * customElements.define('my-component', MyWebComponent);
648
- * ```
649
- */
650
- declare const r2wc: <Props extends IR2WCBaseProps>(elementName: string, ReactComponent: ComponentType<Props>, options?: IR2WCOptions, styles?: string[]) => CustomElementConstructor;
651
-
652
- /**
653
- * Props interface for Widget components
654
- * @interface IWidgetComponentProps
655
- * @property {string} name - The name of the widget
656
- * @property {string} [uuid] - Optional group identifier. Widgets sharing the same uuid will update together
657
- * @property {string[]} [jsFiles] - Array of JavaScript file URLs to load. Files are loaded sequentially in the specified order, useful for dependencies
658
- * @property {unknown} [widgetProps] - Optional props to pass to the widget
659
- */
660
- interface IWidgetComponentProps {
661
- name: string;
662
- uuid?: string;
663
- jsFiles?: string[];
664
- widgetProps?: unknown;
665
- }
666
- /**
667
- * React component that handles widget lifecycle and rendering
668
- * @component
669
- * @example
670
- * ```tsx
671
- * <WidgetComponent
672
- * name="my-widget"
673
- * uuid="group1" // Widgets with the same uuid will update together
674
- * widgetProps={{ color: 'blue' }}
675
- * />
676
- * ```
677
- * Multiple widgets with the same uuid will form a group - when one widget's props
678
- * are updated, all widgets in the group will receive the update.
679
- */
680
- declare const WidgetComponent: (props: IWidgetComponentProps) => react_jsx_runtime.JSX.Element | null;
681
- /**
682
- * Props interface for renderWidget function
683
- * @interface IRenderWidgetProps
684
- * @property {string} name - The name of the widget to load
685
- * @property {string} [uuid] - Optional unique identifier for the widget
686
- * @property {HTMLElement} mountTo - DOM element where the widget should be mounted
687
- * @property {Object.<string, unknown>} widgetProps - Props to pass to the widget
688
- */
689
- interface IRenderWidgetProps {
690
- name: string;
691
- uuid?: string;
692
- mountTo: HTMLElement;
693
- widgetProps?: {
694
- [key: string]: unknown;
695
- };
696
- }
697
- /**
698
- * Programmatically loads and mounts a widget into a specified DOM element
699
- * @function
700
- * @param {IRenderWidgetProps} widgetProps - Configuration options for loading the widget
701
- * @example
702
- * ```ts
703
- * renderWidget({
704
- * widgetName: 'my-widget',
705
- * uuid: 'group1',
706
- * mountTo: document.getElementById('widget-container'),
707
- * widgetProps: {
708
- * color: 'blue',
709
- * size: 'large'
710
- * }
711
- * });
712
- * ```
713
- */
714
- declare const renderWidget: (props: IRenderWidgetProps) => void;
715
-
716
- interface IRegisterWidgetProps<T> {
717
- name: string;
718
- styles?: string[];
719
- component: ComponentType<T>;
720
- svgSpritePath?: string;
721
- }
722
- declare const registerWidget: <T extends object>(props: IRegisterWidgetProps<T>) => CustomElementConstructor;
723
-
724
- declare const importWidgets: (jsFiles: string[]) => Promise<void>;
725
-
726
- type TCloneable = object | number | string | boolean | symbol | bigint | null | undefined;
727
- declare const deepClone: <T extends TCloneable>(obj: T) => T;
728
-
729
- /**
730
- * Checks if the code is running in a browser environment
731
- * @returns {boolean} True if running in a browser, false otherwise
732
- * @example
733
- * if (isBrowser()) {
734
- * // Execute browser-specific code
735
- * window.addEventListener('resize', handleResize);
736
- * }
737
- */
738
- declare const isBrowser: () => boolean;
739
- /**
740
- * Sets CSS custom properties (variables) on an HTML element
741
- * @param {HTMLElement | null} el - The target HTML element
742
- * @param {Record<string, string>} cssVars - Object containing CSS variable names and values
743
- * @example
744
- * const element = document.querySelector('.my-element');
745
- * setStyleProperties(element, {
746
- * '--background-color': '#fff',
747
- * '--text-color': '#000',
748
- * '--padding': '1rem'
749
- * });
750
- */
751
- declare const setStyleProperties: (el: HTMLElement | null, cssVars: Record<string, string>) => void;
752
- /**
753
- * Checks if an element is currently visible in the viewport
754
- * @param {HTMLElement} element - The element to check
755
- * @returns {boolean} True if the element is visible in viewport, false otherwise
756
- * @example
757
- * const element = document.querySelector('.my-element');
758
- * if (checkVisibility(element)) {
759
- * // Element is visible in viewport
760
- * element.classList.add('animate');
761
- * }
762
- */
763
- declare const checkVisibility: (element: HTMLElement) => boolean;
764
- /**
765
- * Calculates the rendered width of text with specified styling
766
- * @param {string} text - The text to measure
767
- * @param {number} fontSize - Font size in pixels
768
- * @param {boolean} [isUppercase=false] - Whether to convert text to uppercase before measuring
769
- * @param {string} [fontFamily] - Font family string, defaults to system fonts
770
- * @returns {number} The width of the text in pixels
771
- * @example
772
- * // Basic usage
773
- * const width = calculateRenderedTextWidth('Hello World', 16);
774
- *
775
- * // With uppercase conversion
776
- * const upperWidth = calculateRenderedTextWidth('Hello World', 16, true);
777
- *
778
- * // With custom font
779
- * const customWidth = calculateRenderedTextWidth('Hello World', 16, false, 'Arial');
780
- *
781
- * // Use the width for calculations
782
- * const containerWidth = width + 32; // text width + padding
783
- */
784
- declare const calculateRenderedTextWidth: (text: string, fontSize: number, isUppercase?: boolean, fontFamily?: string) => number;
785
-
786
- /**
787
- * Deeply compares two values for equality
788
- * Supports primitives, Arrays, Sets, Maps, Dates, and plain objects
789
- * @example
790
- * // Comparing arrays
791
- * isEqual([1, 2, 3], [1, 2, 3]); // true
792
- * isEqual([1, 2, 3], [1, 2, 4]); // false
793
- *
794
- * // Comparing objects
795
- * isEqual({ a: 1, b: 2 }, { a: 1, b: 2 }); // true
796
- * isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); // true
797
- *
798
- * // Comparing nested structures
799
- * isEqual(
800
- * { users: [{ id: 1 }, { id: 2 }] },
801
- * { users: [{ id: 1 }, { id: 2 }] }
802
- * ); // true
803
- *
804
- * // Comparing Sets
805
- * isEqual(new Set([1, 2]), new Set([1, 2])); // true
806
- *
807
- * // Comparing Maps
808
- * const map1 = new Map([['a', 1], ['b', 2]]);
809
- * const map2 = new Map([['a', 1], ['b', 2]]);
810
- * isEqual(map1, map2); // true
811
- *
812
- * // Comparing Dates
813
- * isEqual(new Date('2024-01-01'), new Date('2024-01-01')); // true
814
- */
815
- declare const isEqual: <T, K>(obj: T | T[], objToCompare: K | K[]) => boolean;
816
-
817
- export { type IEventBus, type TBooleanish, type TCloneable, type TDict, type TObjType, WidgetComponent, busDispatch, busSubscribe, calculateRenderedTextWidth, camelCase, capitalize, capitalizeFirstLetter, checkVisibility, deepClone, deepMerge, importWidgets, isBoolean, isBrowser, isEqual, isFunction, isNull, isNumber, isObject, isString, isUndefined, kebabCase, merge, omit, pascalCase, pick, r2wc, registerWidget, renderWidget, setStyleProperties, sleep, slugify, storageCalculateSize, storageClear, storageClearByPrefixOrSuffix, storageExists, storageGetAllKeys, storageGetItem, storageRemoveItem, storageSetItem, stringifyBigIntValues, uncapitalize, useEventBus };