super-utilix 1.0.0 → 1.1.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
@@ -10,18 +10,22 @@ npm install super-utilix
10
10
 
11
11
  ## Features
12
12
 
13
- - 📅 **Date Utilities**: Format dates, calculate age, validate future dates, and more.
14
- - 🛠 **Object Utilities**: deep object manipulation, filtering, sorting, and form data conversion.
15
- - 🔍 **Search & Filter**: Recursive search in objects, array filtering, and query string generation.
13
+ - 📅 **Date Utilities**: Format dates, calculate age, validate future dates, time conversion, and timestamp helpers.
14
+ - 🛠 **Object Utilities**: Deep comparison, field removal, sorting, form data conversion, and complex object manipulations.
15
+ - 🔍 **Search & Filter**: Recursive search in objects, array filtering, query string generation, and URL parameter handling.
16
16
  - 🔢 **Arabic Utilities**: Convert numbers to Arabic ordinal words.
17
- - 📝 **DOM & Events**: HTML text extraction and keyboard event handlers (Arabic, English, Numbers).
17
+ - 📝 **DOM & Events**: HTML text extraction and keyboard event handlers (Arabic, English, Numbers, Floating Point).
18
18
  - 🔄 **CRUD Helpers**: Frontend-side state management for Create, Read, Update, Delete operations.
19
+ - ✅ **Validation**: Date validation helpers.
19
20
 
20
21
  ---
21
22
 
22
23
  ## API Reference
23
24
 
24
- ### 1. Arabic Utilities (`literalOrdinals`)
25
+ ### 1. Arabic Utilities
26
+
27
+ #### `literalOrdinals(num, lang)`
28
+
25
29
  Convert numbers into their Arabic ordinal representation (e.g., 1 -> الأول).
26
30
 
27
31
  ```typescript
@@ -33,115 +37,580 @@ console.log(literalOrdinals(25, 'ar')); // "الخامس والعشرون"
33
37
 
34
38
  ### 2. Date Utilities
35
39
 
36
- #### `formatDateTime(date)`
37
- Formats a date string or object into `DD/MM/YYYY, h:mmA`.
40
+ #### `formatDateWithPattern(date, format)`
41
+
42
+ Formats a `Date` object using a custom pattern.
43
+ Supported tokens: `YYYY`, `YY`, `MM`, `M`, `DD`, `D`, `HH`, `H`, `hh`, `h`, `mm`, `m`, `ss`, `s`, `A`, `a`.
44
+
38
45
  ```typescript
46
+ import { formatDateWithPattern } from 'super-utilix';
47
+
48
+ formatDateWithPattern(new Date(), 'YYYY-MM-DD hh:mm A'); // "2023-12-25 02:30 PM"
49
+ ```
50
+
51
+ #### `formatDateTime(date, format?)`
52
+
53
+ Formats a date string or object. Default format: `DD/MM/YYYY, h:mmA`.
54
+
55
+ ```typescript
56
+ import { formatDateTime } from 'super-utilix';
57
+
39
58
  formatDateTime('2023-12-25T14:30:00'); // "25/12/2023, 2:30PM"
40
59
  ```
41
60
 
42
- #### `formatDate(date)`
43
- Formats a date string or object into `DD/MM/YYYY`.
61
+ #### `formatDate(date, format?)`
62
+
63
+ Formats a date string or object. Default format: `DD/MM/YYYY`.
64
+
44
65
  ```typescript
66
+ import { formatDate } from 'super-utilix';
67
+
45
68
  formatDate('2023-12-25'); // "25/12/2023"
46
69
  ```
47
70
 
48
- #### `calculateDetailedAge(birthDate, t, currentDate, gender)`
71
+ #### `getTime(inputDate)`
72
+
73
+ Extracts time in `HH:mm` format from a date.
74
+
75
+ ```typescript
76
+ import { getTime } from 'super-utilix';
77
+
78
+ getTime('2023-12-25T14:30:00'); // "14:30"
79
+ ```
80
+
81
+ #### `isNotFutureDate(date)`
82
+
83
+ Checks if a date is not in the future (compared to tomorrow's start).
84
+
85
+ ```typescript
86
+ import { isNotFutureDate } from 'super-utilix';
87
+
88
+ isNotFutureDate('2050-01-01'); // false
89
+ ```
90
+
91
+ #### `calculateDetailedAge(birthDate, t?, currentDate?, gender?)`
92
+
49
93
  Calculates detailed age (years, months, days) with localization support.
94
+
95
+ - `t`: Optional translation function `(key: string) => string`.
96
+ - `currentDate`: Defaults to now.
97
+ - `gender`: Optional gender string for localization.
98
+
50
99
  ```typescript
100
+ import { calculateDetailedAge } from 'super-utilix';
101
+
51
102
  const age = calculateDetailedAge('1990-01-01');
52
103
  console.log(age.message); // "33 years - 11 months - 24 days..."
53
104
  ```
54
105
 
55
106
  #### `calculateAge(birthDate)`
56
- Returns the age in years from a given birth date.
107
+
108
+ Returns the age in years from a given birth date string.
109
+ Supports `YYYY-MM-DD` and `DD/MM/YYYY` formats.
110
+
57
111
  ```typescript
112
+ import { calculateAge } from 'super-utilix';
113
+
58
114
  calculateAge('1990-01-01'); // 33
