react-js-plugins 1.3.11 → 1.4.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/README.md CHANGED
@@ -24,1751 +24,1368 @@ pnpm add react-js-plugins
24
24
  | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
25
25
  | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
26
26
 
27
- ### **Features**
28
- Here's the properly structured documentation with clear purpose explanations:
29
27
 
30
- **_log**
31
- Logs a styled message to the console with a specified log level (`log`, `info`, `warn`, `error`).
28
+ ## Array Functions
32
29
 
30
+ ### ✅ **_arrayDiff**
31
+ Returns the difference between two arrays.
33
32
  ```ts
34
- // 📝 Custom log with style
35
- _log("UserService", "Fetching user details...", "info");
33
+ const diff = _arrayDiff(['a', 'b'], ['b']); // ['a']
36
34
  ```
37
35
 
38
- ---
39
- **_handleApi**
40
- Wraps an API call with success and error handling, executing the appropriate callback based on the result.
41
-
36
+ ### ✅ **_arrayIncludesObject**
37
+ Checks if array contains object (by value).
42
38
  ```ts
43
- _handleApi(
44
- getDetails({ name: 'sia' }),
45
- (res) => console.log(res),
46
- (err) => console.error(err)
47
- );
39
+ _arrayIncludesObject(arr, obj);
48
40
  ```
49
- ---
50
-
51
- ✅ **_copyText**
52
- Copies the provided text to the clipboard, using modern APIs with a fallback for older browsers.
53
41
 
42
+ ### ✅ **_arrayIntersection**
43
+ Returns common elements between two arrays.
54
44
  ```ts
55
- // 📋 Copy Text
56
- const success = await _copyText("Hello, clipboard!");
57
- if (success) {
58
- console.log("Text copied successfully");
59
- }
45
+ _arrayIntersection([1,2,3], [2,3,4]); // [2,3]
60
46
  ```
61
- ---
62
47
 
63
- ✅ **_pasteText**
64
- Retrieves and returns the current text content from the clipboard, using modern APIs with a fallback for older browsers.
48
+ ### ✅ **_arrayToObject**
49
+ Converts array of key-value pairs to object.
50
+ ```ts
51
+ _arrayToObject([['a', 1], ['b', 2]]); // { a: 1, b: 2 }
52
+ ```
65
53
 
54
+ ### ✅ **_arrayToObjectByKey**
55
+ Converts array of objects to object using a key.
66
56
  ```ts
67
- // 📥 Paste Text
68
- const text = await _pasteText();
69
- if (text) {
70
- console.log("Pasted text:", text);
71
- }
57
+ _arrayToObjectByKey(users, 'id');
72
58
  ```
73
- ---
74
59
 
75
- ✅ **_alert**
76
- Shows a customizable alert modal.
60
+ ### ✅ **_asyncMap**
61
+ Async map over array items one by one.
77
62
  ```ts
78
- // 🚨 Alert Dialog
79
- await _alert({ title: "Test", text: "Data save successfully!" });
63
+ const results = await _asyncMap(ids, fetchById);
64
+ ```
80
65
 
66
+ ### ✅ **_average**
67
+ Calculates the average of numbers in an array.
68
+ ```ts
69
+ _average([4, 8]); // 6
81
70
  ```
82
- ---
83
- ✅ **_confirm**
84
- Shows a customizable confirm modal.
85
71
 
72
+ ### ✅ **_batchProcess**
73
+ Processes an array of data in asynchronous batches.
86
74
  ```ts
87
- const confirmed = await _confirm({
88
- title: "Are you sure?",
89
- text: "Do you really want to delete this item?",
90
- icon: "warning",
91
- confirmButtonText: "Yes, delete it",
92
- cancelButtonText: "No, cancel",
75
+ await _batchProcess(myArray, 10, async (item) => {
76
+ await handleItem(item);
93
77
  });
94
-
95
- if (confirmed) {
96
- // proceed with delete
97
- } else {
98
- // cancelled
99
- }
100
-
101
78
  ```
102
79
 
103
- ---
104
-
105
- ### ✅ **_generateUUID**
106
-
107
- Generates a unique UUID string using the browser's `crypto` API.
108
-
80
+ ### ✅ **_chunk**
81
+ Splits an array into chunks of a given size.
109
82
  ```ts
110
- // Example usage
111
- const id = _generateUUID();
112
- console.log(id); // e.g., "3b12f1df-5232-4e6b-8f36-3a4e5f7f8b84"
83
+ const parts = _chunk([1, 2, 3, 4], 2); // [[1,2], [3,4]]
113
84
  ```
114
85
 
115
- ---
116
- **_throwError**
117
- Throws an error with an optional context object and logs it to the console.
118
-
86
+ ### ✅ **_deepCloneArray**
87
+ Deeply clones an array of objects.
119
88
  ```ts
120
- // Throw an error
121
- _throwError("Something went wrong",);
89
+ const cloned = _deepCloneArray(originalArray);
122
90
  ```
123
- ---
124
- ✅ **_encodeURI**
125
- Encodes a URI component by escaping special characters to make it safe for use in URLs.
126
91
 
92
+ ### ✅ **_deepCompareArrays**
93
+ Checks if two arrays are deeply equal.
127
94
  ```ts
128
- const encoded = _encodeURI('hello world@2024');
129
- // Output: 'hello%20world%402024'
95
+ const isEqual = _deepCompareArrays(arr1, arr2);
130
96
  ```
131
- ---
132
- ✅ **_decodeURI**
133
- Decodes an encoded URI component back to its original readable string format.
97
+
98
+ ### ✅ **_extractKeyValues**
99
+ Extracts all non-undefined values for a specific key from an array.
134
100
  ```ts
135
- const decoded = _decodeURI('hello%20world%402024');
136
- // Output: 'hello world@2024'
101
+ const employees = [
102
+ { id: 1, name: "Alice" },
103
+ { id: 2 },
104
+ { id: 3, name: "Bob" },
105
+ ];
106
+ _extractKeyValues(employees, "name"); // ["Alice", "Bob"]
137
107
  ```
138
- ---
139
- ✅ **_encryptJson**
140
- Encrypts a JSON object using AES encryption with a secret key.
108
+
109
+ ### ✅ **_extractNestedKeyValues**
110
+ Extracts all non-undefined values from a nested key path in an array of objects.
141
111
  ```ts
142
- // 🔐 Encrypt JSON
143
- const encrypted = _encryptJson({ name: "John" }, "secret123");
112
+ const users = [
113
+ { id: 1, address: { city: "Mumbai" } },
114
+ { id: 2, address: { city: "Pune" } },
115
+ { id: 3 },
116
+ ];
117
+ _extractNestedKeyValues(users, "address.city"); // ["Mumbai", "Pune"]
144
118
  ```
145
- ---
146
- ✅ **_decryptJson**
147
- Decrypts AES-encrypted JSON string using a secret key.
119
+
120
+ ### ✅ **_extractUniqueValues**
121
+ Extracts unique values from an array based on a specific key.
148
122
  ```ts
149
- // 🔓 Decrypt JSON
150
- const decrypted = _decryptJson(encryptedString, "secret123");
123
+ const employees = [
124
+ { id: 1, department: "HR" },
125
+ { id: 2, department: "IT" },
126
+ { id: 3, department: "HR" },
127
+ ];
128
+ _extractUniqueValues(employees, "department"); // ["HR", "IT"]
151
129
  ```
152
- ---
153
- ✅ **_encryptString**
154
- Encrypts a plain string using AES encryption, with optional random IV.
130
+
131
+ ### ✅ **_filterArrayByKeyValue**
132
+ Filters an array by a key-value match. Defaults to filtering where the key's value is `true`.
155
133
  ```ts
156
- // 🔐 Encrypt String
157
- const result = _encryptString("mySecretText", "secretKey");
134
+ const enabledUsers = _filterArrayByKeyValue(userList, "isActive", true);
158
135
  ```
159
- ---
160
- ✅ **_decryptString**
161
- Decrypts an AES-encrypted string using the provided IV and secret key.
136
+
137
+ ### ✅ **_filterByMatchedKey**
138
+ Filters `list1` based on matching key values from `list2`.
162
139
  ```ts
163
- // 🔓 Decrypt String
164
- const plainText = _decryptString(ciphertext, iv, "secretKey");
140
+ const filtered = _filterByMatchedKey(usersList, activeUsers, "userId");
165
141
  ```
166
- ---
167
- ✅ **_encryptPayload**
168
- Encrypts a full payload using a randomly generated key and IV, secured by a static key.
142
+
143
+ ### ✅ **_filterByMatchingKey**
144
+ Filters `list1` by comparing the key's value in `list2`, with more validation than `_filterByMatchedKey`.
169
145
  ```ts
170
- // 🔐 Encrypt Payload
171
- const payload = _encryptPayload({ id: 1 }, "mainSecretKey");
146
+ const filtered = _filterByMatchingKey(productList, inStockItems, "productId");
172
147
  ```
173
- ---
174
- ✅ **_downloadBlob**
175
- Triggers download of a Blob object.
148
+
149
+ ### ✅ **_filterDuplicates**
150
+ Removes duplicates based on a specific object key.
176
151
  ```ts
177
- _downloadBlob(blob, 'myfile.pdf');
152
+ const unique = _filterDuplicates(users, 'id');
178
153
  ```
179
- ---
180
- ✅ **_fileToBase64**
181
- Converts a file to a base64-encoded string.
154
+
155
+ ### ✅ **_findObjectById**
156
+ Finds an object in an array by its `id`.
182
157
  ```ts
183
- const base64 = await _fileToBase64(file);
158
+ const item = _findObjectById(items, '123');
184
159
  ```
185
- ---
186
- ✅ **_base64ToBlob**
187
- Converts a base64-encoded string into a Blob object.
160
+
161
+ ### ✅ **_flattenArray**
162
+ Flattens nested arrays by recursively extracting `item.data` if present.
188
163
  ```ts
189
- const blob = _base64ToBlob(base64String);
164
+ const flat = _flattenArray(nestedArray);
190
165
  ```
191
166
 
192
- ---
193
- **_downloadBase64File**
194
- This function allows downloading any base64-encoded data as a file with a specified filename and extension.
167
+ ### ✅ **_getArrayOfObjectsByProperty**
168
+ Returns all objects with a specific property value.
195
169
  ```ts
196
- const base64Image = 'iVBORw0KGgoAAAANSUhEUgAAA...';
197
- downloadBase64File(base64Image, 'my-picture.png');
198
-
199
- const base64ImageWithPrefix = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA...';
200
- downloadBase64File(base64ImageWithPrefix, 'my-picture.png');
201
-
202
- const base64PDF = 'JVBERi0xLjQKJeLjz9MNCjEgMCBvYmoK...';
203
- downloadBase64File(base64PDF, 'invoice.pdf');
204
-
205
- const base64PDFWithPrefix = 'data:application/pdf;base64,JVBERi0xLjQKJeLjz9MNCjEgMCBvYmoK...';
206
- downloadBase64File(base64PDFWithPrefix, 'invoice.pdf');
207
-
170
+ _getArrayOfObjectsByProperty(data, 'type', 'active');
208
171
  ```
209
172
 
210
- ---
211
- **_dynamicReducer**
212
- Creates a simple dynamic reducer using generic action handler logic.
173
+ ### ✅ **_getMaxMinValue**
174
+ Finds the max and min values in an array.
213
175
  ```ts
214
- // 🧠 Dynamic Reducer
215
- const reducer = _dynamicReducer(initialState);
176
+ const { max, min } = _getMaxMinValue([5, 2, 9]);
216
177
  ```
217
- ---
218
- ✅ **_genericReducer**
219
- A generic reducer accepting predefined handlers for each action type.
178
+
179
+ ### ✅ **_getUniqueValues**
180
+ Returns an array of unique values.
220
181
  ```ts
221
- // ⚙️ Generic Reducer with Custom Actions
222
- const reducer = _genericReducer(initialState, customActions);
182
+ const unique = _getUniqueValues([1, 2, 2, 3]);
223
183
  ```
224
184
 
