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