115
+ calculateAge('01/01/1990'); // 33
116
+ ```
117
+
118
+ #### `birthDateToAge(birthDate)`
119
+
120
+ Returns object `{ years, months, days }` from a birth date.
121
+
122
+ ```typescript
123
+ import { birthDateToAge } from 'super-utilix';
124
+
125
+ console.log(birthDateToAge('1990-01-01'));
126
+ // { years: 33, months: 11, days: 24 }
127
+ ```
128
+
129
+ #### `ageToBirthDate(age)`
130
+
131
+ Calculates birth date from an age object `{ years, months, days }`.
132
+
133
+ ```typescript
134
+ import { ageToBirthDate } from 'super-utilix';
135
+
136
+ const birthDate = ageToBirthDate({ years: 30, months: 5, days: 10 });
137
+ console.log(birthDate); // Date object
138
+ ```
139
+
140
+ #### `ageToBirthDateChangeSegment(oldAge, age)`
141
+
142
+ Calculates a new birth date based on changed age segments.
143
+
144
+ ```typescript
145
+ import { ageToBirthDateChangeSegment } from 'super-utilix';
146
+
147
+ const newBirthDate = ageToBirthDateChangeSegment(
148
+ { years: 30, months: 0, days: 0 },
149
+ { years: 31, months: 0, days: 0 },
150
+ );
151
+ ```
152
+
153
+ #### `convertTimeToTimestamp(timeString)`
154
+
155
+ Converts a time string in format `"DD HH:mm:ss"` (e.g., `"01 10:30:00"`) to milliseconds.
156
+
157
+ ```typescript
158
+ import { convertTimeToTimestamp } from 'super-utilix';
159
+
160
+ const ms = convertTimeToTimestamp('01 10:30:00');
161
+ console.log(ms); // Total milliseconds
59
162
  ```
60
163
 
61
164
  ### 3. Object Utilities
62
165
 
63
166
  #### `removeEmptyFields(obj)`
64
- Removes fields with `null`, `undefined`, or empty string values from an object.
167
+
168
+ Removes fields with `null`, `undefined`, or empty string values.
169
+
65
170
  ```typescript
66
- const clean = removeEmptyFields({ name: 'Ali', age: null, city: '' });
67
- // { name: 'Ali' }
171
+ import { removeEmptyFields } from 'super-utilix';
172
+
173
+ removeEmptyFields({ name: 'Ali', age: null }); // { name: 'Ali' }
68
174
  ```
69
175
 
70
176
  #### `objectToFormData(obj)`
71
- Converts a potentially nested object into a `FormData` object (useful for API requests).
177
+
178
+ Converts a potentially nested object into a `FormData` object.
179
+
72
180
  ```typescript
73
- const formData = objectToFormData({ name: 'Ali', file: fileObj });
181
+ import { objectToFormData } from 'super-utilix';
182
+
183
+ const formData = objectToFormData({ name: 'Ali', file: new File([], 'test.png') });
74
184
  ```
75
185
 
76
- #### `compareObjects(original, updated, keysToIgnore)`
77
- Deeply compares two objects to check if they are equivalent, optionally ignoring specific keys.
186
+ #### `compareObjects(original, updated, keysToIgnore?)`
187
+
188
+ Deeply compares two objects, optionally ignoring specific keys.
189
+
78
190
  ```typescript
79
- const isEqual = compareObjects({ a: 1 }, { a: 1, b: 2 }, ['b']); // true
191
+ import { compareObjects } from 'super-utilix';
192
+
193
+ compareObjects({ a: 1 }, { a: 1, b: 2 }, ['b']); // true
80
194
  ```
81
195
 
82
196
  #### `getChangedFields(original, updated)`
83
- Returns an object containing only the fields that have changed between two objects.
197
+
198
+ Returns an object containing only the fields that have changed.
199
+
84
200
  ```typescript
201
+ import { getChangedFields } from 'super-utilix';
202
+
85
203
  const changes = getChangedFields({ a: 1 }, { a: 2 }); // { a: 2 }