225
- ---
226
- **_importFile**
227
- It supports multiple types of result formats:
228
- base64 → returns file as a base64 string (useful for previews or uploads)
229
- buffer → returns file as an ArrayBuffer (for binary handling)
230
- file → returns the raw File object (for form submission or re-uploads)
231
- unit8array → returns a Uint8Array (for low-level binary use)
232
-
185
+ ### ✅ **_groupBy**
186
+ Groups array items by a given key.
233
187
  ```ts
234
- const handleChangeFile = async (file) => {
235
- const result = await _importFile(file, 'base64');
236
- console.log('result', result);
237
- };
188
+ const grouped = _groupBy(users, 'department');
238
189
  ```
239
- ---
240
- ✅ **_exportExcel**
241
- Exports JSON data to an Excel or CSV file.
190
+
191
+ ### ✅ **_hasElement**
192
+ Searches recursively in a menu tree to find an element by key and value.
242
193
  ```ts
243
- await _exportExcel({
244
- data: [
245
- { name: 'siya', age: 5 },
246
- { name: 'riya', age: 6 },
247
- ],
248
- filename: 'users',
249
- })
250
- .then(() => console.log('Export successful'))
251
- .catch((err) => console.error('Export failed:', err.message));
194
+ const found = _hasElement(menuItems, "id", 5);
252
195
  ```
253
- ---
254
- ✅ **_importExcel**
255
- Exports JSON data to an Excel file.
196
+
197
+ ### ✅ **_hasItem**
198
+ Searches recursively in a menu tree to find an item by `path`.
256
199
  ```ts
257
- // 📤 Import to Excel
258
- const fileInputHandler = async (event: React.ChangeEvent<HTMLInputElement>) => {
259
- const { data, error } = await _importExcel(event);
200
+ const item = _hasItem(menuItems, "/dashboard");
201
+ ```
260
202
 
261
- if (error) {
262
- console.error('Error:', error.message);
263
- return;
264
- }
265
-
266
- if (data) {
267
- console.log('Successfully parsed data:', data);
268
- }
269
- };
203
+ ### **_isEmptyArray**
204
+ Checks if a given value is an empty array.
205
+ ```ts
206
+ const isEmpty = _isEmptyArray([]);
270
207
  ```
271
- ---
272
- ✅ **_thousandSeparator**
273
- Formats a number with thousand separators and fixed decimal precision.
208
+
209
+ ### ✅ **_isInArray**
210
+ Checks if a value exists in array.
274
211
  ```ts
275
- // 💰 Thousand Separator
276
- const formatted = _thousandSeparator(1234567.89);
212
+ _isInArray(['a', 'b'], 'b'); // true
277
213
  ```
278
- ---
279
- ✅ **_getFinancialYear**
280
- Returns the current financial year based on today's date.
214
+
215
+ ### ✅ **_isValueInArray**
216
+ Checks whether a value exists in a given array.
281
217
  ```ts
282
- // 📆 Get Financial Year
283
- const fy = _getFinancialYear();
218
+ const exists = _isValueInArray([1, 2, 3], 2);
284
219
  ```
285
- ---
286
- ✅ **_dateFormat**
287
- Formats a date using Moment.js with the specified format.
220
+
221
+ ### ✅ **_mapAsync**
222
+ Parallel async map over array.
288
223
  ```ts
289
- const formatted = _dateFormat(new Date(), 'YYYY-MM-DD');
224
+ const data = await _mapAsync(users, fetchDetails);
290
225
  ```
291
- ---
292
- ✅ **_dateTransformer**
293
- Recursively formats all dates in an object or array.
294
226
 
227
+ ### ✅ **_mergeArrays**
228
+ Merges two arrays and removes duplicates.
295
229
  ```ts
296
- const result = _dateTransformer(data);
230
+ const merged = _mergeArrays(arr1, arr2);
297
231
  ```
298
- ---
299
232
 
300
- ✅ **_getStorage**
301
- Handles local/session storage actions like GET, SET, REMOVE, CLEAR.
233
+ ### ✅ **_mergeArraysByKey**
234
+ Merges two arrays of objects based on a common key.
302
235
  ```ts
303
- // 🗃️ Use Local Storage
304
- const data = _getStorage({ action: 'GET', type: 'local', key: 'user' });
236
+ const merged = _mergeArraysByKey(arr1, arr2, 'id');
305
237
  ```
306
- ---
307
- ✅ **_convertToCurrency**
308
- Converts a number to a formatted currency string.
238
+
239
+ ### ✅ **_removeFalsy**
240
+ Removes all falsy values (`false`, `0`, `''`, `null`, `undefined`, `NaN`) from an array.
309
241
  ```ts
310
- // 💵 Convert to Currency
311
- const price = _convertToCurrency(2500, 'INR');
242
+ const cleaned = _removeFalsy([0, 1, false, 2, '', 3]); // [1, 2, 3]
312
243
  ```
313
- ---
314
244
 
315
245
  ### ✅ **_removeDuplicateByKey**
316
-
317
246
  Removes duplicates based on a specific key (e.g. `id`), keeping the **first occurrence**.
318
-
319
247
  ```ts
320
248
  const users = [
321
249
  { id: 1, name: 'Alice' },
322
250
  { id: 2, name: 'Bob' },
323
251
  { id: 1, name: 'Alice Duplicate' },
324
252
  ];
325
-
326
253
  const uniqueUsers = _removeDuplicateByKey(users, 'id');
327
254
  // Result: [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
328
255
  ```
329
256
 
330
- ---
331
-
332
- ### ✅ **_globalizeDateTime**
333
-
334
- Converts a date/time to a specific time zone and format.
335
-
257
+ ### ✅ **_removeDuplicates**
258
+ Removes duplicate objects based on a key.
336
259
  ```ts
337
- const localized = _globalizeDateTime('2024-07-09T12:00:00', {
338
- timeZone: 'Asia/Kolkata',
339
- format: 'yyyy-MM-dd HH:mm',
340
- });
341
- // Result: "2024-07-09 17:30"
260
+ const cleaned = _removeDuplicates(data, 'email');
342
261
  ```
343
262
 
344
- ---
345
-
346
- ### ✅ **_formatInternationalDate**
347
-
348
- Formats a date according to locale, timezone, and preset or custom format.
349
-
263
+ ### ✅ **_sortByKey**
264
+ Sorts array of objects by a specific key.
350
265
  ```ts
351
- const formatted = _formatInternationalDate('2024-07-09T10:00:00Z', {
352
- country: 'IN',
353
- timezone: 'Asia/Kolkata',
354
- format: 'DATETIME_SHORT',
355
- });
356
- // Result: "9/7/2024, 3:30 pm"
266
+ const sorted = _sortByKey(products, 'price');
357
267
  ```
358
268
 
359
- ---
360
- **_parseJSON**
361
- Safely parses a JSON string into an object.
269
+ ### ✅ **_sum**
270
+ Returns the sum of an array of numbers.
362
271
  ```ts
363
- // 📦 Parse JSON
364
- const obj = _parseJSON(jsonString);
272
+ _sum([1, 2, 3]); // 6
365
273
  ```
366
- ---
367
- ✅ **_stringifyJSON**
368
- Safely converts an object to a JSON string.
369
274
 
275
+ ### ✅ **_swapArrayByKey**
276
+ Sorts an array in descending order based on a key.
370
277
  ```ts
371
- // 🧾 Stringify JSON
372
- const str = _stringifyJSON(obj);
278
+ const sorted = _swapArrayByKey(data, 'score');
373
279
  ```
374
- ---
375
- ✅ **_getCookie**
376
- Retrieves a cookie value by its name.
280
+
281
+ ### ✅ **_swapArrayElements**
282
+ Swaps two elements in an array.
377
283
  ```ts
378
- // 🍪 Get Cookie
379
- const token = _getCookie('auth_token');
284
+ _swapArrayElements(arr, 0, 1);
380
285
  ```
381
- ---
382
- ✅ **_setCookie**
383
- Sets a cookie with a name, value, and expiry (in days).
384
- ```ts
385
- // 📝 Set Cookie
386
- _setCookie('auth_token', 'abc123', 7);
387
- ```
388
- ---
389
- ✅ **_getBrowserInfo**
390
- Returns the name of the browser (e.g., Chrome, Firefox).
391
- ```ts
392
- // 🌐 Get Browser Info
393
- const browser = _getBrowserInfo();
394
- ```
395
- ---
396
- ✅ **_generatePassword**
397
- Generates a strong random password with mixed characters.
398
- ```ts
399
- // 🔑 Generate Random Password
400
- const newPassword = _generatePassword(12);
401
- ```
402
- ---
403
- ✅ **_getStartStopTime**
404
- Returns the start and end datetime of a given date's month in specified format.
405
- ```ts
406
- // 🕐 Get Start & Stop Time
407
- const { startTime, stopTime } = _getStartStopTime(new Date());
408
- ```
409
- ---
410
- ✅ **getUTCTimestamp**
411
- Returns the UTC timestamp.
412
- ```ts
413
- const ts3 = getUTCTimestamp({ year: 2025, month: "December", day: 25, hour: 10, minute: 30 });
414
- console.log(new Date(ts3).toUTCString()); // Thu, 25 Dec 2025 10:30:00 GMT
415
- ```
416
- ---
417
- ✅ **_setTouchedFields**
418
- Marks all fields with errors as touched in a Formik form.
419
- ```ts
420
- _setTouchedFields(formRef, errors);
421
- ```
422
- ---
423
- ✅ **_isValidForm**
424
- Validates a Formik form and returns whether it's valid.
425
- ```ts
426
- const isValid = await _isValidForm(formRef);
427
- ```
428
- ---
429
- ✅ **_validateFormRef**
430
- Returns form validity and error details from a Formik ref.
431
- ```ts
432
- const { isValid, errors } = await _validateFormRef(formRef);
433
- ```
434
- ---
435
- ✅ **_initializeFormValues**
436
- Initializes form values with empty strings for each field.
437
- ```ts
438
- const initialValues = _initializeFormValues(['name', 'email']);
439
- ```
440
- ---
441
- ✅ **_dynamicRequiredValidation**
442
- Generates a Yup schema with required validations for given fields.
443
- ```ts
444
- const schema = _dynamicRequiredValidation(['name', 'email']);
445
- ```
446
- ---
447
- ✅ **_generateYupValidation**
448
- Creates a Yup validation schema with all fields marked as required.
449
- ```ts
450
- const schema = _generateYupValidation(['name', 'age']);
451
- ```
452
- ---
453
- ✅ **_initializeFormikFields**
454
- Returns an object with default empty string values for Formik fields.
455
- ```ts
456
- const formikFields = _initializeFormikFields(['username', 'password']);
457
- ```
458
- ---
459
- ✅ **_isNotEmpty**
460
- Checks if a given value is not empty — returns false for empty arrays, empty objects, and falsy values like null, undefined, false, or ''.
461
- ```ts
462
- const isEmpty = _isNotEmpty([]);
463
- ```
464
- ---
465
- ✅ **_isEmptyArray**
466
- Checks if a given value is an empty array.
467
- ```ts
468
- const isEmpty = _isEmptyArray([]);
469
- ```
470
- ---
471
- ✅ **_isEmptyObject**
472
- Checks if an object has no own properties.
473
- ```ts
474
- const isObjEmpty = _isEmptyObject({});
475
- ```
476
- ---
477
- ✅ **_isValueInArray**
478
- Checks whether a value exists in a given array.
479
- ```ts
480
- // 🔍 Value in Array
481
- const exists = _isValueInArray([1, 2, 3], 2);
482
- ```
483
- ---
484
- ✅ **_sleep**
485
- Creates a delay for a given time using Promise.
486
286
 
287
+ ### ✅ **_transformArray**
288
+ Applies a transformation function to each item in an array.
487
289
  ```ts
488
- // Delay Execution
489
- await _sleep(1000);
490
- ```
491
- ---
492
- ✅ **_hasItem**
493
- Searches recursively in a menu tree to find an item by `path`.
494
- ```ts
495
- // 🧭 Find Menu Item by Path
496
- const item = _hasItem(menuItems, "/dashboard");
497
- ```
498
- ---
499
- ✅ **_hasElement**
500
- Searches recursively in a menu tree to find an element by key and value.
501
- ```ts
502
- // 🔎 Find Element in Menu
503
- const found = _hasElement(menuItems, "id", 5);
504
- ```
505
- ---
506
- ✅ **_flattenArray**
507
- Flattens nested arrays by recursively extracting `item.data` if present.
508
- ```ts
509
- // 🔁 Flatten Nested Arrays
510
- const flat = _flattenArray(nestedArray);
290
+ const result = _transformArray(users, user => user.name);
511
291
  ```
