mado-ui 0.1.2 → 0.2.1

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.
@@ -0,0 +1,751 @@
1
+ import { extendTailwindMerge } from 'tailwind-merge';
2
+ import { Children, isValidElement, Fragment } from 'react';
3
+
4
+ /**
5
+ * ### Has Class
6
+ * - Returns a boolean based on whether the specified element has the specified class
7
+ * @param {HTMLElement} element Any HTML Element
8
+ * @param {string} className A string of any class to check for
9
+ * @returns {boolean} true if the specified element has the specified class, else false
10
+ */
11
+ function hasClass(element, className) {
12
+ return element.classList.contains(className);
13
+ }
14
+ /**
15
+ * ### Add Class
16
+ * - Adds the specified classes to the specified elements
17
+ * @param {Element|HTMLElement|HTMLElement[]|NodeList|string|undefined} elements An HTML Element, an array of HTML Elements, a Node List, a string (as a selector for a querySelector)
18
+ * @param {string|string[]} classList A string or an array of classes to add to each element
19
+ */
20
+ function addClass(elements, classList) {
21
+ const elementsType = elements.constructor.name, elementsIsString = typeof elements === 'string', classListType = classList.constructor.name, classListIsString = typeof classList === 'string';
22
+ let elementList, classListGroup;
23
+ // & Convert elements to array
24
+ switch (elementsType) {
25
+ // Selector
26
+ case 'String':
27
+ if (elementsIsString)
28
+ elementList = Array.from(document.querySelectorAll(elements));
29
+ break;
30
+ // Multiple HTML Elements
31
+ case 'NodeList':
32
+ if (!elementsIsString)
33
+ elementList = Array.from(elements);
34
+ break;
35
+ // Array of Elements
36
+ case 'Array':
37
+ if (!elementsIsString)
38
+ elementList = elements;
39
+ break;
40
+ // Single HTML Element
41
+ default:
42
+ if (elementsType.startsWith('HTML') && !elementsIsString)
43
+ elementList = [elements];
44
+ }
45
+ // & Convert classList to array
46
+ switch (classListType) {
47
+ case 'String':
48
+ if (classListIsString)
49
+ if (classList.split(' ').length >= 2) {
50
+ classListGroup = classList.split(' ');
51
+ }
52
+ else {
53
+ classListGroup = [classList];
54
+ }
55
+ break;
56
+ case 'Array':
57
+ if (!classListIsString)
58
+ classListGroup = classList;
59
+ break;
60
+ }
61
+ if (!elementList || elementList.length < 1)
62
+ throw new Error(`Elements are invalid or undefined. elements: ${elements} → elementList: ${elementList}`);
63
+ if (!classListGroup || classListGroup.length < 1)
64
+ throw new Error(`Class List is invalid or undefined. classList: ${classList} → classListGroup: ${classListGroup}`);
65
+ elementList.forEach((element) => classListGroup.forEach((classItem) => {
66
+ if (hasClass(element, classItem))
67
+ return;
68
+ element.classList.add(classItem);
69
+ }));
70
+ }
71
+ /**
72
+ * ### Remove Class
73
+ * - Removes the specified classes from the specified elements
74
+ * @param {HTMLElement|HTMLElement[]|NodeList|string|undefined} elements An HTML Element, an array of HTML Elements, a Node List, a string (as a selector for a querySelector)
75
+ * @param {string|string[]} classList A string or an array of classes to remove from each element
76
+ */
77
+ function removeClass(elements, classList) {
78
+ const elementsType = elements.constructor.name, elementsIsString = typeof elements === 'string', classListType = classList.constructor.name, classListIsString = typeof classList === 'string';
79
+ let elementList, classListGroup;
80
+ // & Convert elements to array
81
+ switch (elementsType) {
82
+ // Selector
83
+ case 'String':
84
+ if (elementsIsString)
85
+ elementList = Array.from(document.querySelectorAll(elements));
86
+ break;
87
+ // Multiple HTML Elements
88
+ case 'NodeList':
89
+ if (!elementsIsString)
90
+ elementList = Array.from(elements);
91
+ break;
92
+ // Array of Elements
93
+ case 'Array':
94
+ if (!elementsIsString)
95
+ elementList = elements;
96
+ break;
97
+ // Single HTML Element
98
+ default:
99
+ if (elementsType.startsWith('HTML') && !elementsIsString)
100
+ elementList = [elements];
101
+ }
102
+ // & Convert classList to array
103
+ switch (classListType) {
104
+ case 'String':
105
+ if (classListIsString)
106
+ if (classList.split(' ').length >= 2) {
107
+ classListGroup = classList.split(' ');
108
+ }
109
+ else {
110
+ classListGroup = [classList];
111
+ }
112
+ break;
113
+ case 'Array':
114
+ if (!classListIsString)
115
+ classListGroup = classList;
116
+ break;
117
+ }
118
+ if (!elementList || elementList.length < 1)
119
+ throw new Error(`Elements are invalid or undefined. elements: ${elements} → elementList: ${elementList}`);
120
+ if (!classListGroup || classListGroup.length < 1)
121
+ throw new Error(`Class List is invalid or undefined. classList: ${classList} → classListGroup: ${classListGroup}`);
122
+ elementList.forEach((element) => classListGroup.forEach((classItem) => {
123
+ if (!hasClass(element, classItem))
124
+ return;
125
+ element.classList.remove(classItem);
126
+ }));
127
+ }
128
+ /**
129
+ * ### Toggle Class
130
+ * - Toggles the specified classes on the specified elements
131
+ * @param {HTMLElement|HTMLElement[]|NodeList|string|undefined} elements An HTML Element, an array of HTML Elements, a Node List, a string (as a selector for a querySelector)
132
+ * @param {string|string[]} classList A string or an array of classes to toggle on each element
133
+ */
134
+ function toggleClass(elements, classList) {
135
+ const elementsType = elements.constructor.name, elementsIsString = typeof elements === 'string', classListType = classList.constructor.name, classListIsString = typeof classList === 'string';
136
+ let elementList, classListGroup;
137
+ // & Convert elements to array
138
+ switch (elementsType) {
139
+ // Selector
140
+ case 'String':
141
+ if (elementsIsString)
142
+ elementList = Array.from(document.querySelectorAll(elements));
143
+ break;
144
+ // Multiple HTML Elements
145
+ case 'NodeList':
146
+ if (!elementsIsString)
147
+ elementList = Array.from(elements);
148
+ break;
149
+ // Array of Elements
150
+ case 'Array':
151
+ if (!elementsIsString)
152
+ elementList = elements;
153
+ break;
154
+ // Single HTML Element
155
+ default:
156
+ if (elementsType.startsWith('HTML') && !elementsIsString)
157
+ elementList = [elements];
158
+ }
159
+ // & Convert classList to array
160
+ switch (classListType) {
161
+ case 'String':
162
+ if (classListIsString)
163
+ if (classList.split(' ').length >= 2) {
164
+ classListGroup = classList.split(' ');
165
+ }
166
+ else {
167
+ classListGroup = [classList];
168
+ }
169
+ break;
170
+ case 'Array':
171
+ if (!classListIsString)
172
+ classListGroup = classList;
173
+ break;
174
+ }
175
+ if (!elementList || elementList.length < 1)
176
+ throw new Error(`Elements are invalid or undefined. elements: ${elements} → elementList: ${elementList}`);
177
+ if (!classListGroup || classListGroup.length < 1)
178
+ throw new Error(`Class List is invalid or undefined. classList: ${classList} → classListGroup: ${classListGroup}`);
179
+ elementList.forEach((element) => classListGroup.forEach((classItem) => {
180
+ element.classList.toggle(classItem);
181
+ }));
182
+ }
183
+
184
+ const integerList = Array.from({ length: 100 }, (_, i) => `${i + 1}`);
185
+ const twMerge = extendTailwindMerge({
186
+ extend: {
187
+ theme: {
188
+ color: [
189
+ {
190
+ ui: [
191
+ 'red',
192
+ 'orange',
193
+ 'yellow',
194
+ 'green',
195
+ 'sky-blue',
196
+ 'blue',
197
+ 'violet',
198
+ 'magenta',
199
+ 'purple',
200
+ 'brown',
201
+ 'grey',
202
+ 'pink',
203
+ ],
204
+ },
205
+ ],
206
+ },
207
+ classGroups: {
208
+ animate: [
209
+ {
210
+ animate: [
211
+ 'bounce',
212
+ 'double-spin',
213
+ 'drop-in',
214
+ 'flip',
215
+ 'flip-again',
216
+ 'grid-rows',
217
+ 'heartbeat',
218
+ 'ping',
219
+ 'pulse',
220
+ 'slide-up',
221
+ 'spin',
222
+ 'wave',
223
+ ],
224
+ },
225
+ ],
226
+ 'animation-direction': [
227
+ {
228
+ 'animation-direction': ['normal', 'reverse', 'alternate', 'alternate-reverse'],
229
+ },
230
+ ],
231
+ 'animation-fill': [
232
+ {
233
+ 'animation-fill': ['none', 'forwards', 'backwards', 'both'],
234
+ },
235
+ ],
236
+ 'animation-iteration': [
237
+ {
238
+ 'animation-iteration': [...integerList, 'infinite'],
239
+ },
240
+ ],
241
+ 'animation-state': [
242
+ {
243
+ 'animation-state': ['running', 'paused'],
244
+ },
245
+ ],
246
+ 'grid-cols': [
247
+ {
248
+ 'grid-cols': ['0fr', '1fr'],
249
+ },
250
+ ],
251
+ 'grid-rows': [
252
+ {
253
+ 'grid-rows': ['0fr', '1fr'],
254
+ },
255
+ ],
256
+ transition: ['transition-rows'],
257
+ },
258
+ },
259
+ });
260
+ function extendMadoTailwindMerge(configExtension) {
261
+ const extend = configExtension.extend || {};
262
+ const theme = extend.theme || {};
263
+ const color = 'color' in theme ? theme.color : [];
264
+ const classGroups = extend.classGroups || {};
265
+ const themeRest = { ...theme };
266
+ if ('color' in themeRest)
267
+ delete themeRest.color;
268
+ const extendRest = { ...extend };
269
+ delete extendRest.theme;
270
+ delete extendRest.classGroups;
271
+ return extendTailwindMerge({
272
+ extend: {
273
+ theme: {
274
+ color: [
275
+ {
276
+ ui: [
277
+ 'red',
278
+ 'orange',
279
+ 'yellow',
280
+ 'green',
281
+ 'sky-blue',
282
+ 'blue',
283
+ 'violet',
284
+ 'magenta',
285
+ 'purple',
286
+ 'brown',
287
+ 'grey',
288
+ 'pink',
289
+ ],
290
+ },
291
+ ...color,
292
+ ],
293
+ ...themeRest,
294
+ },
295
+ classGroups: {
296
+ animate: [
297
+ {
298
+ animate: [
299
+ 'bounce',
300
+ 'double-spin',
301
+ 'drop-in',
302
+ 'flip',
303
+ 'flip-again',
304
+ 'grid-rows',
305
+ 'heartbeat',
306
+ 'ping',
307
+ 'pulse',
308
+ 'slide-up',
309
+ 'spin',
310
+ 'wave',
311
+ ],
312
+ },
313
+ ],
314
+ 'animation-direction': [
315
+ {
316
+ 'animation-direction': ['normal', 'reverse', 'alternate', 'alternate-reverse'],
317
+ },
318
+ ],
319
+ 'animation-fill': [
320
+ {
321
+ 'animation-fill': ['none', 'forwards', 'backwards', 'both'],
322
+ },
323
+ ],
324
+ 'animation-iteration': [
325
+ {
326
+ 'animation-iteration': [...integerList, 'infinite'],
327
+ },
328
+ ],
329
+ 'animation-state': [
330
+ {
331
+ 'animation-state': ['running', 'paused'],
332
+ },
333
+ ],
334
+ 'grid-cols': [
335
+ {
336
+ 'grid-cols': ['0fr', '1fr'],
337
+ },
338
+ ],
339
+ 'grid-rows': [
340
+ {
341
+ 'grid-rows': ['0fr', '1fr'],
342
+ },
343
+ ],
344
+ transition: ['transition-rows'],
345
+ ...classGroups,
346
+ },
347
+ ...extendRest,
348
+ },
349
+ ...configExtension,
350
+ });
351
+ }
352
+
353
+ /** The current date as a Date object */
354
+ const d = new Date();
355
+ /** The current minute of the current hour */
356
+ const minutes = d.getMinutes();
357
+ /** The current year */
358
+ const year = d.getFullYear();
359
+ /** An array of the names of month in order */
360
+ const monthNamesList = [
361
+ 'January',
362
+ 'February',
363
+ 'March',
364
+ 'April',
365
+ 'May',
366
+ 'June',
367
+ 'July',
368
+ 'August',
369
+ 'September',
370
+ 'October',
371
+ 'November',
372
+ 'December',
373
+ ];
374
+ /** An array of the names of the days of the week in order */
375
+ const weekdayNamesList = [
376
+ 'Sunday',
377
+ 'Monday',
378
+ 'Tuesday',
379
+ 'Wednesday',
380
+ 'Thursday',
381
+ 'Friday',
382
+ 'Saturday',
383
+ ];
384
+ /** The name of the current month */
385
+ const currentMonthName = getMonthName();
386
+ /** The name of the current day of the week */
387
+ const currentWeekdayName = getWeekdayName();
388
+ /**
389
+ * ### Days In Month
390
+ * - Returns the number of days in the specified month.
391
+ * @param {Date} date A Date object representing the month to get the number of days for. (Preset to the current date)
392
+ * @returns {number} The number of days in the specified month.
393
+ */
394
+ function daysInMonth(date = d) {
395
+ const selectedYear = date.getFullYear(), selectedMonth = date.getMonth() + 1;
396
+ return new Date(selectedYear, selectedMonth, 0).getDate();
397
+ }
398
+ /**
399
+ * ### First of Month
400
+ * - Returns the first day of the specified month.
401
+ * @param {Date} date A Date object representing the month to get the first day for. (Preset to current date)
402
+ * @returns {Date} A Date object of the given month, with the first day.
403
+ */
404
+ function firstOfMonth(date = d) {
405
+ // Return a new Date object with the first of the month selected
406
+ return new Date(date.getFullYear(), date.getMonth(), 1);
407
+ }
408
+ /**
409
+ * ### Get Date
410
+ * - Returns the date with two digits
411
+ * @param {number|Date} date The date to get date
412
+ * @returns {string} The date with two digits
413
+ */
414
+ function getDate(date = d) {
415
+ if (typeof date !== 'number')
416
+ date = date.getDate();
417
+ let formattedDate = date.toString();
418
+ if (formattedDate.length === 1)
419
+ formattedDate = `0${formattedDate}`;
420
+ return formattedDate;
421
+ }
422
+ /**
423
+ * ### Get Hours
424
+ * - Returns the hours with two digits
425
+ * @param {number|Date} hours The date to get hours
426
+ * @returns {string} The hours with two digits
427
+ */
428
+ function getHours(hours = d) {
429
+ if (typeof hours !== 'number')
430
+ hours = hours.getHours();
431
+ let formattedHours = hours.toString();
432
+ if (formattedHours.length === 1)
433
+ formattedHours = `0${formattedHours}`;
434
+ return formattedHours;
435
+ }
436
+ /**
437
+ * ### Get Hours in 12
438
+ * - Returns the hour based on the specified 24 hour value in a 12 hour format
439
+ * @param {number|Date} hour The hour to be converted to 12 hour format
440
+ * @returns {number} The hour in a 12 hour format
441
+ */
442
+ function getHoursIn12(hour = d) {
443
+ if (typeof hour !== 'number')
444
+ hour = hour.getHours();
445
+ if (hour > 12)
446
+ return hour - 12;
447
+ return hour;
448
+ }
449
+ /**
450
+ * ### Get Meridian from Hour
451
+ * - Returns either 'pm' or 'am' based on the specified 24 hour value
452
+ * @param {number|Date} hour The hour to get the meridian from
453
+ * @returns {'am'|'pm'} The meridian for the given hour
454
+ */
455
+ function getMeridianFromHour(hour = d) {
456
+ if (typeof hour !== 'number')
457
+ hour = hour.getHours();
458
+ if (hour >= 12)
459
+ return 'pm';
460
+ return 'am';
461
+ }
462
+ /**
463
+ * ### Get Milliseconds
464
+ * - Returns the milliseconds with two digits
465
+ * @param {number|Date} milliseconds The date to get milliseconds
466
+ * @returns {string} The milliseconds with two digits
467
+ */
468
+ function getMilliseconds(milliseconds = d) {
469
+ if (typeof milliseconds !== 'number')
470
+ milliseconds = milliseconds.getMilliseconds();
471
+ let formattedMilliseconds = minutes.toString();
472
+ if (formattedMilliseconds.length === 1)
473
+ formattedMilliseconds = `0${formattedMilliseconds}`;
474
+ return formattedMilliseconds;
475
+ }
476
+ /**
477
+ * ### Get Minutes
478
+ * - Returns the minutes with two digits
479
+ * @param {number|Date} minutes The date to get minutes
480
+ * @returns {string} The minutes with two digits
481
+ */
482
+ function getMinutes(minutes = d) {
483
+ if (typeof minutes !== 'number')
484
+ minutes = minutes.getMinutes();
485
+ let formattedMinutes = minutes.toString();
486
+ if (formattedMinutes.length === 1)
487
+ formattedMinutes = `0${formattedMinutes}`;
488
+ return formattedMinutes;
489
+ }
490
+ /**
491
+ * ### Get Month
492
+ * - Returns the month with two digits
493
+ * @param {number|Date} month The date to get month
494
+ * @returns {string} The month with two digits
495
+ */
496
+ function getMonth(month = d) {
497
+ if (typeof month !== 'number')
498
+ month = month.getMonth() + 1;
499
+ let formattedMonth = month.toString();
500
+ if (formattedMonth.length === 1)
501
+ formattedMonth = `0${formattedMonth}`;
502
+ return formattedMonth;
503
+ }
504
+ function getMonthIndexFromName(name) {
505
+ return monthNamesList.findIndex(monthName => monthName === name);
506
+ }
507
+ /**
508
+ * ### Get Month Name
509
+ * - Returns the name of the specified month
510
+ * @param {Date} date A Date object representing the month to get the name of the month from. (Preset to the current date)
511
+ * @returns {MonthName} The name of the specified month
512
+ */
513
+ function getMonthName(date = d) {
514
+ if (typeof date === 'number')
515
+ return monthNamesList[date];
516
+ return monthNamesList[date.getMonth()];
517
+ }
518
+ /**
519
+ * ### Get Next Month
520
+ * - Returns the number of the following month from the specified month
521
+ * @param {Date} date The Date object representing the month to get the following month from (Preset to current date)
522
+ * @returns {number} The indexed month of the following month
523
+ */
524
+ function getNextMonth(date = d) {
525
+ const givenMonth = date.getMonth(); // Get the month from date
526
+ // Return the indexed month. min 0, max 11
527
+ return givenMonth === 11 ? 0 : givenMonth + 1;
528
+ }
529
+ /**
530
+ * ### Get Previous Month
531
+ * - Returns the number of the previous month from the specified month
532
+ * @param {Date} date The Date object representing the month to get the previous month from (Preset to current date)
533
+ * @returns {number} The indexed month of the previous month
534
+ */
535
+ function getPreviousMonth(date = d) {
536
+ const givenMonth = date.getMonth(); // Get the month from date
537
+ // Return the indexed month. min 0, max 11
538
+ return givenMonth === 0 ? 11 : givenMonth - 1;
539
+ }
540
+ /**
541
+ * ### Get Seconds
542
+ * - Returns the seconds with two digits
543
+ * @param {number|Date} seconds The date to get seconds
544
+ * @returns {string} The seconds with two digits
545
+ */
546
+ function getSeconds(seconds = d) {
547
+ if (typeof seconds !== 'number')
548
+ seconds = seconds.getSeconds();
549
+ let formattedSeconds = seconds.toString();
550
+ if (formattedSeconds.length === 1)
551
+ formattedSeconds = `0${formattedSeconds}`;
552
+ return formattedSeconds;
553
+ }
554
+ /**
555
+ * ### Get User Readable Date
556
+ * - Returns a string of the current date in a user-friendly way
557
+ * - Includes `'Yesterday'`, '`Today'`, and `'Tomorrow'`
558
+ * @param date (default: `new Date()`)
559
+ * @returns {'Today'|'Tomorrow'|'Yesterday'|string} `'weekday, month day, year'` | `'Yesterday'` | `'Today'` | `'Tomorrow'`
560
+ */
561
+ function getUserReadableDate(date = d) {
562
+ const dateTime = date.getTime();
563
+ const today = new Date(), isToday = dateTime === today.getTime();
564
+ if (isToday)
565
+ return 'Today';
566
+ const yesterday = new Date(today.getDate() - 1), isYesterday = dateTime === yesterday.getTime();
567
+ if (isYesterday)
568
+ return 'Yesterday';
569
+ const tomorrow = new Date(today.getDate() + 1), isTomorrow = dateTime === tomorrow.getTime();
570
+ if (isTomorrow)
571
+ return 'Tomorrow';
572
+ const thisYear = today.getFullYear(), isSameYear = date.getFullYear() === thisYear;
573
+ const fullDateString = toFullDateString(date, {
574
+ weekday: 'code',
575
+ year: !isSameYear,
576
+ });
577
+ return fullDateString;
578
+ }
579
+ /**
580
+ * ### Get Weekday Name
581
+ * - Returns the weekday name of the specified day
582
+ * @param {number | Date} weekday A Date object or number representing the day to get the weekday name from. (Preset to the current date)
583
+ * @returns {WeekdayName} The name of the specified weekday
584
+ */
585
+ function getWeekdayName(weekday = d) {
586
+ if (typeof weekday === 'number')
587
+ return weekdayNamesList[weekday];
588
+ // Return the name of the day of the week
589
+ return weekdayNamesList[weekday.getDay()];
590
+ }
591
+ /**
592
+ * ### Get Years in Range
593
+ * - Returns an array of years in between the specified minimum and maximum years
594
+ * @param {number} minYear The minimum year
595
+ * @param {number} maxYear The maximum year
596
+ * @returns {number[]} Array of years
597
+ */
598
+ function getYearsInRange(minYear = 0, maxYear = year) {
599
+ const yearList = [];
600
+ for (let selectedYear = minYear; selectedYear <= maxYear; selectedYear++) {
601
+ yearList.push(selectedYear);
602
+ }
603
+ return yearList;
604
+ }
605
+ /**
606
+ * ### To Full Date String
607
+ * - Returns a formatted string to display the date
608
+ * @param {Date} date (default: `new Date()`)
609
+ * @param {ToFullDateStringOptionsProps} options Change how to display the weekday, month name, day of the month, and year.
610
+ * @returns {string} '`weekday`, `month` `day`, `year`'
611
+ */
612
+ function toFullDateString(date = d, options) {
613
+ let weekdayName = getWeekdayName(date), monthName = getMonthName(date), dayOfMonth = date.getDate(), year = date.getFullYear().toString();
614
+ if (options) {
615
+ const includesWeekday = options.weekday !== false, includesDay = options.day !== false, includesMonth = options.month !== false, includesYear = options.year !== false;
616
+ if (includesWeekday) {
617
+ if (options.weekday === 'code')
618
+ weekdayName = weekdayName.slice(0, 3);
619
+ if (includesMonth || includesDay || includesYear)
620
+ weekdayName += ', ';
621
+ }
622
+ else {
623
+ weekdayName = '';
624
+ }
625
+ if (includesMonth) {
626
+ if (options.month === 'code')
627
+ monthName = monthName.slice(0, 3);
628
+ if (includesDay)
629
+ monthName += ' ';
630
+ }
631
+ else {
632
+ monthName = '';
633
+ }
634
+ if (!includesDay)
635
+ dayOfMonth = '';
636
+ if (includesYear) {
637
+ if (options.year === 'code')
638
+ year = year.slice(-2);
639
+ if (includesMonth || includesDay)
640
+ year = ', ' + year;
641
+ }
642
+ else {
643
+ year = '';
644
+ }
645
+ }
646
+ return weekdayName + monthName + dayOfMonth + year;
647
+ }
648
+ /**
649
+ * ### Get User Readable Date From Timestampz
650
+ * - Returns a string of the current date in a user-friendly way
651
+ * - Includes `'Yesterday'`, '`Today'`, and `'Tomorrow'`
652
+ * @param string
653
+ * @returns {'Today'|'Tomorrow'|'Yesterday'|string} `'weekday, month day, year'` | `'Yesterday'` | `'Today'` | `'Tomorrow'`
654
+ */
655
+ function getUserReadableDateFromTimestampz(timestampz) {
656
+ const [date, time] = timestampz.split('T') || [];
657
+ const [year, month, day] = date?.split('-').map(string => Number(string)) || [];
658
+ const timezoneIsAheadOfUTC = time?.includes('+');
659
+ const [hms, _timezone] = timezoneIsAheadOfUTC ? time?.split('+') : time?.split('-') || [];
660
+ const [hours, minutes, seconds] = hms?.split(':').map(string => Number(string)) || [];
661
+ // const [timezoneHours, timezoneMinutes] = timezone?.split(':').map(string => Number(string)) || []
662
+ const dateAndTime = new Date(year, month - 1, day, hours, minutes, seconds), userReadableDateAndTime = getUserReadableDate(dateAndTime);
663
+ return userReadableDateAndTime;
664
+ }
665
+
666
+ function findComponentByType(children, componentType) {
667
+ const childrenArray = Children.toArray(children);
668
+ for (const child of childrenArray) {
669
+ if (isValidElement(child) && child.type === componentType)
670
+ return child;
671
+ }
672
+ for (const child of childrenArray) {
673
+ if (isValidElement(child)) {
674
+ if (child.type === Fragment && child.props.children) {
675
+ const found = findComponentByType(child.props.children, componentType);
676
+ if (found)
677
+ return found;
678
+ }
679
+ else if (child.props.children) {
680
+ const found = findComponentByType(child.props.children, componentType);
681
+ if (found)
682
+ return found;
683
+ }
684
+ }
685
+ }
686
+ return null;
687
+ }
688
+
689
+ function easeOutExpo(time, start, end, duration) {
690
+ return time == duration ? start + end : end * (-Math.pow(2, (-10 * time) / duration) + 1) + start;
691
+ }
692
+
693
+ const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
694
+ /**
695
+ * # Is Email
696
+ * Checks whether the specified string is in email format
697
+ */
698
+ function isEmail(email) {
699
+ return emailRegex.test(email);
700
+ }
701
+ const telRegex = /(?:\+1\s|1\s|)?\d{3}\.\d{3}\.\d{4}|(?:\+1\s|1\s|)?\d{3}-\d{3}-\d{4}|(?:\+1\s|1\s|)?\(\d{3}\) \d{3}-\d{4}|(?:\+1\s|1\s|\+1|1|)?\d{10}/;
702
+ /**
703
+ * # Is Phone Number
704
+ * Checks whether the specified string is in phone number format
705
+ */
706
+ function isPhoneNumber(tel) {
707
+ return telRegex.test(tel);
708
+ }
709
+
710
+ /**
711
+ * # Format Phone Number
712
+ * Converts any string containing at least 10 numbers to a formatted phone number
713
+ * @param {string} string
714
+ * @returns {string} string formatted (000) 000-0000
715
+ */
716
+ function formatPhoneNumber(string, countryCode) {
717
+ return (`${countryCode ? `+${countryCode} ` : ''}` +
718
+ string
719
+ .replace(/\D/g, '')
720
+ .slice(-10)
721
+ .split('')
722
+ .map((char, index) => {
723
+ if (index === 0)
724
+ return `(${char}`;
725
+ if (index === 2)
726
+ return `${char}) `;
727
+ if (index === 5)
728
+ return `${char}-`;
729
+ return char;
730
+ })
731
+ .join(''));
732
+ }
733
+ /**
734
+ * # To Lower Case
735
+ * Converts a string to lowercase, and offers easy string replacements for creating snake case, kebab case, or your own.
736
+ * @param str - The string to convert to lowercase.
737
+ * @param options - Configuration options.
738
+ * @param options[0] - The delimiter to split the string. Defaults to space.
739
+ * @param options[1] - The string to join the parts back together. Defaults to space.
740
+ * @returns The lowercase version of the input string, with the replacements, if provided.
741
+ */
742
+ function toLowerCase(str, [delimiter, joiner]) {
743
+ return str.toLowerCase().replaceAll(delimiter || ' ', joiner || ' ');
744
+ }
745
+
746
+ function twSort(className) {
747
+ return className;
748
+ }
749
+
750
+ export { addClass, currentMonthName, currentWeekdayName, daysInMonth, easeOutExpo, emailRegex, extendMadoTailwindMerge, findComponentByType, firstOfMonth, formatPhoneNumber, getDate, getHours, getHoursIn12, getMeridianFromHour, getMilliseconds, getMinutes, getMonth, getMonthIndexFromName, getMonthName, getNextMonth, getPreviousMonth, getSeconds, getUserReadableDate, getUserReadableDateFromTimestampz, getWeekdayName, getYearsInRange, hasClass, isEmail, isPhoneNumber, monthNamesList, removeClass, telRegex, toFullDateString, toLowerCase, toggleClass, twMerge, twSort, weekdayNamesList };
751
+ //# sourceMappingURL=utils.esm.js.map