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