512
- ---
513
-
514
- ✅ **_filterByMatchedKey**
515
- Filters `list1` based on matching key values from `list2`.
516
292
 
293
+ ### ✅ **_transformAsyncData**
294
+ Applies a transformer to each array item asynchronously.
517
295
  ```ts
518
- // 🔍 Filter by matching key in both lists
519
- const filtered = _filterByMatchedKey(usersList, activeUsers, "userId");
296
+ const updated = await _transformAsyncData(data, transformFn);
520
297
  ```
521
298
 
522
- ---
523
-
524
- ✅ **_filterByMatchingKey**
525
- Filters `list1` by comparing the key's value in `list2`, with more validation than `_filterByMatchedKey`.
526
-
299
+ ### ✅ **_updateObjectInArray**
300
+ Updates a matching object in an array by key-value.
527
301
  ```ts
528
- // 🔍 Filter with validation for objects
529
- const filtered = _filterByMatchingKey(productList, inStockItems, "productId");
302
+ const updated = _updateObjectInArray(users, 'id', '123', { name: 'New Name' });
530
303
  ```
531
304
 
532
305
  ---
533
306
 
534
- **_filterArrayByKeyValue**
535
- Filters an array by a key-value match. Defaults to filtering where the key's value is `true`.
307
+ ## Object Functions
536
308
 
537
- ```ts
538
- // ✅ Filter by key value
539
- const enabledUsers = _filterArrayByKeyValue(userList, "isActive", true);
540
- ```
541
-
542
- ---
543
- ✅ **_deepClone**
309
+ ### ✅ **_deepClone**
544
310
  Deep clones an object using `JSON.stringify` and `JSON.parse`.
545
311
  ```ts
546
- // 🧬 Deep Clone
547
312
  const clone = _deepClone(originalObj);
548
313
  ```
549
- ---
550
- ✅ **_mergeObjects**
551
- Merges two objects, giving priority to the second object’s properties.
552
- ```ts
553
- // 🔀 Merge Objects
554
- const merged = _mergeObjects(obj1, obj2);
555
- ```
556
- ---
557
- ✅ **_mapObject**
558
- Maps over an object and returns an array using a callback.
559
- ```ts
560
- // 🗺️ Map Object
561
- const result = _mapObject(myObj, (key, value) => `${key}: ${value}`);
562
- ```
563
- ---
564
- ✅ **_isEqual**
565
- Checks deep equality of two values using `JSON.stringify`.
566
- ```ts
567
- // 🟰 Check Equality
568
- const isSame = _isEqual(obj1, obj2);
569
- ```
570
- ---
571
- ✅ **_capitalize**
572
- Capitalizes the first character of a string.
573
- ```ts
574
- // 🔡 Capitalize
575
- const name = _capitalize("john");
576
- ```
577
-
578
- ---
579
-
580
- ### ✅ **_countWords**
581
-
582
- Counts the number of words in a string by trimming whitespace and splitting by spaces.
583
314
 
315
+ ### ✅ **_deepEqual**
316
+ Deep comparison between two objects.
584
317
  ```ts
585
- const wordCount = _countWords(' Hello world! How are you? ');
586
- // Output: 5
318
+ const isSame = _deepEqual(objA, objB);
587
319
  ```
588
320
 
589
- ---
590
- ✅ **_isMobile**
591
- Detects if the current device is a mobile device.
592
- ```ts
593
- // 📱 Check if Mobile
594
- const mobile = _isMobile();
595
- ```
596
- ---
597
- ✅ **_scrollToTop**
598
- Scrolls the page smoothly to the top.
599
- ```ts
600
- // ⬆️ Scroll to Top
601
- _scrollToTop();
602
- ```
603
- ---
604
- ✅ **_batchProcess**
605
- Processes an array of data in asynchronous batches.
606
- ```ts
607
- await _batchProcess(myArray, 10, async (item) => {
608
- await handleItem(item);
609
- });
610
- ```
611
- ---
612
- ✅ **_flattenObject**
613
- Flattens a nested object into dot notation key-value pairs.
614
- ```ts
615
- const flat = _flattenObject({ a: { b: 1 } }); // { 'a.b': 1 }
616
- ```
617
- ---
618
- ✅ **_deepMerge**
321
+ ### ✅ **_deepMerge**
619
322
  Recursively merges two objects.
620
323
  ```ts
621
324
  const merged = _deepMerge(obj1, obj2);
622
325
  ```
623
- ---
624
- ✅ **_chunk**
625
- Splits an array into chunks of a given size.
626
326
 
327
+ ### ✅ **_filterObjectByKey**
328
+ Filters object based on allowed keys.
627
329
  ```ts
628
- const parts = _chunk([1, 2, 3, 4], 2); // [[1,2], [3,4]]
629
- ```
630
- ---
631
- ✅ **_asyncDebounce**
632
- Debounces an async function call.
633
- ```ts
634
- const debouncedFn = _asyncDebounce(fetchData, 500);
635
- debouncedFn();
330
+ _filterObjectByKey(user, ['id', 'name']);
636
331
  ```
637
- ---
638
- ✅ **_deepCloneArray**
639
- Deeply clones an array of objects.
332
+
333
+ ### ✅ **_flattenObject**
334
+ Flattens a nested object into dot notation key-value pairs.
640
335
  ```ts
641
- const cloned = _deepCloneArray(originalArray);
336
+ const flat = _flattenObject({ a: { b: 1 } }); // { 'a.b': 1 }
642
337
  ```
643
- ---
644
- ✅ **_getMaxMinValue**
645
- Finds the max and min values in an array.
338
+
339
+ ### ✅ **_freeze**
340
+ Freezes an object to make it immutable.
646
341
  ```ts
647
- const { max, min } = _getMaxMinValue([5, 2, 9]);
342
+ const frozen = _freeze(config);
648
343
  ```
649
- ---
650
- ✅ **_asyncMap**
651
- Async map over array items one by one.
344
+
345
+ ### ✅ **_getKeyByValue**
346
+ Returns the first key in an object with the matching value.
652
347
  ```ts
653
- const results = await _asyncMap(ids, fetchById);
348
+ const key = _getKeyByValue(obj, 'targetValue');
654
349
  ```
655
- ---
656
- ✅ **_transformAsyncData**
657
- Applies a transformer to each array item asynchronously.
658
350
 
351
+ ### ✅ **_getKeysByValue**
352
+ Finds all keys in an object with a specific value.
659
353
  ```ts
660
- const updated = await _transformAsyncData(data, transformFn);
354
+ const keys = _getKeysByValue(obj, 'active');
661
355
  ```
662
- ---
663
- ✅ **_getNestedProperty**
356
+
357
+ ### ✅ **_getNestedProperty**
664
358
  Retrieves value from object using a string path.
665
359
  ```ts
666
360
  const value = _getNestedProperty(user, 'profile.name');
667
361
  ```
668
- ---
669
- ✅ **_deepEqual**
670
- Deep comparison between two objects.
671
- ```ts
672
- const isSame = _deepEqual(objA, objB);
673
- ```
674
- ---
675
- ✅ **_mergeArrays**
676
- Merges two arrays and removes duplicates.
677
- ```ts
678
- const merged = _mergeArrays(arr1, arr2);
679
- ```
680
- ---
681
- ✅ **_filterDuplicates**
682
- Removes duplicates based on a specific object key.
683
- ```ts
684
- const unique = _filterDuplicates(users, 'id');
685
- ```
686
-
687
- ---
688
-
689
- ✅ **_extractUniqueValues**
690
- Extracts unique values from an array based on a specific key.
691
362
 
363
+ ### ✅ **_getObjectValues**
364
+ Returns object values as an array.
692
365
  ```ts
693
- const employees = [
694
- { id: 1, department: "HR" },
695
- { id: 2, department: "IT" },
696
- { id: 3, department: "HR" },
697
- ];
698
-
699
- _extractUniqueValues(employees, "department");
700
- ["HR", "IT"]
366
+ _getObjectValues({ a: 1, b: 2 }); // [1, 2]
701
367
  ```
702
368
 
703
- ---
704
-
705
- ✅ **_extractKeyValues**
706
- Extracts all non-undefined values for a specific key from an array.
707
-
369
+ ### ✅ **_getValueByKey**
370
+ Returns the value of a key from an object.
708
371
  ```ts
709
- const employees = [
710
- { id: 1, name: "Alice" },
711
- { id: 2 },
712
- { id: 3, name: "Bob" },
713
- ];
714
-
715
- _extractKeyValues(employees, "name");
716
- ["Alice", "Bob"]
372
+ const value = _getValueByKey(obj, 'username');
717
373
  ```
718
374
 
719
- ---
720
-
721
- ✅ **_extractNestedKeyValues**
722
- Extracts all non-undefined values from a nested key path in an array of objects.
723
-
724
- ```ts
725
- const users = [
726
- { id: 1, address: { city: "Mumbai" } },
727
- { id: 2, address: { city: "Pune" } },
728
- { id: 3 },
729
- ];
730
-
731
- _extractNestedKeyValues(users, "address.city");
732
-
733
- ["Mumbai", "Pune"]
734
- ```
735
- ---
736
- ✅ **_sortByKey**
737
- Sorts array of objects by a specific key.
738
- ```ts
739
- const sorted = _sortByKey(products, 'price');
740
- ```
741
- ---
742
- ✅ **_mapAsync**
743
- Parallel async map over array.
744
- ```ts
745
- const data = await _mapAsync(users, fetchDetails);
746
- ```
747
- ---
748
- ✅ **_formatDate**
749
- Formats a date based on a custom pattern.
750
- ```ts
751
- _formatDate(new Date(), 'YMD'); // e.g., "Apr 9, 2025"
752
- ```
753
- ---
754
- ✅ **_calPercentage**
755
- Calculates the percentage of a value relative to total.
756
- ```ts
757
- _calPercentage(40, 200); // 20
758
- ```
759
- ---
760
- ✅ **_sum**
761
- Returns the sum of an array of numbers.
762
- ```ts
763
- _sum([1, 2, 3]); // 6
764
- ```
765
- ---
766
- ✅ **_average**
767
- Calculates the average of numbers in an array.
768
- ```ts
769
- _average([4, 8]); // 6
770
- ```
771
- ---
772
- ✅ **_getPriceAfterTax**
773
- Adds tax to a given price.
774
- ```ts
775
- _getPriceAfterTax(100, 18); // 118
776
- ```
777
- ---
778
- ✅ **_calculateTimeDifference**
779
- Returns difference between two dates in readable format.
780
- ```ts
781
- _calculateTimeDifference(start, end); // "1d 2h 3m 4s"
782
- ```
783
- ---
784
- ✅ **_arrayIncludesObject**
785
- Checks if array contains object (by value).
786
- ```ts
787
- _arrayIncludesObject(arr, obj);
788
- ```
789
- ---
790
- ✅ **_toCamelCase**
791
- Converts kebab-case or snake_case to camelCase.
375
+ ### ✅ **_isEmptyObject**
376
+ Checks if an object has no own properties.
792
377
  ```ts
793
- _toCamelCase('hello_world'); // helloWorld
378
+ const isObjEmpty = _isEmptyObject({});
794
379
  ```
795
- ---
796
- ✅ **_freeze**
797
- Freezes an object to make it immutable.
380
+
381
+ ### ✅ **_isEqual**
382
+ Checks deep equality of two values using `JSON.stringify`.
798
383
  ```ts
799
- const frozen = _freeze(config);
384
+ const isSame = _isEqual(obj1, obj2);
800
385
  ```
801
- ---
802
- ✅ **_isFreeze**
386
+
387
+ ### ✅ **_isFreeze**
803
388
  Checks if object is frozen.
804
389
  ```ts
805
390
  _isFreeze(obj); // true/false
806
391
  ```
