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