86
204
  ```
87
205
 
206
+ #### `capitalizeString(str)`
207
+
208
+ Capitalizes the first letter of a string.
209
+
210
+ ```typescript
211
+ import { capitalizeString } from 'super-utilix';
212
+
213
+ capitalizeString('hello'); // "Hello"
214
+ ```
215
+
216
+ #### `removeIdFromObjects(objects)`
217
+
218
+ Removes `_id` field from an array of objects.
219
+
220
+ ```typescript
221
+ import { removeIdFromObjects } from 'super-utilix';
222
+
223
+ const result = removeIdFromObjects([{ _id: '1', name: 'Ali' }]);
224
+ // [{ name: 'Ali' }]
225
+ ```
226
+
227
+ #### `removeItemsWithIds(array, idsToRemove)`
228
+
229
+ Removes items from an array that match the given IDs.
230
+
231
+ ```typescript
232
+ import { removeItemsWithIds } from 'super-utilix';
233
+
234
+ const result = removeItemsWithIds([{ _id: '1' }, { _id: '2' }], ['1']);
235
+ // [{ _id: '2' }]
236
+ ```
237
+
238
+ #### `createOptionsArray(data, valueField, ...labelFields)`
239
+
240
+ Creates an array of options `{ value, label }` for select inputs.
241
+
242
+ ```typescript
243
+ import { createOptionsArray } from 'super-utilix';
244
+
245
+ const users = [{ id: 1, firstName: 'Ali', lastName: 'Khan' }];
246
+ const options = createOptionsArray(users, 'id', 'firstName', 'lastName');
247
+ // [{ value: 1, label: "Ali Khan" }]
248
+ ```
249
+
250
+ #### `filterUsersOption(option, inputValue)`
251
+
252
+ Filter helper for user select options (matches name or email).
253
+
254
+ ```typescript
255
+ import { filterUsersOption } from 'super-utilix';
256
+
257
+ // Used in filter logic
258
+ const isMatch = filterUsersOption(
259
+ { label: { props: { children: ['Ali', 'ali@example.com'] } } },
260
+ 'Ali',
261
+ );
262
+ ```
263
+
264
+ #### `removeKeys(obj, keys)`
265
+
266
+ Removes specified keys from an object.
267
+
268
+ ```typescript
269
+ import { removeKeys } from 'super-utilix';
270
+
271
+ const result = removeKeys({ a: 1, b: 2 }, ['b']); // { a: 1 }
272
+ ```
273
+
274
+ #### `getArrayKeys(obj)`
275
+
276
+ Returns an array of keys that have array values in the object.
277
+
278
+ ```typescript
279
+ import { getArrayKeys } from 'super-utilix';
280
+
281
+ getArrayKeys({ a: [1, 2], b: 3 }); // [{ a: [1, 2] }]
282
+ ```
283
+
284
+ #### `convertObjectToArray(obj)`
285
+
286
+ Converts an object `{ key: value }` into an array `[{ key: value }]`.
287
+
288
+ ```typescript
289
+ import { convertObjectToArray } from 'super-utilix';
290
+
291
+ convertObjectToArray({ a: 1, b: 2 }); // [{ a: 1 }, { b: 2 }]
292
+ ```
293
+
294
+ #### `comparePermissionLists(list1, list2)`
295
+
296
+ Compares two lists of permissions.
297
+
298
+ ```typescript
299
+ import { comparePermissionLists } from 'super-utilix';
300
+
301
+ const isEqual = comparePermissionLists([{ read: ['users'] }], [{ read: ['users'] }]); // true
302
+ ```
303
+
304
+ #### `sortObjectByKeys(obj)`
305
+
306
+ Sorts object keys alphabetically.
307
+
308
+ ```typescript
309
+ import { sortObjectByKeys } from 'super-utilix';
310
+
311
+ sortObjectByKeys({ b: 2, a: 1 }); // { a: 1, b: 2 }
312
+ ```
313
+
314
+ #### `sortObjectByValues(obj)`
315
+
316
+ Sorts object properties by numeric values.
317
+
318
+ ```typescript
319
+ import { sortObjectByValues } from 'super-utilix';
320
+
321
+ sortObjectByValues({ a: 2, b: 1 }); // { b: 1, a: 2 }
322
+ ```
323
+
324
+ #### `removeFields(obj, fieldsToRemove)`
325
+
326
+ Recursively removes specified fields from an object or array.
327
+
328
+ ```typescript
329
+ import { removeFields } from 'super-utilix';
330
+
331
+ removeFields({ a: 1, nested: { a: 1, b: 2 } }, ['a']);
332
+ // { nested: { b: 2 } }
333
+ ```
334
+
335
+ #### `removeFieldsTopLevel(obj, fieldsToRemove)`
336
+
337
+ Removes specified fields from an object or array (shallow).
338
+
339
+ ```typescript
340
+ import { removeFieldsTopLevel } from 'super-utilix';
341
+
342
+ removeFieldsTopLevel({ a: 1, nested: { a: 1 } }, ['a']);
343
+ // { nested: { a: 1 } }
344
+ ```
345
+
346
+ #### `getLabelByItemsAndId(id, items, fields)`
347
+
348
+ Finds a label from items array by ID.
349
+
350
+ ```typescript
351
+ import { getLabelByItemsAndId } from 'super-utilix';
352
+
353
+ getLabelByItemsAndId(1, [{ id: 1, name: 'Ali' }], 'name'); // "Ali"
354
+ ```
355
+
356
+ #### `getLabelByItemsAndOptions(id, items)`
357
+
358
+ Finds a label from options array (`{ value, label }`) by ID.
359
+
360
+ ```typescript
361
+ import { getLabelByItemsAndOptions } from 'super-utilix';
362
+
363
+ getLabelByItemsAndOptions(1, [{ value: 1, label: 'Ali' }]); // "Ali"
364
+ ```
365
+
88
366
  ### 4. Search & Filter Utilities
89
367
 
90
- #### `searchInObjects(data, query, childrenField, fieldsToSearch)`
91
- Recursively searches through an array of objects (and their children) for a query string.
368
+ #### `searchInObjects(data, query, childrenField, fieldsToSearch?)`
369
+
370
+ Recursively searches through an array of objects (and their children).
371
+
372
+ ```typescript
373
+ import { searchInObjects } from 'super-utilix';
374
+
375
+ const data = [{ id: 1, name: 'Parent', children: [{ id: 2, name: 'Child' }] }];
376
+ const result = searchInObjects(data, 'Child', 'children', ['name']);
377
+ ```
378
+
379
+ #### `searchInObjectsWithParents(data, query, childrenField, fieldsToSearch?)`
380
+
381
+ Same as `searchInObjects` but retains the parent structure for matching children.
382
+
383
+ ```typescript
384
+ import { searchInObjectsWithParents } from 'super-utilix';
385
+
386
+ const result = searchInObjectsWithParents(data, 'Child', 'children', ['name']);
387
+ ```
388
+
389
+ #### `addSearchParam(searchParams, setSearchParams, key, value)`
390
+
391
+ Helper to update URL search parameters.
392
+
92
393
  ```typescript
93
- const result = searchInObjects(treeData, 'node', 'children', ['name']);
394
+ import { addSearchParam } from 'super-utilix';
395
+
396
+ // Inside a component or hook
397
+ addSearchParam(searchParams, setSearchParams, 'page', '2');
94
398
  ```
95
399
 
96
400
  #### `filterInArray(field, values, data)`
401
+
97
402
  Filters an array of objects based on whether a field's value exists in a provided array.
403
+
98
404
  ```typescript
405
+ import { filterInArray } from 'super-utilix';
406
+
99
407
  filterInArray('id', [1, 2], [{ id: 1 }, { id: 3 }]); // [{ id: 1 }]
100
408
  ```
101
409
 
410
+ #### `filterInObjects(data, query, childrenField, fieldsToFilter?)`
411
+
412
+ Recursively filters objects based on a query string matching specified fields.
413
+
414
+ ```typescript
415
+ import { filterInObjects } from 'super-utilix';
416
+
417
+ const result = filterInObjects(data, ['Child'], 'children', ['name']);
418
+ ```
419
+
420
+ ### 5. Query String Utilities
421
+
102
422
  #### `toQueryString(params)`
103
- Converts an object into a URL query string, automatically removing empty fields.
423
+
424
+ Converts an object into a URL query string, removing empty fields.
425
+
104
426
  ```typescript
427
+ import { toQueryString } from 'super-utilix';
428
+
105
429
  toQueryString({ page: 1, search: 'test' }); // "page=1&search=test"