807
- ---
808
- ✅ **_seal**
809
- Seals an object to prevent adding/removing properties.
810
- ```ts
811
- _seal(settings);
812
- ```
813
- ---
814
- ✅ **_isSeal**
392
+
393
+ ### ✅ **_isSeal**
815
394
  Checks if object is sealed.
816
395
  ```ts
817
396
  _isSeal(obj); // true/false
818
397
  ```
819
- ---
820
- ✅ **_arrayToObject**
821
- Converts array of key-value pairs to object.
822
- ```ts
823
- _arrayToObject([['a', 1], ['b', 2]]);
824
- ```
825
- ---
826
- ✅ **_objectToArray**
827
- Converts object to array of key-value pairs.
828
- ```ts
829
- _objectToArray({ a: 1 }); // [['a', 1]]
830
- ```
831
- ---
832
- ✅ **_arrayToObjectByKey**
833
- Converts array of objects to object using a key.
834
- ```ts
835
- _arrayToObjectByKey(users, 'id');
836
- ```
837
- ---
838
- ✅ **_isInArray**
839
- Checks if a value exists in array.
398
+
399
+ ### ✅ **_mapObject**
400
+ Maps over an object and returns an array using a callback.
840
401
  ```ts
841
- _isInArray(['a', 'b'], 'b'); // true
402
+ const result = _mapObject(myObj, (key, value) => `${key}: ${value}`);
842
403
  ```
843
- ---
844
- ✅ **_getObjectValues**
845
- Returns object values as an array.
404
+
405
+ ### ✅ **_mergeObjects**
406
+ Merges two objects, giving priority to the second object's properties.
846
407
  ```ts
847
- _getObjectValues({ a: 1, b: 2 }); // [1, 2]
408
+ const merged = _mergeObjects(obj1, obj2);
848
409
  ```
849
- ---
850
- ✅ **_swapArrayElements**
851
- Swaps two elements in an array.
410
+
411
+ ### ✅ **_objectToArray**
412
+ Converts object to array of key-value pairs.
852
413
  ```ts
853
- _swapArrayElements(arr, 0, 1);
414
+ _objectToArray({ a: 1 }); // [['a', 1]]
854
415
  ```
855
- ---
856
- ✅ **_filterObjectByKey**
857
- Filters object based on allowed keys.
416
+
417
+ ### ✅ **_seal**
418
+ Seals an object to prevent adding/removing properties.
858
419
  ```ts
859
- _filterObjectByKey(user, ['id', 'name']);
420
+ _seal(settings);
860
421
  ```
861
- ---
862
- ✅ **_getScrollPosition**
863
- Returns current window scroll position.
864
422
 
423
+ ### ✅ **_setNestedProperty**
424
+ Sets a deeply nested property in an object using a string path.
865
425
  ```ts
866
- const { scrollX, scrollY } = _getScrollPosition();
426
+ _setNestedProperty(obj, 'user.address.city', 'Mumbai');
867
427
  ```
428
+
868
429
  ---
869
- ✅ **_arrayIntersection**
870
- Returns common elements between two arrays.
430
+
431
+ ## Form & Validation Functions
432
+
433
+ ### ✅ **_dynamicRequiredValidation**
434
+ Generates a Yup schema with required validations for given fields.
871
435
  ```ts
872
- _arrayIntersection([1,2,3], [2,3,4]); // [2,3]
436
+ const schema = _dynamicRequiredValidation(['name', 'email']);
873
437
  ```
874
- ---
875
- ✅ **_getArrayOfObjectsByProperty**
876
- Returns all objects with a specific property value.
438
+
439
+ ### ✅ **_generateYupValidation**
440
+ Creates a Yup validation schema with all fields marked as required.
877
441
  ```ts
878
- _getArrayOfObjectsByProperty(data, 'type', 'active');
442
+ const schema = _generateYupValidation(['name', 'age']);
879
443
  ```
880
- ---
881
- ✅ **_setNestedProperty**
882
- Sets a deeply nested property in an object using a string path.
444
+
445
+ ### ✅ **_initializeFormikFields**
446
+ Returns an object with default empty string values for Formik fields.
883
447
  ```ts
884
- _setNestedProperty(obj, 'user.address.city', 'Mumbai');
448
+ const formikFields = _initializeFormikFields(['username', 'password']);
885
449
  ```
886
- ---
887
- ✅ **_transformArray**
888
- Applies a transformation function to each item in an array.
450
+
451
+ ### ✅ **_initializeFormValues**
452
+ Initializes form values with empty strings for each field.
889
453
  ```ts
890
- const result = _transformArray(users, user => user.name);
454
+ const initialValues = _initializeFormValues(['name', 'email']);
891
455
  ```
892
- ---
893
- ✅ **_findObjectById**
894
- Finds an object in an array by its `id`.
456
+
457
+ ### ✅ **_isValidForm**
458
+ Validates a Formik form and returns whether it's valid.
895
459
  ```ts
896
- const item = _findObjectById(items, '123');
460
+ const isValid = await _isValidForm(formRef);
897
461
  ```
898
- ---
899
- ✅ **_getUniqueValues**
900
- Returns an array of unique values.
462
+
463
+ ### ✅ **_setTouchedFields**
464
+ Marks all fields with errors as touched in a Formik form.
901
465
  ```ts
902
- const unique = _getUniqueValues([1, 2, 2, 3]);
466
+ _setTouchedFields(formRef, errors);
903
467
  ```
904
- ---
905
- ✅ **_mergeArraysByKey**
906
- Merges two arrays of objects based on a common key.
468
+
469
+ ### ✅ **_validateFormRef**
470
+ Returns form validity and error details from a Formik ref.
907
471
  ```ts
908
- const merged = _mergeArraysByKey(arr1, arr2, 'id');
472
+ const { isValid, errors } = await _validateFormRef(formRef);
909
473
  ```
910
474
 
911
475
  ---
912
476
 
913
- **_removeDuplicates**
914
- Removes duplicate objects based on a key.
477
+ ## Validation Functions
915
478
 
479
+ ### ✅ **_isValidBase64**
480
+ Checks if a string is a valid Base64-encoded value.
916
481
  ```ts
917
- const cleaned = _removeDuplicates(data, 'email');
482
+ const isValid = _isValidBase64('U29tZSB0ZXh0');
918
483
  ```
919
484
 
920
- ---
921
-
922
- ✅ **_groupBy**
923
- Groups array items by a given key.
485
+ ### ✅ **_isValidBlob**
486
+ Checks if the input is a `Blob`.
487
+ ```ts
488
+ const isValid = _isValidBlob(new Blob(['text']));
489
+ ```
924
490
 
491
+ ### ✅ **_isValidBoolean**
492
+ Checks if the input is a boolean.
925
493
  ```ts
926
- const grouped = _groupBy(users, 'department');
494
+ const isValid = _isValidBoolean(true);
927
495
  ```
928
496
 
929
- ---
497
+ ### ✅ **_isValidCreditCard**
498
+ Checks if a string matches known credit card patterns.
499
+ ```ts
500
+ const isValid = _isValidCreditCard('4111111111111111');
501
+ ```
930
502
 
931
- ✅ **_arrayDiff**
932
- Returns the difference between two arrays.
503
+ ### ✅ **_isValidDate**
504
+ Checks if a string matches the `YYYY-MM-DD` date format.
505
+ ```ts
506
+ const isValid = _isValidDate('2025-04-09');
507
+ ```
933
508
 
509
+ ### ✅ **_isValidDateObject**
510
+ Checks if the input is a valid `Date` object.
934
511
  ```ts
935
- const diff = _arrayDiff(['a', 'b'], ['b']);
512
+ const isValid = _isValidDateObject(new Date());
936
513
  ```
937
514
 
938
- ---
515
+ ### ✅ **_isValidDateRange**
516
+ Checks if the start date is earlier than or equal to the end date.
517
+ ```ts
518
+ const isValid = _isValidDateRange('2025-01-01', '2025-12-31');
519
+ ```
939
520
 
940
- ✅ **_deepCompareArrays**
941
- Checks if two arrays are deeply equal.
521
+ ### ✅ **_isValidDateTime**
522
+ Checks if a string matches the `YYYY-MM-DDTHH:mm:ss` format.
523
+ ```ts
524
+ const isValid = _isValidDateTime('2025-04-09T12:30:00');
525
+ ```
942
526
 
527
+ ### ✅ **_isValidDateString**
528
+ Checks if the string can be parsed as a valid date.
943
529
  ```ts
944
- const isEqual = _deepCompareArrays(arr1, arr2);
530
+ const isValid = _isValidDateString('2025-04-09');
945
531
  ```
946
532
 
947
- ---
533
+ ### ✅ **_isValidEmail**
534
+ Checks if a string is a valid email address.
535
+ ```ts
536
+ const isValid = _isValidEmail('user@example.com');
537
+ ```
948
538
 
949
- ✅ **_updateObjectInArray**
950
- Updates a matching object in an array by key-value.
539
+ ### ✅ **_isValidEvent**
540
+ Checks if the input is an instance of `Event`.
541
+ ```ts
542
+ const isValid = _isValidEvent(new Event('click'));
543
+ ```
951
544
 
545
+ ### ✅ **_isValidFile**
546
+ Checks if the input is a `File`.
952
547
  ```ts
953
- const updated = _updateObjectInArray(users, 'id', '123', { name: 'New Name' });
548
+ const isValid = _isValidFile(new File([''], 'file.txt'));
954
549
  ```
955
550
 
956
- ---
551
+ ### ✅ **_isValidFormData**
552
+ Checks if the input is a `FormData` instance.
553
+ ```ts
554
+ const isValid = _isValidFormData(new FormData());
555
+ ```
957
556
 
958
- ✅ **_getKeyByValue**
959
- Returns the first key in an object with the matching value.
557
+ ### ✅ **_isValidFunction**
558
+ Checks if the input is a valid function.
559
+ ```ts
560
+ const isValid = _isValidFunction(() => {});
561
+ ```
960
562
 
563
+ ### ✅ **_isValidHexColor**
564
+ Checks if a string is a valid hex color code.
961
565
  ```ts
962
- const key = _getKeyByValue(obj, 'targetValue');
566
+ const isValid = _isValidHexColor('#FF5733');
963
567
  ```
964
568
 
965
- ---
569
+ ### ✅ **_isValidHTMLCollection**
570
+ Checks if the input is an `HTMLCollection`.
571
+ ```ts
572
+ const isValid = _isValidHTMLCollection(document.forms);
573
+ ```
966
574
 
967
- ✅ **_getValueByKey**
968
- Returns the value of a key from an object.
575
+ ### ✅ **_isValidHTMLElement**
576
+ Checks if the input is an instance of `HTMLElement`.
577
+ ```ts
578
+ const isValid = _isValidHTMLElement(document.body);
579
+ ```
969
580
 
581
+ ### ✅ **_isValidIP**
582
+ Checks if a string is a valid IPv4 address.
970
583
  ```ts
971
- const value = _getValueByKey(obj, 'username');
584
+ const isValid = _isValidIP('192.168.1.1');
972
585
  ```
973
586
 
974
- ---
587
+ ### ✅ **_isValidJSON**
588
+ Checks if a string is valid JSON.
589
+ ```ts
590
+ const isValid = _isValidJSON('{"name":"John"}');
591
+ ```
975
592
 
976
- ✅ **_getKeysByValue**
977
- Finds all keys in an object with a specific value.
593
+ ### ✅ **_isValidMacAddress**
594
+ Checks if a string is a valid MAC address.
595
+ ```ts
596
+ const isValid = _isValidMacAddress('00:1A:2B:3C:4D:5E');
597
+ ```
978
598
 
599
+ ### ✅ **_isValidNode**
600
+ Checks if the input is a `Node`.
979
601
  ```ts
980
- const keys = _getKeysByValue(obj, 'active');
602
+ const isValid = _isValidNode(document.createTextNode('text'));
981
603
  ```
982
604
 
983
- ---
605
+ ### ✅ **_isValidNodeList**
606
+ Checks if the input is a `NodeList`.
607
+ ```ts
608
+ const isValid = _isValidNodeList(document.querySelectorAll('div'));
609
+ ```
984
610
 
985
- ✅ **_escapeRegExpMatch**
986
- Escapes special characters for regex matching.
611
+ ### ✅ **_isValidNumber**
612
+ Checks if the input is a valid number.
613
+ ```ts
614
+ const isValid = _isValidNumber(123.45);
615
+ ```
987
616
 
617
+ ### ✅ **_isValidPassword**
618
+ Checks if a password has 8+ characters, at least 1 letter and 1 number.
988
619
  ```ts
989
- const escaped = _escapeRegExpMatch('a+b*c');
620
+ const isValid = _isValidPassword('Abc12345');
990
621
  ```
991
622
 
992
- ---
623
+ ### ✅ **_isValidPhoneNumber**
624
+ Checks if a string is a valid international phone number (10–15 digits).
625
+ ```ts
626
+ const isValid = _isValidPhoneNumber('+919876543210');
627
+ ```
993
628
 
994
- ✅ **_isExactMatch**
995
- Checks if a string contains an exact word match using regex.
629
+ ### ✅ **_isValidPromise**
630
+ Checks if the input is a `Promise`.
631
+ ```ts
632
+ const isValid = _isValidPromise(Promise.resolve());
633
+ ```
996
634
 
635
+ ### ✅ **_isValidRegExp**
636
+ Checks if the input is a regular expression.
997
637
  ```ts
998
- const match = _isExactMatch('The quick brown fox', 'quick');
638
+ const isValid = _isValidRegExp(/abc/);
999
639
  ```
1000
640
 
1001
- ---
641
+ ### ✅ **_isValidString**
642
+ Checks if the input is a non-empty string.
643
+ ```ts
644
+ const isValid = _isValidString('Hello');
645
+ ```
1002
646
 
1003
- ✅ **_bytesToSize**
1004
- Converts byte size into a human-readable format.
647
+ ### ✅ **_isValidTime**
648
+ Checks if a string is a valid 24-hour `HH:mm` format.
649
+ ```ts
650
+ const isValid = _isValidTime('23:59');
651
+ ```
1005
652
 
653
+ ### ✅ **_isValidURL**
654
+ Checks if a string is a valid URL format.
1006
655
  ```ts
1007
- const size = _bytesToSize(1024); // "1 KB"
656
+ const isValid = _isValidURL('https://example.com');
1008
657
  ```
1009
658
 
1010
- ---
659
+ ### ✅ **_isValidURLSearchParams**
660
+ Checks if the input is a `URLSearchParams` instance.
661
+ ```ts
662
+ const isValid = _isValidURLSearchParams(new URLSearchParams());
663
+ ```
1011
664
 
1012
- ✅ **_swapArrayByKey**
1013
- Sorts an array in descending order based on a key.
665
+ ### ✅ **_isValidUsername**
666
+ Checks if a username is 3+ characters and contains only letters, numbers, dots, underscores, or hyphens.
667
+ ```ts
668
+ const isValid = _isValidUsername('john_doe');
669
+ ```
1014
670
 
671
+ ### ✅ **_isValidUUID**
672
+ Checks if a string is a valid UUID (v1 to v5).
1015
673
  ```ts
1016
- const sorted = _swapArrayByKey(data, 'score');
674
+ const isValid = _isValidUUID('550e8400-e29b-41d4-a716-446655440000');
1017
675
  ```
1018
676
 
1019
677
  ---
1020
678
 
1021
- **_allowDecimalKeys**
1022
- Allows only decimal input and valid control keys.
679
+ ## Security & Encryption Functions
1023
680
 
681
+ ### ✅ **_decryptJson**
682
+ Decrypts AES-encrypted JSON string using a secret key.
1024
683
  ```ts
1025
- <input onKeyDown={_allowDecimalKeys} />
684
+ const decrypted = _decryptJson(encryptedString, "secret123");
1026
685
  ```
1027
686
 
1028
- ---
687
+ ### ✅ **_decryptString**
688
+ Decrypts an AES-encrypted string using the provided IV and secret key.
689
+ ```ts
690
+ const plainText = _decryptString(ciphertext, iv, "secretKey");
691
+ ```
1029
692
 
1030
- ✅ **_allowAlphaKeys**
1031
- Allows only alphabetic input and valid control keys.
693
+ ### ✅ **_encryptJson**
694
+ Encrypts a JSON object using AES encryption with a secret key.
695
+ ```ts
696
+ const encrypted = _encryptJson({ name: "John" }, "secret123");
697
+ ```
1032
698
 
699
+ ### ✅ **_encryptPayload**
700
+ Encrypts a full payload using a randomly generated key and IV, secured by a static key.
1033
701
  ```ts
1034
- <input onKeyDown={_allowAlphaKeys} />
702
+ const payload = _encryptPayload({ id: 1 }, "mainSecretKey");
1035
703
  ```
1036
704
 
1037
- ---
705
+ ### ✅ **_encryptString**
706
+ Encrypts a plain string using AES encryption, with optional random IV.
707
+ ```ts
708
+ const result = _encryptString("mySecretText", "secretKey");
709
+ ```
1038
710
 
1039
- ✅ **_handlePasteDecimalKeys**
1040
- Prevents pasting invalid decimal values.
711
+ ### ✅ **_escapeHTML**
712
+ Escapes special HTML characters to prevent injection or rendering issues.
713
+ ```ts
714
+ const safeHTML = _escapeHTML('<div class="test">Tom & Jerry</div>');
715
+ // Output: '&lt;div class=&quot;test&quot;&gt;Tom &amp; Jerry&lt;/div&gt;'
716
+ ```
1041
717
 
718
+ ### ✅ **_generatePassword**
719
+ Generates a strong random password with mixed characters.
1042
720
  ```ts
1043
- <input onPaste={_handlePasteDecimalKeys} />
721
+ const newPassword = _generatePassword(12);
1044
722
  ```
1045
723
 
1046
724
  ---
1047
725
 
1048
- **_handlePasteAlphabetKeys**
1049
- Prevents pasting non-alphabetic characters.
726
+ ## Event & DOM Functions
1050
727
 
728
+ ### ✅ **_addEventListenerToElement**
729
+ Attaches an event listener to a DOM element.
1051
730
  ```ts
1052
- <input onPaste={_handlePasteAlphabetKeys} />
731
+ _addEventListenerToElement('#my-btn', 'click', handleClick);
1053
732
  ```
1054
733
 
1055
- ---
734
+ ### ✅ **_allowAlphaKeys**
735
+ Allows only alphabetic input and valid control keys.
736
+ ```ts
737
+ <input onKeyDown={_allowAlphaKeys} />
738
+ ```
1056
739
 
1057
- ✅ **_allowAlphaNumericKeys**
740
+ ### ✅ **_allowAlphaNumericKeys**
1058
741
  Allows only alphanumeric keys during typing.
1059
-
1060
742
  ```ts
1061
743
  document.addEventListener('keydown', _allowAlphaNumericKeys);
1062
744
  ```
1063
745
 
1064
- ---
1065
-
1066
- ✅ **_onWindowLoad**
1067
-
1068
- Executes the callback when the **entire window is fully loaded**, including all images and assets.
1069
-
746
+ ### ✅ **_allowDecimalKeys**
747
+ Allows only decimal input and valid control keys.
1070
748
  ```ts
1071
- // 🔍 Run when everything (DOM + images) is fully loaded
1072
- _onWindowLoad(() => {
1073
- console.log('Window fully loaded!');
1074
- });
749
+ <input onKeyDown={_allowDecimalKeys} />
1075
750
  ```
1076
751
 
1077
- ---
1078
-
1079
- ✅ **_onDOMLoad**
1080
-
1081
- Executes the callback when the **DOM is fully parsed**, but before images and other resources are necessarily loaded.
1082
-
752
+ ### ✅ **_clearNode**
753
+ Hides specific sibling DOM nodes relative to a base element.
1083
754
  ```ts
1084
- // 🔍 Run when DOM is ready for manipulation
1085
- _onDOMLoad(() => {
1086
- const el = document.getElementById('app');
1087
- console.log('DOM ready:', el);
1088
- });
755
+ _clearNode('.my-element', [{ type: 'previous', steps: 1 }]);
1089
756
  ```
1090
757
 
1091
- ---
1092
-
1093
- ✅ **_onFullReload**
1094
-
1095
- Executes the callback **only when the page is reloaded** (not on SPA route changes or soft navigation).
758
+ ### ✅ **_cloneElement**
759
+ Clones a DOM element.
760
+ ```ts
761
+ const clone = _cloneElement('.to-clone');
762
+ ```
1096
763
 
764
+ ### ✅ **_domSelector**
765
+ Selects a single or all DOM elements matching a CSS selector.
1097
766
  ```ts
1098
- // 🔄 Run only on a full page reload (F5 or browser refresh)
1099
- _onFullReload(() => {
1100
- console.log('Page was fully reloaded.');
1101
- });
767
+ const el = _domSelector('#myElement');
768
+ const elements = _domSelector('.list-item', true);
1102
769
  ```
1103
770
 
1104
- ---
771
+ ### ✅ **_getChildElements**
772
+ Returns child elements of a selector.
773
+ ```ts
774
+ const children = _getChildElements('.container');
775
+ ```
1105
776
 
1106
- ✅ **_getQueryString**
777
+ ### ✅ **_getElementAttribute**
778
+ Gets the value of an element's attribute.
779
+ ```ts
780
+ const id = _getElementAttribute('.item', 'data-id');
781
+ ```
1107
782
 
1108
- Returns the query string from the current URL, supporting both `?search` and `#hash?search` formats.
783
+ ### **_getElementsByClass**
784
+ Returns elements with a given class.
785
+ ```ts
786
+ const elements = _getElementsByClass('my-class');
787
+ ```
1109
788
 
789
+ ### ✅ **_getElementsByTag**
790
+ Returns elements with a given tag name.
1110
791
  ```ts
1111
- // 🔍 Get current query string
1112
- const query = _getQueryString();
1113
- console.log('Query string:', query); // Example: ?id=123
792
+ const buttons = _getElementsByTag('button');
1114
793
  ```
1115
794
 
1116
- ---
1117
-
1118
- ✅ **_domSelector**
1119
- Selects a single or all DOM elements matching a CSS selector.
795
+ ### ✅ **_getParent**
796
+ Returns parent of a DOM element.
797
+ ```ts
798
+ const parent = _getParent('.child');
799
+ ```
1120
800
 
801
+ ### ✅ **_getScrollPosition**
802
+ Returns current window scroll position.
1121
803
  ```ts
1122
- // 🔍 Select DOM Element
1123
- const el = _domSelector('#myElement');
804
+ const { scrollX, scrollY } = _getScrollPosition();
805
+ ```
1124
806
 
1125
- // 🔍 Select All DOM Elements
1126
- const elements = _domSelector('.list-item', true);
807
+ ### **_handlePasteAlphabetKeys**
808
+ Prevents pasting non-alphabetic characters.
809
+ ```ts
810
+ <input onPaste={_handlePasteAlphabetKeys} />
1127
811
  ```
1128
812
 
1129
- ---
813
+ ### ✅ **_handlePasteDecimalKeys**
814
+ Prevents pasting invalid decimal values.
815
+ ```ts
816
+ <input onPaste={_handlePasteDecimalKeys} />
817
+ ```
1130
818
 
1131
- ✅ **_hideElement**
819
+ ### ✅ **_hideElement**
1132
820
  Hides a DOM element by setting its `display` style to `'none'`.
1133
-
1134
821
  ```ts
1135
- // 🙈 Hide Element
1136
822
  _hideElement('#modal');
1137
823
  ```
1138
824
 
1139
- ---
1140
-
1141
- ✅ **_showElement**
1142
- Displays a hidden DOM element using the provided `displayType` (default is `'block'`).
1143
-
825
+ ### ✅ **_insertHTML**
826
+ Injects HTML at a specific position.
1144
827
  ```ts
1145
- // 👁️ Show Element
1146
- _showElement('#modal');
1147
-
1148
- // 👁️ Show with Custom Display Type
1149
- _showElement('#modal', 'flex');
828
+ _insertHTML('#box', 'beforeend', '<div>Hello</div>');
1150
829
  ```
1151
830
 