106
430
  ```
107
431
 
108
- ### 5. Event Handlers (Input Validation)
432
+ #### `createSearchQuery(params)`
433
+
434
+ Creates a query string from parameters, handling arrays and primitives.
435
+
436
+ ```typescript
437
+ import { createSearchQuery } from 'super-utilix';
438
+
439
+ createSearchQuery({ ids: [1, 2], type: 'all' }); // "ids=1&ids=2&type=all"
440
+ ```
441
+
442
+ #### `serializeFormQuery(params)`
443
+
444
+ Serializes form params for backend requests.
445
+
446
+ ```typescript
447
+ import { serializeFormQuery } from 'super-utilix';
448
+
449
+ serializeFormQuery({ ids: [1, 2] }); // "ids=1,2"
450
+ ```
451
+
452
+ #### `arrFromQuery(query)`
453
+
454
+ Converts a comma-separated query string back to an array of numbers.
455
+
456
+ ```typescript
457
+ import { arrFromQuery } from 'super-utilix';
458
+
459
+ arrFromQuery('1,2,3'); // [1, 2, 3]
460
+ ```
461
+
462
+ #### `uniqueId()`
463
+
464
+ Generates a unique timestamp-based ID.
465
+
466
+ ```typescript
467
+ import { uniqueId } from 'super-utilix';
468
+
469
+ console.log(uniqueId()); // 168...
470
+ ```
471
+
472
+ #### `pureURLS3(url)`
473
+
474
+ Cleans up S3 URLs to remove query parameters and domain prefix.
475
+
476
+ ```typescript
477
+ import { pureURLS3 } from 'super-utilix';
478
+
479
+ pureURLS3('http://bucket.s3.com/folder/file.png?token=...'); // "folder/file.png"
480
+ ```
481
+
482
+ #### `prePareFilters(searchParams)`
483
+
484
+ Parses and prepares filter parameters from URL search params.
485
+
486
+ ```typescript
487
+ import { prePareFilters } from 'super-utilix';
488
+
489
+ const filters = prePareFilters(new URLSearchParams('filters=%5B...%5D'));
490
+ ```
491
+
492
+ ### 6. Event Handlers (Input Validation)
493
+
494
+ #### `handleKeyDownNumber`
495
+
496
+ Prevents non-numeric input.
109
497
 
110
- #### `handleKeyDownNumber(event)`
111
- Prevents non-numeric input in text fields.
112
498
  ```typescript
499
+ import { handleKeyDownNumber } from 'super-utilix';
500
+
113
501
  <input onKeyDown={handleKeyDownNumber} />
114
502
  ```
115
503
 
116
- #### `handleKeyDownArabic(event)`
117
- Restricts input to Arabic characters and common symbols.
504
+ #### `handleKeyDownNumberNoCopy`
505
+
506
+ Prevents non-numeric input and disables copy/paste.
507
+
508
+ ```typescript
509
+ import { handleKeyDownNumberNoCopy } from 'super-utilix';
510
+
511
+ <input onKeyDown={handleKeyDownNumberNoCopy} />
512
+ ```
513
+
514
+ #### `handleKeyDownFloatNumber`
515
+
516
+ Allows numbers and one decimal point.
517
+
518
+ ```typescript
519
+ import { handleKeyDownFloatNumber } from 'super-utilix';
520
+
521
+ <input onKeyDown={handleKeyDownFloatNumber} />
522
+ ```
523
+
524
+ #### `handleKeyDownArabic`
118
525
 
119
- #### `handleKeyDownEnglish(event)`
120
- Restricts input to English characters and common symbols.
526
+ Restricts input to Arabic characters.
121
527
 
122
- ### 6. DOM Utilities
528
+ ```typescript
529
+ import { handleKeyDownArabic } from 'super-utilix';
530
+
531
+ <input onKeyDown={handleKeyDownArabic} />
532
+ ```
533
+
534
+ #### `handleKeyDownEnglish`
535
+
536
+ Restricts input to English characters.
537
+
538
+ ```typescript
539
+ import { handleKeyDownEnglish } from 'super-utilix';
540
+
541
+ <input onKeyDown={handleKeyDownEnglish} />
542
+ ```
543
+
544
+ ### 7. DOM Utilities
123
545
 
124
546
  #### `getTextOnlyFromHtml(html)`
125
- Extracts plain text from an HTML string using `DOMParser`.
547
+
548
+ Extracts plain text from an HTML string.
549
+
126
550
  ```typescript
551
+ import { getTextOnlyFromHtml } from 'super-utilix';
552
+
127
553
  getTextOnlyFromHtml('<p>Hello <b>World</b></p>'); // "Hello World"
128
554
  ```
129
555
 
130
- ### 7. CRUD Operations (Frontend)
131
- Helper functions to manage state arrays for CRUD operations.
556
+ ### 8. CRUD Operations (Frontend)
132
557
 
133
- - `handleCreateFront`: Adds a new item to the list.
134
- - `handleUpdateFront`: Updates an existing item in the list.
135
- - `handleDeleteFront`: Removes an item from the list.
558
+ Helper functions to manage state arrays for Create, Read, Update, Delete.
559
+
560
+ #### Usage of CRUD Helpers
136
561
 
137
562
  ```typescript
563
+ import {
564
+ handleCreateFront,
565
+ handleCreateFrontUnique,
566
+ handleUpdateFront,
567
+ handleDeleteFront,
568
+ } from 'super-utilix';
569
+
570
+ // Create
138
571
  handleCreateFront({ items, setItems, itemData: { name: 'New Item' } });