1152
- ---
1153
-
1154
- ✅ **_removeElement**
1155
- Removes the **first matched** DOM element from the document.
1156
-
831
+ ### ✅ **_isDocumentLoaded**
832
+ Checks if the document has fully loaded.
1157
833
  ```ts
1158
- // Remove Element
1159
- _removeElement('#banner');
834
+ if (_isDocumentLoaded()) { /* safe to run code */ }
1160
835
  ```
1161
836
 
1162
- ---
1163
-
1164
- ✅ **_removeNode**
1165
- Removes **all matched** DOM elements from the document.
1166
-
837
+ ### ✅ **_isElementInViewport**
838
+ Checks if element is visible in viewport.
1167
839
  ```ts
1168
- // 🧹 Remove All Matching Nodes
1169
- _removeNode('.temp-item');
840
+ const isVisible = _isElementInViewport('.my-element');
1170
841
  ```
1171
842
 
1172
- ---
1173
-
1174
- ✅ **_removeSafeElement**
1175
- Safely removes an element if it exists and has a parent.
1176
-
843
+ ### ✅ **_isElementPresent**
844
+ Checks if an element exists in the DOM.
1177
845
  ```ts
1178
- // 🛡️ Safe Remove Element
1179
- _removeSafeElement('#popup');
846
+ const exists = _isElementPresent('.my-element');
1180
847
  ```
1181
848
 
1182
- ---
1183
-
1184
- ✅ **_clearNode**
1185
- Hides specific sibling DOM nodes relative to a base element.
1186
-
849
+ ### ✅ **_onDOMLoad**
850
+ Executes the callback when the **DOM is fully parsed**, but before images and other resources are necessarily loaded.
1187
851
  ```ts
1188
- _clearNode('.my-element', [{ type: 'previous', steps: 1 }]);
852
+ _onDOMLoad(() => {
853
+ const el = document.getElementById('app');
854
+ console.log('DOM ready:', el);
855
+ });
1189
856
  ```
1190
857
 
1191
- ---
1192
-
1193
- ✅ **_isElementPresent**
1194
- Checks if an element exists in the DOM.
858
+ ### ✅ **_onFullReload**
859
+ Executes the callback **only when the page is reloaded** (not on SPA route changes or soft navigation).
1195
860
  ```ts
1196
- const exists = _isElementPresent('.my-element');
861
+ _onFullReload(() => {
862
+ console.log('Page was fully reloaded.');
863
+ });
1197
864
  ```
1198
- ---
1199
865
 
1200
- ✅ **_removeElement**
1201
- Removes an element from the DOM.
866
+ ### ✅ **_onWindowLoad**
867
+ Executes the callback when the **entire window is fully loaded**, including all images and assets.
868
+ ```ts
869
+ _onWindowLoad(() => {
870
+ console.log('Window fully loaded!');
871
+ });
872
+ ```
1202
873
 
874
+ ### ✅ **_reloadAfterLoad**
875
+ Reloads page after a delay post-load.
1203
876
  ```ts
1204
- _removeElement('#to-remove');
877
+ _reloadAfterLoad(3000); // Reload 3s after load
1205
878
  ```
1206
879
 
1207
- ---
1208
- **_getParent**
1209
- Returns parent of a DOM element.
880
+ ### ✅ **_removeAllChildren**
881
+ Clears all child nodes of an element.
1210
882
  ```ts
1211
- const parent = _getParent('.child');
883
+ _removeAllChildren('#container');
1212
884
  ```
1213
- ---
1214
- ✅ **_getChildElements**
1215
- Returns child elements of a selector.
885
+
886
+ ### ✅ **_removeElement**
887
+ Removes the **first matched** DOM element from the document.
1216
888
  ```ts
1217
- const children = _getChildElements('.container');
889
+ _removeElement('#banner');
1218
890
  ```
1219
- ---
1220
- ✅ **_handleParentsMenu**
1221
- Recursively updates parent menu's assigned state and permissions based on children.
891
+
892
+ ### ✅ **_removeElementAttribute**
893
+ Removes an attribute from an element.
1222
894
  ```ts
1223
- _handleParentsMenu(menuList, menuId);
895
+ _removeElementAttribute('.item', 'data-id');
1224
896
  ```
1225
- ---
1226
- ✅ **_handleParentNode**
1227
- Recursively updates parent permissions based on child permissions.
897
+
898
+ ### ✅ **_removeEventListenerFromElement**
899
+ Removes a specific event listener.
1228
900
  ```ts
1229
- _handleParentNode(menuList, menuId, permissionKey);
901
+ _removeEventListenerFromElement('#my-btn', 'click', handleClick);
1230
902
  ```
1231
- ---
1232
- ✅ **_handleChildrenMenu**
1233
- Recursively sets assigned state and permissions of child nodes.
903
+
904
+ ### ✅ **_removeNode**
905
+ Removes **all matched** DOM elements from the document.
1234
906
  ```ts
1235
- _handleChildrenMenu(menuList, parentKey, checked);
907
+ _removeNode('.temp-item');
1236
908
  ```
1237
909
 
1238
- ---
910
+ ### ✅ **_removeSafeElement**
911
+ Safely removes an element if it exists and has a parent.
912
+ ```ts
913
+ _removeSafeElement('#popup');
914
+ ```
1239
915
 
1240
- ✅ **_replaceContent**
916
+ ### ✅ **_replaceContent**
1241
917
  Replaces inner HTML of an element.
1242
-
1243
918
  ```ts
1244
919
  _replaceContent('#content', '<p>New content</p>');
1245
920
  ```
1246
921
 
1247
- ---
1248
-
1249
- ✅ **_cloneElement**
1250
- Clones a DOM element.
1251
-
922
+ ### ✅ **_runOnIframeLoad**
923
+ Runs a callback when iframe finishes loading.
1252
924
  ```ts
1253
- const clone = _cloneElement('.to-clone');
925
+ _runOnIframeLoad('#myIframe', () => console.log('Loaded'));
1254
926
  ```
1255
927
 
1256
- ---
1257
-
1258
- ✅ **_scrollToElement**
928
+ ### ✅ **_scrollToElement**
1259
929
  Scrolls smoothly to an element.
1260
-
1261
930
  ```ts
1262
931
  _scrollToElement('#target');
1263
932
  ```
1264
933
 
1265
- ---
1266
-
1267
- ✅ **_isElementInViewport**
1268
- Checks if element is visible in viewport.
1269
-
934
+ ### ✅ **_scrollToTop**
935
+ Scrolls the page smoothly to the top.
1270
936
  ```ts
1271
- const isVisible = _isElementInViewport('.my-element');
937
+ _scrollToTop();
1272
938
  ```
1273
939
 
1274
- ---
940
+ ### ✅ **_setElementAttribute**
941
+ Sets an attribute on a DOM element.
942
+ ```ts
943
+ _setElementAttribute('.item', 'data-id', '123');
944
+ ```
1275
945
 
1276
- ✅ **_setElementDisabled**
946
+ ### ✅ **_setElementDisabled**
1277
947
  Enables or disables a DOM element.
1278
-
1279
948
  ```ts
1280
949
  _setElementDisabled('#submit-btn', true);
1281
950
  ```
1282
951
 
1283
- ---
1284
-
1285
- ✅ **_addEventListenerToElement**
1286
- Attaches an event listener to a DOM element.
1287
-
952
+ ### ✅ **_setMultipleStyles**
953
+ Applies multiple CSS styles to an element.
1288
954
  ```ts
1289
- _addEventListenerToElement('#my-btn', 'click', handleClick);
955
+ _setMultipleStyles('.card', { color: 'red', fontWeight: 'bold' });
1290
956
  ```
1291
957
 
1292
- ---
1293
-
1294
- ✅ **_removeEventListenerFromElement**
1295
- Removes a specific event listener.
1296
-
958
+ ### ✅ **_showElement**
959
+ Displays a hidden DOM element using the provided `displayType` (default is `'block'`).
1297
960
  ```ts
1298
- _removeEventListenerFromElement('#my-btn', 'click', handleClick);
961
+ _showElement('#modal');
962
+ _showElement('#modal', 'flex');
1299
963
  ```
1300
964
 
1301
965
  ---
1302
966
 
1303
- **_getElementAttribute**
1304
- Gets the value of an element’s attribute.
967
+ ## File & Data Functions
1305
968
 
969
+ ### ✅ **_base64ToBlob**
970
+ Converts a base64-encoded string into a Blob object.
1306
971
  ```ts
1307
- const id = _getElementAttribute('.item', 'data-id');
972
+ const blob = _base64ToBlob(base64String);
1308
973
  ```
1309
974
 
1310
- ---
1311
-
1312
- ✅ **_setElementAttribute**
1313
- Sets an attribute on a DOM element.
1314
-
975
+ ### ✅ **_downloadBase64File**
976
+ Downloads any base64-encoded data as a file with a specified filename and extension.
1315
977
  ```ts
1316
- _setElementAttribute('.item', 'data-id', '123');
1317
- ```
1318
-
1319
- ---
978
+ const base64Image = 'iVBORw0KGgoAAAANSUhEUgAAA...';
979
+ downloadBase64File(base64Image, 'my-picture.png');
1320
980
 
1321
- **_removeElementAttribute**
1322
- Removes an attribute from an element.
981
+ const base64PDF = 'JVBERi0xLjQKJeLjz9MNCjEgMCBvYmoK...';
982
+ downloadBase64File(base64PDF, 'invoice.pdf');
983
+ ```
1323
984
 
985
+ ### ✅ **_downloadBlob**
986
+ Triggers download of a Blob object.
1324
987
  ```ts
1325
- _removeElementAttribute('.item', 'data-id');
988
+ _downloadBlob(blob, 'myfile.pdf');
1326
989
  ```
1327
990
 
1328
- ---
1329
-
1330
- ✅ **_removeAllChildren**
1331
- Clears all child nodes of an element.
1332
-
991
+ ### ✅ **_exportExcel**
992
+ Exports JSON data to an Excel or CSV file.
1333
993
  ```ts
1334
- _removeAllChildren('#container');
994
+ await _exportExcel({
995
+ data: [
996
+ { name: 'siya', age: 5 },
997
+ { name: 'riya', age: 6 },
998
+ ],
999
+ filename: 'users',
1000
+ })
1001
+ .then(() => console.log('Export successful'))
1002
+ .catch((err) => console.error('Export failed:', err.message));
1335
1003
  ```
1336
1004
 
1337
- ---
1338
-
1339
- ✅ **_getElementsByClass**
1340
- Returns elements with a given class.
1341
-
1005
+ ### ✅ **_fileToBase64**
1006
+ Converts a file to a base64-encoded string.
1342
1007
  ```ts
1343
- const elements = _getElementsByClass('my-class');
1008
+ const base64 = await _fileToBase64(file);
1344
1009
  ```
1345
1010
 
1346
- ---
1011
+ ### ✅ **_importExcel**
1012
+ Imports data from an Excel file.
1013
+ ```ts
1014
+ const fileInputHandler = async (event: React.ChangeEvent<HTMLInputElement>) => {
1015
+ const { data, error } = await _importExcel(event);
1347
1016
 
1348
- **_getElementsByTag**
1349
- Returns elements with a given tag name.
1017
+ if (error) {
1018
+ console.error('Error:', error.message);
1019
+ return;
1020
+ }
1021
+
1022
+ if (data) {
1023
+ console.log('Successfully parsed data:', data);
1024
+ }
1025
+ };
1026
+ ```
1350
1027
 
1028
+ ### ✅ **_importFile**
1029
+ Supports multiple types of result formats: base64, buffer, file, unit8array.
1351
1030
  ```ts
1352
- const buttons = _getElementsByTag('button');
1031
+ const handleChangeFile = async (file) => {
1032
+ const result = await _importFile(file, 'base64');
1033
+ console.log('result', result);
1034
+ };
1353
1035
  ```
1354
1036
 
1355
1037
  ---
1356
1038
 
1357
- **_setMultipleStyles**
1358
- Applies multiple CSS styles to an element.
1039
+ ## Browser & Storage Functions
1359
1040
 
1041
+ ### ✅ **_clearRouteState**
1042
+ Removes the route state from the browser's history without reloading the page, keeping the current path intact.
1360
1043
  ```ts
1361
- _setMultipleStyles('.card', { color: 'red', fontWeight: 'bold' });
1044
+ _clearRouteState('/dashboard');
1362
1045
  ```
1363
1046
 
1364
- ---
1365
-
1366
- ✅ **_insertHTML**
1367
- Injects HTML at a specific position.
1368
-
1047
+ ### ✅ **_copyText**
1048
+ Copies the provided text to the clipboard, using modern APIs with a fallback for older browsers.
1369
1049
  ```ts
1370
- _insertHTML('#box', 'beforeend', '<div>Hello</div>');
1050
+ const success = await _copyText("Hello, clipboard!");
1051
+ if (success) {
1052
+ console.log("Text copied successfully");
1053
+ }
1371
1054
  ```
1372
1055
 
1373
- ---
1374
-
1375
- ✅ **_isDocumentLoaded**
1376
- Checks if the document has fully loaded.
1377
-
1056
+ ### ✅ **_getBrowserInfo**
1057
+ Returns the name of the browser (e.g., Chrome, Firefox).
1378
1058
  ```ts
1379
- if (_isDocumentLoaded()) { /* safe to run code */ }
1059
+ const browser = _getBrowserInfo();
1380
1060
  ```
1381
1061
 
1382
- ---
1383
-
1384
- ✅ **_runOnIframeLoad**
1385
- Runs a callback when iframe finishes loading.
1386
-
1062
+ ### ✅ **_getCookie**
1063
+ Retrieves a cookie value by its name.
1387
1064
  ```ts
1388
- _runOnIframeLoad('#myIframe', () => console.log('Loaded'));
1065
+ const token = _getCookie('auth_token');
1389
1066
  ```
1390
1067
 
1391
- ---
1392
-
1393
- ✅ **_reloadAfterLoad**
1394
- Reloads page after a delay post-load.
1395
-
1068
+ ### ✅ **_getQueryString**
1069
+ Returns the query string from the current URL, supporting both `?search` and `#hash?search` formats.
1396
1070
  ```ts
1397
- _reloadAfterLoad(3000); // Reload 3s after load
1071
+ const query = _getQueryString();
1072
+ console.log('Query string:', query); // Example: ?id=123
1398
1073
  ```
1399
1074
 
1400
- ---
1401
-
1402
- ✅ **_isValidEmail**
1403
- Checks if a string is a valid email address.
1404
-
1075
+ ### ✅ **_getStorage**
1076
+ Handles local/session storage actions like GET, SET, REMOVE, CLEAR.
1405
1077
  ```ts
1406
- // 📧 Validate Email
1407
- const isValid = _isValidEmail('user@example.com');
1078
+ const data = _getStorage({ action: 'GET', type: 'local', key: 'user' });
1408
1079
  ```
1409
1080
 
1410
- ---
1411
-
1412
- ✅ **_isValidPhoneNumber**
1413
- Checks if a string is a valid international phone number (10–15 digits).
1414
-
1081
+ ### ✅ **_isMobile**
1082
+ Detects if the current device is a mobile device.
1415
1083
  ```ts
1416
- // 📱 Validate Phone Number
1417
- const isValid = _isValidPhoneNumber('+919876543210');
1084
+ const mobile = _isMobile();
1418
1085
  ```
1419
1086
 
1420
- ---
1421
-
1422
- ✅ **_isValidURL**
1423
- Checks if a string is a valid URL format.
1087
+ ### ✅ **_pasteText**
1088
+ Retrieves and returns the current text content from the clipboard, using modern APIs with a fallback for older browsers.
1089
+ ```ts
1090
+ const text = await _pasteText();
1091
+ if (text) {
1092
+ console.log("Pasted text:", text);
1093
+ }
1094
+ ```
1424
1095
 
1096
+ ### ✅ **_setCookie**
1097
+ Sets a cookie with a name, value, and expiry (in days).
1425
1098
  ```ts
1426
- // 🌐 Validate URL
1427
- const isValid = _isValidURL('https://example.com');
1099
+ _setCookie('auth_token', 'abc123', 7);
1428
1100
  ```
1429
1101
 
1430
1102
  ---
1431
1103
 
1432
- **_isValidDate**
1433
- Checks if a string matches the `YYYY-MM-DD` date format.
1104
+ ## String & Text Functions
1434
1105
 
1106
+ ### ✅ **_bytesToSize**
1107
+ Converts byte size into a human-readable format.
1435
1108
  ```ts
1436
- // 📅 Validate Date
1437
- const isValid = _isValidDate('2025-04-09');
1109
+ const size = _bytesToSize(1024); // "1 KB"
1438
1110
  ```
1439
1111
 
1440
- ---
1441
-
1442
- ✅ **_isValidTime**
1443
- Checks if a string is a valid 24-hour `HH:mm` format.
1444
-
1112
+ ### ✅ **_capitalize**
1113
+ Capitalizes the first character of a string.
1445
1114
  ```ts
1446
- // Validate Time
1447
- const isValid = _isValidTime('23:59');
1115
+ const name = _capitalize("john"); // "John"
1448
1116
  ```
1449
1117
 
1450
- ---
1451
-
1452
- ✅ **_isValidDateTime**
1453
- Checks if a string matches the `YYYY-MM-DDTHH:mm:ss` format.
1454
-
1118
+ ### ✅ **_countWords**
1119
+ Counts the number of words in a string by trimming whitespace and splitting by spaces.
1455
1120
  ```ts
1456
- // 🕒 Validate DateTime
1457
- const isValid = _isValidDateTime('2025-04-09T12:30:00');
1121
+ const wordCount = _countWords(' Hello world! How are you? '); // 5
1458
1122
  ```
1459
1123
 
1460
- ---
1461
-
1462
- ✅ **_isValidDateRange**
1463
- Checks if the start date is earlier than or equal to the end date.
1464
-
1124
+ ### ✅ **_decodeURI**
1125
+ Decodes an encoded URI component back to its original readable string format.
1465
1126
  ```ts
1466
- // 🔄 Validate Date Range
1467
- const isValid = _isValidDateRange('2025-01-01', '2025-12-31');
1127
+ const decoded = _decodeURI('hello%20world%402024'); // 'hello world@2024'
1468
1128
  ```
1469
1129
 
1470
- ---
1471
-
1472
- ✅ **_isValidPassword**
1473
- Checks if a password has 8+ characters, at least 1 letter and 1 number.
1474
-
1130
+ ### ✅ **_encodeURI**
1131
+ Encodes a URI component by escaping special characters to make it safe for use in URLs.
1475
1132
  ```ts
1476
- // 🔐 Validate Password
1477
- const isValid = _isValidPassword('Abc12345');
1133
+ const encoded = _encodeURI('hello world@2024'); // 'hello%20world%402024'
1478
1134
  ```
1479
1135
 
1480
- ---
1481
-
1482
- ✅ **_isValidUsername**
1483
- Checks if a username is 3+ characters and contains only letters, numbers, dots, underscores, or hyphens.
1484
-
1136
+ ### ✅ **_escapeRegExpMatch**
1137
+ Escapes special characters for regex matching.
1485
1138
  ```ts
1486
- // 👤 Validate Username
1487
- const isValid = _isValidUsername('john_doe');
1139
+ const escaped = _escapeRegExpMatch('a+b*c');
1488
1140
  ```
1489
1141
 
1490
- ---
1491
-
1492
- ✅ **_isValidCreditCard**
1493
- Checks if a string matches known credit card patterns.
1494
-
1142
+ ### ✅ **_isExactMatch**
1143
+ Checks if a string contains an exact word match using regex.
1495
1144
  ```ts
1496
- // 💳 Validate Credit Card
1497
- const isValid = _isValidCreditCard('4111111111111111');
1145
+ const match = _isExactMatch('The quick brown fox', 'quick');
1498
1146
  ```
1499
1147
 
1500
- ---
1501
-
1502
- ✅ **_isValidHexColor**
1503
- Checks if a string is a valid hex color code.
1504
-
1148
+ ### ✅ **_parseJSON**
1149
+ Safely parses a JSON string into an object.
1505
1150
  ```ts
1506
- // 🎨 Validate Hex Color
1507
- const isValid = _isValidHexColor('#FF5733');
1151
+ const obj = _parseJSON(jsonString);
1508
1152
  ```
1509
1153
 
1510
- ---
1511
-
1512
- ✅ **_isValidIP**
1513
- Checks if a string is a valid IPv4 address.
1514
-
1154
+ ### ✅ **_stringifyJSON**
1155
+ Safely converts an object to a JSON string.
1515
1156
  ```ts
1516
- // 🌐 Validate IP Address
1517
- const isValid = _isValidIP('192.168.1.1');
1157
+ const str = _stringifyJSON(obj);
1518
1158
  ```
1519
1159
 
1520
- ---
1521
-
1522
- ✅ **_isValidMacAddress**
1523
- Checks if a string is a valid MAC address.
1524
-
1160
+ ### ✅ **_toCamelCase**
1161
+ Converts kebab-case or snake_case to camelCase.
1525
1162
  ```ts
1526
- // 💻 Validate MAC Address
1527
- const isValid = _isValidMacAddress('00:1A:2B:3C:4D:5E');
1163
+ _toCamelCase('hello_world'); // helloWorld
1528
1164
  ```
1529
1165
 
1530
1166
  ---
1531
1167
 
1532
- **_isValidUUID**
1533
- Checks if a string is a valid UUID (v1 to v5).
1168
+ ## Date & Time Functions
1534
1169
 
1170
+ ### ✅ **_calculateTimeDifference**
1171
+ Returns difference between two dates in readable format.
1535
1172
  ```ts
1536
- // 🆔 Validate UUID
1537
- const isValid = _isValidUUID('550e8400-e29b-41d4-a716-446655440000');
1173
+ _calculateTimeDifference(start, end); // "1d 2h 3m 4s"
1538
1174
  ```
1539
1175
 
1540
- ---
1541
-
1542
- ✅ **_isValidBase64**
1543
- Checks if a string is a valid Base64-encoded value.
1544
-
1176
+ ### ✅ **_dateFormat**
1177
+ Formats a date using Moment.js with the specified format.
1545
1178
  ```ts
1546
- // 🧬 Validate Base64
1547
- const isValid = _isValidBase64('U29tZSB0ZXh0');
1179
+ const formatted = _dateFormat(new Date(), 'YYYY-MM-DD');
1548
1180
  ```
1549
1181
 
1550
- ---
1551
-
1552
- ✅ **_isValidJSON**
1553
- Checks if a string is valid JSON.
1554
-
1182
+ ### ✅ **_dateTransformer**
1183
+ Recursively formats all dates in an object or array.
1555
1184
  ```ts
1556
- // 📦 Validate JSON
1557
- const isValid = _isValidJSON('{"name":"John"}');
1185
+ const result = _dateTransformer(data);
1558
1186
  ```
1559
1187
 
1560
- ---
1561
-
1562
- ✅ **_isValidFunction**
1563
- Checks if the input is a valid function.
1564
-
1188
+ ### ✅ **_formatDate**
1189
+ Formats a date based on a custom pattern.
1565
1190
  ```ts
1566
- // 🛠️ Validate Function
1567
- const isValid = _isValidFunction(() => {});
1191
+ _formatDate(new Date(), 'YMD'); // e.g., "Apr 9, 2025"
1568
1192
  ```
1569
1193
 
1570
- ---
1571
-
1572
- ✅ **_isValidString**
1573
- Checks if the input is a non-empty string.
1574
-
1194
+ ### ✅ **_formatInternationalDate**
1195
+ Formats a date according to locale, timezone, and preset or custom format.
1575
1196
  ```ts
1576
- // ✏️ Validate String
1577
- const isValid = _isValidString('Hello');
1197
+ const formatted = _formatInternationalDate('2024-07-09T10:00:00Z', {
1198
+ country: 'IN',
1199
+ timezone: 'Asia/Kolkata',
1200
+ format: 'DATETIME_SHORT',
1201
+ }); // "9/7/2024, 3:30 pm"
1578
1202
  ```
1579
1203
 