572
+
573
+ // Create Unique
574
+ handleCreateFrontUnique({ items, setItems, itemData, uniqueField: 'id' });
575
+
576
+ // Update
577
+ handleUpdateFront({ id: 1, items, setItems, itemData: { name: 'Updated' } });
578
+
579
+ // Delete
580
+ handleDeleteFront({ id: 1, items, setItems });
139
581
  ```
140
582
 
141
- ### 8. Validation
583
+ ### 9. Validation
142
584
 
143
- #### `validateDay(value)`, `validateMonth(value)`, `validateYear(value)`
144
- Validates and sanitizes date inputs (e.g., ensures day is between 1-31).
585
+ #### `validateDay(value)`
586
+
587
+ Ensures day is between 1-31.
588
+
589
+ ```typescript
590
+ import { validateDay } from 'super-utilix';
591
+
592
+ validateDay('32'); // "31"
593
+ ```
594
+
595
+ #### `validateMonth(value)`
596
+
597
+ Ensures month is between 1-12.
598
+
599
+ ```typescript
600
+ import { validateMonth } from 'super-utilix';
601
+
602
+ validateMonth('13'); // "12"
603
+ ```
604
+
605
+ #### `validateYear(value)`
606
+
607
+ Ensures year is valid (>= 1900).
608
+
609
+ ```typescript
610
+ import { validateYear } from 'super-utilix';
611
+
612
+ validateYear('1800'); // "1900"
613
+ ```
145
614
 
146
615
  ## License
147
616
 
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var b=Object.defineProperty,E=Object.defineProperties,U=Object.getOwnPropertyDescriptor,R=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertyNames,D=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var F=(e,t,r)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,l=(e,t)=>{for(var r in t||(t={}))A.call(t,r)&&F(e,r,t[r]);if(D)for(var r of D(t))Y.call(t,r)&&F(e,r,t[r]);return e},j=(e,t)=>E(e,R(t));var k=(e,t)=>{var r={};for(var n in e)A.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&D)for(var n of D(e))t.indexOf(n)<0&&Y.call(e,n)&&(r[n]=e[n]);return r};var K=(e,t)=>{for(var r in t)b(e,r,{get:t[r],enumerable:!0})},B=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of N(t))!A.call(e,s)&&s!==r&&b(e,s,{get:()=>t[s],enumerable:!(n=U(t,s))||n.enumerable});return e};var H=e=>B(b({},"__esModule",{value:!0}),e);var Kt={};K(Kt,{addSearchParam:()=>Lt,ageToBirthDate:()=>q,ageToBirthDateChangeSegment:()=>tt,arrFromQuery:()=>$t,birthDateToAge:()=>v,calculateAge:()=>rt,calculateDetailedAge:()=>V,capitalizeString:()=>yt,compareObjects:()=>wt,comparePermissionLists:()=>xt,convertObjectToArray:()=>bt,convertTimeToTimestamp:()=>et,createOptionsArray:()=>ht,createSearchQuery:()=>jt,filterInArray:()=>ut,filterInObjects:()=>lt,filterUsersOption:()=>dt,formatDate:()=>Z,formatDateTime:()=>J,formatDateWithPattern:()=>O,getArrayKeys:()=>Dt,getChangedFields:()=>C,getLabelByItemsAndId:()=>St,getLabelByItemsAndOptions:()=>Mt,getTextOnlyFromHtml:()=>st,getTime:()=>X,handleCreateFront:()=>z,handleCreateFrontUnique:()=>Q,handleDeleteFront:()=>W,handleKeyDownArabic:()=>ot,handleKeyDownEnglish:()=>at,handleKeyDownFloatNumber:()=>ft,handleKeyDownNumber:()=>it,handleKeyDownNumberNoCopy:()=>ct,handleUpdateFront:()=>_,isNotFutureDate:()=>G,literalOrdinals:()=>$,objectToFormData:()=>L,prePareFilters:()=>Pt,pureURLS3:()=>Yt,removeEmptyFields:()=>M,removeFields:()=>T,removeFieldsFromObject:()=>S,removeFieldsTopLevel:()=>Tt,removeIdFromObjects:()=>gt,removeItemsWithIds:()=>pt,removeKeys:()=>mt,searchInObjects:()=>Et,searchInObjectsWithParents:()=>Ct,serializeFormQuery:()=>kt,sortObjectByKeys:()=>At,sortObjectByValues:()=>Ot,toQueryString:()=>Ft,uniqueId:()=>It,validateDay:()=>Ut,validateMonth:()=>Rt,validateYear:()=>Nt});module.exports=H(Kt);var $=(e,t)=>{if(t==="ar"){let r=["","\u0627\u0644\u0623\u0648\u0644","\u0627\u0644\u062B\u0627\u0646\u064A","\u0627\u0644\u062B\u0627\u0644\u062B","\u0627\u0644\u0631\u0627\u0628\u0639","\u0627\u0644\u062E\u0627\u0645\u0633","\u0627\u0644\u0633\u0627\u062F\u0633","\u0627\u0644\u0633\u0627\u0628\u0639","\u0627\u0644\u062B\u0627\u0645\u0646","\u0627\u0644\u062A\u0627\u0633\u0639"],n=["\u0627\u0644\u062D\u0627\u062F\u064A \u0639\u0634\u0631","\u0627\u0644\u062B\u0627\u0646\u064A \u0639\u0634\u0631","\u0627\u0644\u062B\u0627\u0644\u062B \u0639\u0634\u0631","\u0627\u0644\u0631\u0627\u0628\u0639 \u0639\u0634\u0631","\u0627\u0644\u062E\u0627\u0645\u0633 \u0639\u0634\u0631","\u0627\u0644\u0633\u0627\u062F\u0633 \u0639\u0634\u0631","\u0627\u0644\u0633\u0627\u0628\u0639 \u0639\u0634\u0631","\u0627\u0644\u062B\u0627\u0645\u0646 \u0639\u0634\u0631","\u0627\u0644\u062A\u0627\u0633\u0639 \u0639\u0634\u0631"],s=["","\u0627\u0644\u0639\u0627\u0634\u0631","\u0627\u0644\u0639\u0634\u0631\u0648\u0646","\u0627\u0644\u062B\u0644\u0627\u062B\u0648\u0646","\u0627\u0644\u0623\u0631\u0628\u0639\u0648\u0646","\u0627\u0644\u062E\u0645\u0633\u0648\u0646","\u0627\u0644\u0633\u062A\u0648\u0646","\u0627\u0644\u0633\u0628\u0639\u0648\u0646","\u0627\u0644\u062B\u0645\u0627\u0646\u0648\u0646","\u0627\u0644\u062A\u0633\u0639\u0648\u0646"],o=["","\u0627\u0644\u0645\u0627\u0626\u0629","\u0627\u0644\u0645\u0626\u062A\u0627\u0646","\u0627\u0644\u062B\u0644\u0627\u062B\u0645\u0627\u0626\u0629","\u0627\u0644\u0623\u0631\u0628\u0639\u0645\u0627\u0626\u0629","\u0627\u0644\u062E\u0645\u0633\u0645\u0627\u0626\u0629","\u0627\u0644\u0633\u062A\u0645\u0627\u0626\u0629","\u0627\u0644\u0633\u0628\u0639\u0645\u0627\u0626\u0629","\u0627\u0644\u062B\u0645\u0627\u0646\u0645\u0627\u0626\u0629","\u0627\u0644\u062A\u0633\u0639\u0645\u0627\u0626\u0629"];if(e===1)return"\u0627\u0644\u0623\u0648\u0644";let a=Math.floor(e/100),u=e%100;if(a>0)return u===0?o[a]:`${o[a]} \u0648${$(u,t)}`;if(e>=2&&e<=9)return r[e];if(e>=11&&e<=19)return n[e-11];if(e%10===0&&e<100)return s[e/10];let i=e%10,c=Math.floor(e/10)*10;return c===10?`\u0627\u0644${r[i]} \u0639\u0634\u0631`:i===1?`\u0627\u0644\u062D\u0627\u062F\u064A \u0648${s[c/10]}`:i===2?`\u0627\u0644\u062B\u0627\u0646\u064A \u0648${s[c/10]}`:`${r[i]} \u0648${s[c/10]}`}else{let r=["th","st","nd","rd"],n=e%100;return e+(r[(n-20)%10]||r[n]||r[0])}};var z=({items:e,setItems:t,itemData:r})=>{if(!e||!t||!r)return;let n=l({id:Number(new Date().getTime())},r);n&&t([...e,n])},Q=({items:e,setItems:t,itemData:r,uniqueField:n})=>{if(!e||!t||!r)return;e.some(o=>n&&typeof r=="object"&&r!==null?o[n]===r[n]:o===r)||t([...e,r])},_=({id:e,items:t,setItems:r,itemData:n})=>{!e||!t||!r||!n||r(t==null?void 0:t.map(s=>s.id===e?l(l({},s),n):s))},W=({id:e,items:t,setItems:r})=>{!e||!t||!r||r(t==null?void 0:t.filter(n=>{var s;return typeof n=="object"&&n!==null&&!Array.isArray(e)?n.id!==e:Array.isArray(e)?!e.includes((s=n.id)!=null?s:n):n!==e}))};var O=(e,t)=>{let r=e.getDate(),n=e.getMonth()+1,s=e.getFullYear(),o=e.getHours(),a=o%12||12,u=e.getMinutes(),i=e.getSeconds(),c=o>=12?"PM":"AM",f={YYYY:String(s),YY:String(s).slice(-2),MM:String(n).padStart(2,"0"),M:String(n),DD:String(r).padStart(2,"0"),D:String(r),HH:String(o).padStart(2,"0"),H:String(o),hh:String(a).padStart(2,"0"),h:String(a),mm:String(u).padStart(2,"0"),m:String(u),ss:String(i).padStart(2,"0"),s:String(i),A:c,a:c.toLowerCase()};return t.replace(/YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|A|a/g,y=>f[y])},J=(e,t="DD/MM/YYYY, h:mmA")=>{if(!e)return"";let r=new Date(e);return O(r,t)},Z=(e,t="DD/MM/YYYY")=>{if(!e)return"";let r=new Date(e);return O(r,t)},G=e=>{let t=new Date(e),r=new Date;return r.setDate(r.getDate()+1),r.setHours(0,0,0,0),t<r};function X(e){if(!e)return"";let t=new Date(e),r=o=>o.toString().padStart(2,"0"),n=r(t.getHours()),s=r(t.getMinutes());return`${n}:${s}`}var V=(e,t=void 0,r=new Date,n)=>{var f,y,g,p,h;let s={age:{years:0,months:0,days:0},message:(f=t==null?void 0:t("no_age"))!=null?f:"No age"};if(e==null)return s;let o=e instanceof Date?e:nt(e)?new Date(e):new Date(Number(e)),a=r instanceof Date?r:new Date(Number(r));if(isNaN(o.getTime())||isNaN(a.getTime())||a<o)return s;let u=a.getFullYear()-o.getFullYear(),i=a.getMonth()-o.getMonth(),c=a.getDate()-o.getDate();if(c<0){let m=new Date(a.getFullYear(),a.getMonth(),0);c+=m.getDate(),i--}return i<0&&(u--,i+=12),{age:{years:u,months:i,days:c},message:`${u} ${(y=t==null?void 0:t("years"))!=null?y:"years"} - ${i} ${(g=t==null?void 0:t("months"))!=null?g:"months"} - ${c} ${(p=t==null?void 0:t("days"))!=null?p:"days"} / ${(h=t==null?void 0:t(n!=null?n:""))!=null?h:n}`}},v=e=>{if(!e)return null;let t=new Date(e),r=new Date,n=r.getFullYear()-t.getFullYear(),s=r.getMonth()-t.getMonth(),o=r.getDate()-t.getDate();return o<0&&(s--,o+=new Date(r.getFullYear(),r.getMonth(),0).getDate()),s<0&&(n--,s+=12),{years:n,months:s,days:o}},q=e=>{let t=new Date,r=t.getFullYear()-e.years,n=t.getMonth()-e.months,s=t.getDate()-e.days,o=new Date(t.getFullYear(),t.getMonth(),t.getDate());return o.setFullYear(r),o.setMonth(n),o.setDate(s),o},tt=(e,t)=>{let r=new Date,n=e&&e.years?e.years-t.years:r.getFullYear()-t.years,s=e&&e.months?e.months-t.months:r.getMonth()-t.months,o=e&&e.days?e.days-t.days:r.getDate()-t.days,a=new Date(r.getFullYear(),r.getMonth(),r.getDate());return a.setFullYear(n),a.setMonth(s),a.setDate(o),a};function et(e){let[t,r]=e.split(" "),n=parseInt(t.replace(/^0+/,""),10),[s,o,a]=(r||"00:00:00").split(":").map(i=>parseInt(i,10));return n*24*60*60*1e3+s*60*60*1e3+o*60*1e3+a*1e3}var rt=e=>{let t=new Date,r;if(e.includes("/")){let[o,a,u]=e.split("/").map(Number);r=new Date(u,a-1,o)}else if(!isNaN(Date.parse(e)))r=new Date(e);else throw new Error("Unsupported date format");let n=t.getFullYear()-r.getFullYear(),s=t.getMonth()-r.getMonth();return(s<0||s===0&&t.getDate()<r.getDate())&&n--,n};function nt(e){let t=new Date(e);return!isNaN(t.getTime())&&t.toISOString()===e}var st=e=>{var n;let t=new DOMParser,r=e&&t.parseFromString(e,"text/html");return(n=r&&r.body.textContent)!=null?n:""};var ot=e=>{let{key:t,ctrlKey:r,metaKey:n}=e;t==="Backspace"||t==="Delete"||t==="ArrowLeft"||t==="ArrowRight"||t==="ArrowUp"||t==="ArrowDown"||t==="Tab"||t==="Enter"||(r||n)&&(t==="c"||t==="v"||t==="x"||t==="a")||/[\u0600-\u06FF0-9\s!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/.test(t)||e.preventDefault()},at=e=>{let{key:t,ctrlKey:r,metaKey:n}=e;t==="Backspace"||t==="Delete"||t==="ArrowLeft"||t==="ArrowRight"||t==="ArrowUp"||t==="ArrowDown"||t==="Tab"||t==="Enter"||(r||n)&&(t==="c"||t==="v"||t==="x"||t==="a")||/[A-Za-z0-9\s!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/.test(t)||e.preventDefault()},it=e=>{let{key:t,ctrlKey:r,metaKey:n}=e;t==="Backspace"||t==="Delete"||t==="ArrowLeft"||t==="ArrowRight"||t==="ArrowUp"||t==="ArrowDown"||t==="Tab"||t==="Enter"||(r||n)&&(t==="c"||t==="v"||t==="x"||t==="a")||/[0-9]/.test(t)||e.preventDefault()},ct=e=>{let{key:t}=e;t==="Backspace"||t==="Delete"||t==="ArrowLeft"||t==="ArrowRight"||t==="ArrowUp"||t==="ArrowDown"||t==="Tab"||t==="Enter"||/[0-9]/.test(t)||e.preventDefault()},ft=e=>{let{key:t,ctrlKey:r,metaKey:n}=e,s=e.currentTarget;t==="Backspace"||t==="Delete"||t==="ArrowLeft"||t==="ArrowRight"||t==="ArrowUp"||t==="ArrowDown"||t==="Tab"||t==="Enter"||(r||n)&&(t==="c"||t==="v"||t==="x"||t==="a")||t==="."&&!s.value.includes(".")||!/[0-9]/.test(t)&&t!=="."&&e.preventDefault()};function ut(e,t,r){return t.length===0?r:r.filter(n=>t.includes(n[e]))}function lt(e=[],t,r="children",n){if(!e)return[];if(!t||(t==null?void 0:t.length)===0)return e;let s=a=>(n?n.map(i=>a[i]).filter(Boolean):Object.values(a)).some(i=>typeof i=="string"&&t.some(c=>i.includes(c))),o=a=>{let u=[];return a.forEach(i=>{s(i)&&u.push(i),i[r]&&(u=u.concat(o(i[r])))}),u};return o(e)}var yt=e=>e.charAt(0).toUpperCase()+e.slice(1);function M(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>(t==null?void 0:t.length)!==0&&t!==null&&t!==void 0))}function gt(e){return e.map(n=>{var s=n,{_id:t}=s,r=k(s,["_id"]);return r})}function pt(e,t){return e.filter(r=>!(r!=null&&r._id)||!t.includes(r==null?void 0:r._id))}function ht(e,t,...r){return e.map(n=>({value:n[t],label:r.map(s=>n[s]).join(" ")}))}function dt(e,t){var s,o,a,u,i,c,f,y,g,p,h,m;let r=`${(i=(u=(a=(o=(s=e==null?void 0:e.label)==null?void 0:s.props)==null?void 0:o.children)==null?void 0:a[0])==null?void 0:u.props)==null?void 0:i.children}`,n=(p=(g=(y=(f=(c=e==null?void 0:e.label)==null?void 0:c.props)==null?void 0:f.children)==null?void 0:y[1])==null?void 0:g.props)==null?void 0:p.children;return((h=r==null?void 0:r.toLowerCase())==null?void 0:h.includes(t==null?void 0:t.toLowerCase()))||((m=n==null?void 0:n.toLowerCase())==null?void 0:m.includes(t==null?void 0:t.toLowerCase()))}function mt(e,t){let r=l({},e);for(let n of t)delete r[n];return r}function Dt(e){let t=[];for(let r in e)Array.isArray(e[r])&&t.push({[r]:e[r]});return t}function bt(e){return e?Object.entries(e).map(([t,r])=>({[t]:r})):[]}function xt(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){let n=Object.keys(e[r]),s=Object.keys(t[r]);if(n.length!==s.length)return!1;for(let o of n){if(!s.includes(o))return!1;let a=e[r][o],u=t[r][o];if(a.length!==u.length)return!1;for(let i of a)if(!u.includes(i))return!1}}return!0}function L(e,t=new FormData,r=""){for(let n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;let s=r?`${r}[${n}]`:n;typeof e[n]=="object"&&!(e[n]instanceof File)?L(e[n],t,s):t.append(s,e[n])}return t}function I(e){return e instanceof Date}function x(e){return e!==null&&typeof e=="object"}function w(e){return Array.isArray(e)}function P(e,t){let r={};for(let n in e)t.includes(n)||(r[n]=e[n]);return r}function d(e,t){if(e===t)return!0;if(e==null||t==null||typeof e!=typeof t)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!d(e[r],t[r]))return!1;return!0}if(typeof e=="object"&&typeof t=="object"){let r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let s of r)if(!n.includes(s)||!d(e[s],t[s]))return!1;return!0}return!1}function wt(e,t,r=[]){let n=P(e,r),s=P(t,r);return d(n,s)}function C(e,t){if(!e&&!t)return{};if(!e)return t!=null?t:{};if(!t)return{};let r={};return Object.keys(t).forEach(n=>{let s=e==null?void 0:e[n],o=t==null?void 0:t[n];if(I(o)&&I(s)){s.getTime()!==o.getTime()&&(r[n]=o);return}if(x(o)&&!x(s)){r[n]=o;return}if(x(o)&&!w(o)&&x(s)&&!w(s)){let a=C(s,o);Object.keys(a).length>0&&(r[n]=a);return}if(w(o)||w(s)){d(s,o)||(r[n]=o);return}d(s,o)||(r[n]=o)}),r}function At(e){let t=Object.entries(e).sort((r,n)=>r[0].localeCompare(n[0]));return Object.fromEntries(t)}function Ot(e){let t=Object.entries(e).sort((r,n)=>typeof r[1]=="number"&&typeof n[1]=="number"?r[1]-n[1]:0);return Object.fromEntries(t)}function T(e,t){if(Array.isArray(e))return e.map(r=>T(r,t));if(typeof e=="object"&&e!==null){let r={};for(let n in e)t.includes(n)||(r[n]=T(e[n],t));return r}return e}function Tt(e,t){return e==null?e:Array.isArray(e)?e.map(r=>typeof r=="object"&&r!==null?S(r,t):r):typeof e=="object"&&e!==null?S(e,t):e}function S(e,t){let r=l({},e);for(let n of t||[])delete r[n];return r}var St=(e,t,r="name")=>{if(!t||!e)return;let n=t==null?void 0:t.find(s=>s.id===e);return n?Array.isArray(r)?r.map(s=>n[s]).join(" "):n[r]:""},Mt=(e,t)=>{if(!t||!e)return;let r=t==null?void 0:t.find(n=>n.value===e||(n==null?void 0:n.id)===e||(n==null?void 0:n._id)===e);return r?r.label:""};function Ft(e){return e?Object.entries(M(e)).filter(([,t])=>t!==void 0).map(([t,r])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(r))}`).join("&"):""}function Yt(e){return e!=null&&e.startsWith("http")?e.split(".com/")[1].split("?")[0]:e}var jt=e=>{let t=new URLSearchParams;for(let[r,n]of Object.entries(e))if(Array.isArray(n))for(let s of n)t.append(r,s.toString());else n!==void 0&&t.append(r,n.toString());return t.toString()},kt=e=>Object.entries(e).map(([t,r])=>Array.isArray(r)?r.length===0?"":`${t}=${r.join(",")}`:r===void 0||r===""?"":`${t}=${r}`).filter(t=>t!=="").join("&"),$t=e=>!e||e===null||e===""?[]:e.split(",").map(t=>parseInt(t)),It=()=>Date.now()+Math.floor(Math.random()*1e4),Pt=e=>{let t=e.get("filters");if(!t)return null;try{let r=decodeURIComponent(t);return JSON.parse(r)}catch(r){return console.error("Error parsing filters from URL:",r),null}};var Lt=(e,t,r,n)=>{let s=new URLSearchParams(e);s.set(r,n),t(s)};function Ct(e=[],t="",r="children",n){var u;if(!e)return[];if(!t)return e;let s=(u=t.trim())==null?void 0:u.toLowerCase(),o=i=>(n?n.map(f=>i[f]).filter(Boolean):Object.values(i)).some(f=>typeof f=="string"&&(f==null?void 0:f.toLowerCase().includes(s))),a=i=>i.map(c=>{let f=c[r]?a(c[r]):[];return o(c)||f.length>0?j(l({},c),{[r]:f.length>0?f:void 0}):null}).filter(c=>c!==null);return a(e)}function Et(e=[],t="",r="children",n){var u;if(!e)return[];if(!t)return e;let s=(u=t==null?void 0:t.trim())==null?void 0:u.toLowerCase(),o=i=>(n?n.map(f=>i[f]).filter(Boolean):Object.values(i)).some(f=>typeof f=="string"&&(f==null?void 0:f.toLowerCase().includes(s))),a=i=>{let c=[];return i.forEach(f=>{o(f)&&c.push(f),f[r]&&(c=c.concat(a(f[r])))}),c};return a(e)}var Ut=e=>{let t=e.replace(/\D/g,"");return t?Math.min(Math.max(parseInt(t,10),1),31).toString():""},Rt=e=>{let t=e.replace(/\D/g,"");return t?Math.min(Math.max(parseInt(t,10),1),12).toString():""},Nt=e=>{let t=e.replace(/\D/g,"");return t?t.length<4?t:parseInt(t,10)<1900?"1900":t:""};0&&(module.exports={addSearchParam,ageToBirthDate,ageToBirthDateChangeSegment,arrFromQuery,birthDateToAge,calculateAge,calculateDetailedAge,capitalizeString,compareObjects,comparePermissionLists,convertObjectToArray,convertTimeToTimestamp,createOptionsArray,createSearchQuery,filterInArray,filterInObjects,filterUsersOption,formatDate,formatDateTime,formatDateWithPattern,getArrayKeys,getChangedFields,getLabelByItemsAndId,getLabelByItemsAndOptions,getTextOnlyFromHtml,getTime,handleCreateFront,handleCreateFrontUnique,handleDeleteFront,handleKeyDownArabic,handleKeyDownEnglish,handleKeyDownFloatNumber,handleKeyDownNumber,handleKeyDownNumberNoCopy,handleUpdateFront,isNotFutureDate,literalOrdinals,objectToFormData,prePareFilters,pureURLS3,removeEmptyFields,removeFields,removeFieldsFromObject,removeFieldsTopLevel,removeIdFromObjects,removeItemsWithIds,removeKeys,searchInObjects,searchInObjectsWithParents,serializeFormQuery,sortObjectByKeys,sortObjectByValues,toQueryString,uniqueId,validateDay,validateMonth,validateYear});
2
+ //# sourceMappingURL=index.cjs.map