1580
- ---
1581
-
1582
- ✅ **_isValidNumber**
1583
- Checks if the input is a valid number.
1584
-
1204
+ ### ✅ **_getFinancialYear**
1205
+ Returns the current financial year based on today's date.
1585
1206
  ```ts
1586
- // 🔢 Validate Number
1587
- const isValid = _isValidNumber(123.45);
1207
+ const fy = _getFinancialYear();
1588
1208
  ```
1589
1209
 
1590
- ---
1591
-
1592
- ✅ **_isValidBoolean**
1593
- Checks if the input is a boolean.
1594
-
1210
+ ### ✅ **_getStartStopTime**
1211
+ Returns the start and end datetime of a given date's month in specified format.
1595
1212
  ```ts
1596
- // Validate Boolean
1597
- const isValid = _isValidBoolean(true);
1213
+ const { startTime, stopTime } = _getStartStopTime(new Date());
1598
1214
  ```
1599
1215
 
1600
- ---
1601
-
1602
- ✅ **_isValidDateObject**
1603
- Checks if the input is a valid `Date` object.
1604
-
1216
+ ### ✅ **_getUTCTimestamp**
1217
+ Returns the UTC timestamp.
1605
1218
  ```ts
1606
- // 📆 Validate Date Object
1607
- const isValid = _isValidDateObject(new Date());
1219
+ const ts3 = getUTCTimestamp({ year: 2025, month: "December", day: 25, hour: 10, minute: 30 });
1220
+ console.log(new Date(ts3).toUTCString()); // Thu, 25 Dec 2025 10:30:00 GMT
1608
1221
  ```
1609
1222
 
1610
- ---
1611
-
1612
- ✅ **_isValidBlob**
1613
- Checks if the input is a `Blob`.
1614
-
1223
+ ### ✅ **_globalizeDateTime**
1224
+ Converts a date/time to a specific time zone and format.
1615
1225
  ```ts
1616
- // 🗂️ Validate Blob
1617
- const isValid = _isValidBlob(new Blob(['text']));
1226
+ const localized = _globalizeDateTime('2024-07-09T12:00:00', {
1227
+ timeZone: 'Asia/Kolkata',
1228
+ format: 'yyyy-MM-dd HH:mm',
1229
+ }); // "2024-07-09 17:30"
1618
1230
  ```
1619
1231
 
1620
- ---
1621
-
1622
- ✅ **_isLeapYear**
1623
-
1232
+ ### ✅ **_isLeapYear**
1624
1233
  Determines whether a given year is a leap year based on calendar rules.
1625
-
1626
1234
  ```ts
1627
- const isLeap = _isLeapYear(2024);
1628
- // Output: true
1235
+ const isLeap = _isLeapYear(2024); // true
1629
1236
  ```
1630
1237
 
1631
- ---
1632
-
1633
- ✅ **_isWeekend**
1634
-
1238
+ ### ✅ **_isWeekend**
1635
1239
  Checks if a given date falls on a weekend (Saturday or Sunday).
1636
-
1637
1240
  ```ts
1638
- const weekend = _isWeekend(new Date('2025-06-08'));
1639
- // Output: true // (Sunday)
1241
+ const weekend = _isWeekend(new Date('2025-06-08')); // true (Sunday)
1640
1242
  ```
1641
1243
 
1642
1244
  ---
1643
1245
 
1644
- ✅ **_removeFalsy**
1645
-
1646
- Removes all falsy values (`false`, `0`, `''`, `null`, `undefined`, `NaN`) from an array.
1647
1246
 
1247
+ ### ✅ **_calPercentage**
1248
+ Calculates the percentage of a value relative to total.
1648
1249
  ```ts
1649
- const cleaned = _removeFalsy([0, 1, false, 2, '', 3]);
1650
- // Output: [1, 2, 3]
1250
+ _calPercentage(40, 200); // 20
1651
1251
  ```
1652
1252
 
1653
- ---
1654
-
1655
- ✅ **_escapeHTML**
1656
-
1657
- Escapes special HTML characters to prevent injection or rendering issues.
1658
-
1253
+ ### ✅ **_convertToCurrency**
1254
+ Converts a number to a formatted currency string.
1659
1255
  ```ts
1660
- const safeHTML = _escapeHTML('<div class="test">Tom & Jerry</div>');
1661
- // Output: '&lt;div class=&quot;test&quot;&gt;Tom &amp; Jerry&lt;/div&gt;'
1256
+ const price = _convertToCurrency(2500, 'INR');
1662
1257
  ```
1663
1258
 
1664
- ---
1665
-
1666
- ✅ **_isValidFile**
1667
- Checks if the input is a `File`.
1668
-
1259
+ ### ✅ **_getPriceAfterTax**
1260
+ Adds tax to a given price.
1669
1261
  ```ts
1670
- // 📁 Validate File
1671
- const isValid = _isValidFile(new File([''], 'file.txt'));
1262
+ _getPriceAfterTax(100, 18); // 118
1672
1263
  ```
1673
1264
 
1674
- ---
1675
-
1676
- ✅ **_isValidRegExp**
1677
- Checks if the input is a regular expression.
1678
-
1265
+ ### ✅ **_thousandSeparator**
1266
+ Formats a number with thousand separators and fixed decimal precision.
1679
1267
  ```ts
1680
- // 🔍 Validate RegExp
1681
- const isValid = _isValidRegExp(/abc/);
1268
+ const formatted = _thousandSeparator(1234567.89);
1682
1269
  ```
1683
1270
 
1684
1271
  ---
1685
1272
 
1686
- ✅ **_isValidPromise**
1687
- Checks if the input is a `Promise`.
1688
-
1273
+ ### ✅ **_alert**
1274
+ Shows a customizable alert modal.
1689
1275
  ```ts
1690
- // Validate Promise
1691
- const isValid = _isValidPromise(Promise.resolve());
1276
+ await _alert({ title: "Test", text: "Data save successfully!" });
1692
1277
  ```
1693
1278
 
1694
- ---
1695
-
1696
- ✅ **_isValidDateString**
1697
- Checks if the string can be parsed as a valid date.
1698
-
1279
+ ### ✅ **_asyncDebounce**
1280
+ Debounces an async function call.
1699
1281
  ```ts
1700
- // 🗓️ Validate Date String
1701
- const isValid = _isValidDateString('2025-04-09');
1282
+ const debouncedFn = _asyncDebounce(fetchData, 500);
1283
+ debouncedFn();
1702
1284
  ```
1703
1285
 
1704
- ---
1286
+ ### ✅ **_confirm**
1287
+ Shows a customizable confirm modal.
1288
+ ```ts
1289
+ const confirmed = await _confirm({
1290
+ title: "Are you sure?",
1291
+ text: "Do you really want to delete this item?",
1292
+ icon: "warning",
1293
+ confirmButtonText: "Yes, delete it",
1294
+ cancelButtonText: "No, cancel",
1295
+ });
1705
1296
 
1706
- **_isValidHTMLElement**
1707
- Checks if the input is an instance of `HTMLElement`.
1297
+ if (confirmed) {
1298
+ // proceed with delete
1299
+ } else {
1300
+ // cancelled
1301
+ }
1302
+ ```
1708
1303
 
1304
+ ### ✅ **_dynamicReducer**
1305
+ Creates a simple dynamic reducer using generic action handler logic.
1709
1306
  ```ts
1710
- // 🧱 Validate HTMLElement
1711
- const isValid = _isValidHTMLElement(document.body);
1307
+ const reducer = _dynamicReducer(initialState);
1712
1308
  ```
1713
1309
 
1714
- ---
1715
-
1716
- ✅ **_isValidEvent**
1717
- Checks if the input is an instance of `Event`.
1718
-
1310
+ ### ✅ **_generateUUID**
1311
+ Generates a unique UUID string using the browser's `crypto` API.
1719
1312
  ```ts
1720
- // 🎫 Validate Event
1721
- const isValid = _isValidEvent(new Event('click'));
1313
+ const id = _generateUUID();
1314
+ console.log(id); // e.g., "3b12f1df-5232-4e6b-8f36-3a4e5f7f8b84"
1722
1315
  ```
1723
1316
 
1724
- ---
1725
-
1726
- ✅ **_isValidNode**
1727
- Checks if the input is a `Node`.
1728
-
1317
+ ### ✅ **_genericReducer**
1318
+ A generic reducer accepting predefined handlers for each action type.
1729
1319
  ```ts
1730
- // 🌿 Validate Node
1731
- const isValid = _isValidNode(document.createTextNode('text'));
1320
+ const reducer = _genericReducer(initialState, customActions);
1732
1321
  ```
1733
1322
 
1734
- ---
1735
-
1736
- ✅ **_isValidNodeList**
1737
- Checks if the input is a `NodeList`.
1738
-
1323
+ ### ✅ **_handleApi**
1324
+ Wraps an API call with success and error handling, executing the appropriate callback based on the result.
1739
1325
  ```ts
1740
- // 📚 Validate NodeList
1741
- const isValid = _isValidNodeList(document.querySelectorAll('div'));
1326
+ _handleApi(
1327
+ getDetails({ name: 'sia' }),
1328
+ (res) => console.log(res),
1329
+ (err) => console.error(err)
1330
+ );
1742
1331
  ```
1743
1332
 
1744
- ---
1745
-
1746
- ✅ **_isValidHTMLCollection**
1747
- Checks if the input is an `HTMLCollection`.
1333
+ ### ✅ **_handleChildrenMenu**
1334
+ Recursively sets assigned state and permissions of child nodes.
1335
+ ```ts
1336
+ _handleChildrenMenu(menuList, parentKey, checked);
1337
+ ```
1748
1338
 
1339
+ ### ✅ **_handleParentNode**
1340
+ Recursively updates parent permissions based on child permissions.
1749
1341
  ```ts
1750
- // 🏗️ Validate HTMLCollection
1751
- const isValid = _isValidHTMLCollection(document.forms);
1342
+ _handleParentNode(menuList, menuId, permissionKey);
1752
1343
  ```
1753
1344
 
1754
- ---
1345
+ ### ✅ **_handleParentsMenu**
1346
+ Recursively updates parent menu's assigned state and permissions based on children.
1347
+ ```ts
1348
+ _handleParentsMenu(menuList, menuId);
1349
+ ```
1755
1350
 
1756
- ✅ **_isValidFormData**
1757
- Checks if the input is a `FormData` instance.
1351
+ ### ✅ **_handleSafe**
1352
+ Executes a synchronous or asynchronous action safely, handling errors and an optional `finally` block without breaking the application.
1353
+ ```ts
1354
+ await _handleSafe(
1355
+ async () => {
1356
+ await someAsyncTask();
1357
+ },
1358
+ (error) => {
1359
+ console.error('Error occurred:', error);
1360
+ },
1361
+ () => {
1362
+ console.log('Cleanup after execution');
1363
+ }
1364
+ );
1365
+ ```
1758
1366
 
1367
+ ### ✅ **_isNotEmpty**
1368
+ Checks if a given value is not empty — returns false for empty arrays, empty objects, and falsy values like null, undefined, false, or ''.
1759
1369
  ```ts
1760
- // 📝 Validate FormData
1761
- const isValid = _isValidFormData(new FormData());
1370
+ const isEmpty = _isNotEmpty([]);
1762
1371
  ```
1763
1372
 
1764
- ---
1373
+ ### ✅ **_log**
1374
+ Logs a styled message to the console with a specified log level (`log`, `info`, `warn`, `error`).
1375
+ ```ts
1376
+ _log("UserService", "Fetching user details...", "info");
1377
+ ```
1765
1378
 
1766
- ✅ **_isValidURLSearchParams**
1767
- Checks if the input is a `URLSearchParams` instance.
1379
+ ### ✅ **_sleep**
1380
+ Creates a delay for a given time using Promise.
1381
+ ```ts
1382
+ await _sleep(1000); // Wait 1 second
1383
+ ```
1768
1384
 
1385
+ ### ✅ **_throwError**
1386
+ Throws an error with an optional context object and logs it to the console.
1769
1387
  ```ts
1770
- // 🔍 Validate URLSearchParams
1771
- const isValid = _isValidURLSearchParams(new URLSearchParams());
1388
+ _throwError("Something went wrong");
1772
1389
  ```
1773
1390
 
1774
1391
  ###