tods-competition-factory 1.9.4 → 1.9.5
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/forge/generate.mjs +1 -0
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.d.ts +9 -18
- package/dist/forge/query.mjs +1 -0
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.d.ts +3 -3
- package/dist/forge/transform.mjs +1 -0
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/forge/utilities.d.ts +2 -1
- package/dist/forge/utilities.mjs +25 -24
- package/dist/forge/utilities.mjs.map +1 -1
- package/dist/index.mjs +732 -731
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +1387 -1386
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1543,706 +1543,29 @@ function globalLog$1(engine, log) {
|
|
|
1543
1543
|
}
|
|
1544
1544
|
}
|
|
1545
1545
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
function
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
if (!
|
|
1556
|
-
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
return
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
function validTimeValue(value) {
|
|
1572
|
-
const spaceSplit = typeof value === "string" ? value?.split(" ") : [];
|
|
1573
|
-
if (value && spaceSplit?.length > 1 && !["AM", "PM"].includes(spaceSplit[1].toUpperCase()))
|
|
1574
|
-
return false;
|
|
1575
|
-
return !!(!value || timeValidation.test(convertTime(value, true, true)));
|
|
1576
|
-
}
|
|
1577
|
-
function isValidDateString(scheduleDate) {
|
|
1578
|
-
return isISODateString(scheduleDate) || validDateString.test(scheduleDate);
|
|
1579
|
-
}
|
|
1580
|
-
function DateHHMM(date) {
|
|
1581
|
-
const dt = new Date(date);
|
|
1582
|
-
const secs = dt.getSeconds() + 60 * dt.getMinutes() + 60 * 60 * dt.getHours();
|
|
1583
|
-
return HHMMSS(secs, { displaySeconds: false });
|
|
1584
|
-
}
|
|
1585
|
-
function HHMMSS(s, format) {
|
|
1586
|
-
const secondNumber = parseInt(s, 10);
|
|
1587
|
-
const hours = Math.floor(secondNumber / 3600);
|
|
1588
|
-
const minutes = Math.floor((secondNumber - hours * 3600) / 60);
|
|
1589
|
-
const seconds = secondNumber - hours * 3600 - minutes * 60;
|
|
1590
|
-
const displaySeconds = !format || format?.displaySeconds;
|
|
1591
|
-
const timeString = displaySeconds ? hours + ":" + minutes + ":" + seconds : hours + ":" + minutes;
|
|
1592
|
-
return timeString.split(":").map(zeroPad).join(":");
|
|
1593
|
-
}
|
|
1594
|
-
const getUTCdateString = (date) => {
|
|
1595
|
-
const dateDate = isDate(date) || isISODateString(date) ? new Date(date) : /* @__PURE__ */ new Date();
|
|
1596
|
-
const monthNumber = dateDate.getUTCMonth() + 1;
|
|
1597
|
-
const utcMonth = monthNumber < 10 ? `0${monthNumber}` : `${monthNumber}`;
|
|
1598
|
-
return `${dateDate.getUTCFullYear()}-${zeroPad(utcMonth)}-${zeroPad(
|
|
1599
|
-
dateDate.getUTCDate()
|
|
1600
|
-
)}`;
|
|
1601
|
-
};
|
|
1602
|
-
function timeUTC(date) {
|
|
1603
|
-
const dateDate = isDate(date) || isISODateString(date) ? new Date(date) : /* @__PURE__ */ new Date();
|
|
1604
|
-
return Date.UTC(
|
|
1605
|
-
dateDate.getFullYear(),
|
|
1606
|
-
dateDate.getMonth(),
|
|
1607
|
-
dateDate.getDate()
|
|
1608
|
-
);
|
|
1609
|
-
}
|
|
1610
|
-
function formatDate(date, separator = "-", format = "YMD") {
|
|
1611
|
-
if (!date)
|
|
1612
|
-
return "";
|
|
1613
|
-
if (typeof date === "string" && date.indexOf("T") < 0)
|
|
1614
|
-
date = date + "T00:00";
|
|
1615
|
-
const d = new Date(date);
|
|
1616
|
-
let month = "" + (d.getMonth() + 1);
|
|
1617
|
-
let day = "" + d.getDate();
|
|
1618
|
-
const year = d.getFullYear();
|
|
1619
|
-
if (month.length < 2)
|
|
1620
|
-
month = "0" + month;
|
|
1621
|
-
if (day.length < 2)
|
|
1622
|
-
day = "0" + day;
|
|
1623
|
-
if (format === "DMY")
|
|
1624
|
-
return [day, month, year].join(separator);
|
|
1625
|
-
if (format === "MDY")
|
|
1626
|
-
return [month, day, year].join(separator);
|
|
1627
|
-
if (format === "YDM")
|
|
1628
|
-
return [year, day, month].join(separator);
|
|
1629
|
-
if (format === "DYM")
|
|
1630
|
-
return [day, year, month].join(separator);
|
|
1631
|
-
if (format === "MYD")
|
|
1632
|
-
return [month, year, day].join(separator);
|
|
1633
|
-
return [year, month, day].join(separator);
|
|
1634
|
-
}
|
|
1635
|
-
function offsetDate(date) {
|
|
1636
|
-
const targetTime = date ? new Date(date) : /* @__PURE__ */ new Date();
|
|
1637
|
-
const tzDifference = targetTime.getTimezoneOffset();
|
|
1638
|
-
return new Date(targetTime.getTime() - tzDifference * 60 * 1e3);
|
|
1639
|
-
}
|
|
1640
|
-
function offsetTime(date) {
|
|
1641
|
-
return offsetDate(date).getTime();
|
|
1642
|
-
}
|
|
1643
|
-
function isDate(dateArg) {
|
|
1644
|
-
if (typeof dateArg == "boolean")
|
|
1645
|
-
return false;
|
|
1646
|
-
const t = dateArg instanceof Date && dateArg || !isNaN(dateArg) && new Date(dateArg) || false;
|
|
1647
|
-
return t && !isNaN(t.valueOf());
|
|
1648
|
-
}
|
|
1649
|
-
function dateRange(startDt, endDt) {
|
|
1650
|
-
if (!isValidDateString(startDt) || !isValidDateString(endDt))
|
|
1651
|
-
return [];
|
|
1652
|
-
const startDateString = extractDate(startDt) + "T00:00";
|
|
1653
|
-
const endDateString = extractDate(endDt) + "T00:00";
|
|
1654
|
-
const startDate = new Date(startDateString);
|
|
1655
|
-
const endDate = new Date(endDateString);
|
|
1656
|
-
const process = isDate(endDate) && isDate(startDate) && isValidDateRange(startDate, endDate);
|
|
1657
|
-
const between = [];
|
|
1658
|
-
let iterations = 0;
|
|
1659
|
-
if (process) {
|
|
1660
|
-
const currentDate = startDate;
|
|
1661
|
-
let dateSecs = currentDate.getTime();
|
|
1662
|
-
while (dateSecs <= endDate.getTime() && iterations < 300) {
|
|
1663
|
-
iterations += 1;
|
|
1664
|
-
between.push(new Date(currentDate));
|
|
1665
|
-
dateSecs = currentDate.setDate(currentDate.getDate() + 1);
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
return between.map((date) => formatDate(date));
|
|
1669
|
-
function isValidDateRange(minDate, maxDate) {
|
|
1670
|
-
return minDate <= maxDate;
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
const re = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
1674
|
-
function isISODateString(dateString) {
|
|
1675
|
-
if (typeof dateString !== "string")
|
|
1676
|
-
return false;
|
|
1677
|
-
return re.test(dateString);
|
|
1678
|
-
}
|
|
1679
|
-
function isTimeString(timeString) {
|
|
1680
|
-
if (typeof timeString !== "string")
|
|
1681
|
-
return false;
|
|
1682
|
-
const noZ = timeString.split("Z")[0];
|
|
1683
|
-
const parts = noZ.split(":");
|
|
1684
|
-
const isNumeric = parts.every((part) => !isNaN(parseInt(part)));
|
|
1685
|
-
const invalid = parts.length < 2 || !isNumeric || parseInt(parts[0]) > 23 || parseInt(parts[1]) > 60;
|
|
1686
|
-
return !invalid;
|
|
1687
|
-
}
|
|
1688
|
-
function timeStringMinutes(timeString) {
|
|
1689
|
-
const validTimeString = extractTime(timeString);
|
|
1690
|
-
if (!validTimeString)
|
|
1691
|
-
return 0;
|
|
1692
|
-
const [hours, minutes] = validTimeString.split(":").map((value) => parseInt(value));
|
|
1693
|
-
return hours * 60 + minutes;
|
|
1694
|
-
}
|
|
1695
|
-
function dayMinutesToTimeString(totalMinutes) {
|
|
1696
|
-
let hours = Math.floor(totalMinutes / 60);
|
|
1697
|
-
const minutes = totalMinutes - hours * 60;
|
|
1698
|
-
if (hours > 23)
|
|
1699
|
-
hours = hours % 24;
|
|
1700
|
-
return [zeroPad(hours), zeroPad(minutes)].join(":");
|
|
1701
|
-
}
|
|
1702
|
-
function tidyTime(timeString) {
|
|
1703
|
-
return isTimeString(timeString) ? timeString.split(":").slice(0, 2).map(zeroPad).join(":") : void 0;
|
|
1704
|
-
}
|
|
1705
|
-
function extractTime(dateString) {
|
|
1706
|
-
return isISODateString(dateString) && dateString.indexOf("T") > 0 ? tidyTime(dateString.split("T").reverse()[0]) : tidyTime(dateString);
|
|
1707
|
-
}
|
|
1708
|
-
function extractDate(dateString) {
|
|
1709
|
-
return isISODateString(dateString) || dateValidation.test(dateString) ? dateString.split("T")[0] : void 0;
|
|
1710
|
-
}
|
|
1711
|
-
function dateStringDaysChange(dateString, daysChange) {
|
|
1712
|
-
const date = new Date(dateString);
|
|
1713
|
-
date.setDate(date.getDate() + daysChange);
|
|
1714
|
-
return extractDate(date.toISOString());
|
|
1715
|
-
}
|
|
1716
|
-
function splitTime(value) {
|
|
1717
|
-
value = typeof value !== "string" ? "00:00" : value;
|
|
1718
|
-
const o = {}, time = {};
|
|
1719
|
-
({ 0: o.time, 1: o.ampm } = value.split(" ") || []);
|
|
1720
|
-
({ 0: time.hours, 1: time.minutes } = o.time.split(":") || []);
|
|
1721
|
-
time.ampm = o.ampm;
|
|
1722
|
-
if (isNaN(time.hours) || isNaN(time.minutes) || time.ampm && !["AM", "PM"].includes(time.ampm.toUpperCase()))
|
|
1723
|
-
return {};
|
|
1724
|
-
return time;
|
|
1725
|
-
}
|
|
1726
|
-
function militaryTime(value) {
|
|
1727
|
-
const time = splitTime(value);
|
|
1728
|
-
if (time.ampm && time.hours) {
|
|
1729
|
-
if (time.ampm.toLowerCase() === "pm" && parseInt(time.hours) < 12)
|
|
1730
|
-
time.hours = (time.hours && parseInt(time.hours) || 0) + 12;
|
|
1731
|
-
if (time.ampm.toLowerCase() === "am" && time.hours === "12")
|
|
1732
|
-
time.hours = "00";
|
|
1733
|
-
}
|
|
1734
|
-
const timeString = `${time.hours || "12"}:${time.minutes || "00"}`;
|
|
1735
|
-
return timeString.split(":").map(zeroPad).join(":");
|
|
1736
|
-
}
|
|
1737
|
-
function regularTime(value) {
|
|
1738
|
-
const time = splitTime(value);
|
|
1739
|
-
if (typeof time === "object" && !Object.keys(time).length)
|
|
1740
|
-
return void 0;
|
|
1741
|
-
if (time.ampm)
|
|
1742
|
-
return value;
|
|
1743
|
-
if (time.hours > 12) {
|
|
1744
|
-
time.hours -= 12;
|
|
1745
|
-
time.ampm = "PM";
|
|
1746
|
-
} else if (time.hours === "12") {
|
|
1747
|
-
time.ampm = "PM";
|
|
1748
|
-
} else if (time.hours === "00") {
|
|
1749
|
-
time.hours = "12";
|
|
1750
|
-
time.ampm = "AM";
|
|
1751
|
-
} else {
|
|
1752
|
-
time.ampm = "AM";
|
|
1753
|
-
}
|
|
1754
|
-
if (time.hours?.[0] === "0") {
|
|
1755
|
-
time.hours = time.hours.slice(1);
|
|
1756
|
-
}
|
|
1757
|
-
return `${time.hours || "12"}:${time.minutes || "00"} ${time.ampm}`;
|
|
1758
|
-
}
|
|
1759
|
-
function convertTime(value, time24, keepDate) {
|
|
1760
|
-
const hasDate = extractDate(value);
|
|
1761
|
-
const timeString = extractTime(value);
|
|
1762
|
-
const timeValue = hasDate ? timeString : value;
|
|
1763
|
-
return !value ? void 0 : time24 && (hasDate && keepDate && value || militaryTime(timeValue)) || regularTime(timeValue);
|
|
1764
|
-
}
|
|
1765
|
-
function timeSort(a, b) {
|
|
1766
|
-
const as = splitTime(a);
|
|
1767
|
-
const bs = splitTime(b);
|
|
1768
|
-
if (parseInt(as.hours) < parseInt(bs.hours))
|
|
1769
|
-
return -1;
|
|
1770
|
-
if (parseInt(as.hours) > parseInt(bs.hours))
|
|
1771
|
-
return 1;
|
|
1772
|
-
if (as.hours === bs.hours) {
|
|
1773
|
-
if (parseInt(as.minutes) < parseInt(bs.minutes))
|
|
1774
|
-
return -1;
|
|
1775
|
-
if (parseInt(as.minutes) > parseInt(bs.minutes))
|
|
1776
|
-
return 1;
|
|
1777
|
-
}
|
|
1778
|
-
return 0;
|
|
1779
|
-
}
|
|
1780
|
-
function addDays(date, days = 7) {
|
|
1781
|
-
const universalDate = extractDate(date) + "T00:00";
|
|
1782
|
-
const now = new Date(universalDate);
|
|
1783
|
-
const adjustedDate = new Date(now.setDate(now.getDate() + days));
|
|
1784
|
-
return formatDate(adjustedDate);
|
|
1785
|
-
}
|
|
1786
|
-
function addWeek(date) {
|
|
1787
|
-
return addDays(date);
|
|
1788
|
-
}
|
|
1789
|
-
function getDateByWeek(week, year, dateFormat, sunday = false) {
|
|
1790
|
-
const date = new Date(year, 0, 1 + (week - 1) * 7);
|
|
1791
|
-
const startValue = sunday ? 0 : 1;
|
|
1792
|
-
date.setDate(date.getDate() + (startValue - date.getDay()));
|
|
1793
|
-
return formatDate(date, dateFormat);
|
|
1794
|
-
}
|
|
1795
|
-
function dateFromDay(year, day, dateFormat) {
|
|
1796
|
-
const date = new Date(year, 0);
|
|
1797
|
-
return formatDate(new Date(date.setDate(day)), dateFormat);
|
|
1798
|
-
}
|
|
1799
|
-
function timeToDate(timeString, date = void 0) {
|
|
1800
|
-
const [hours, minutes] = (timeString || "00:00").split(":").map(zeroPad);
|
|
1801
|
-
const milliseconds = offsetDate(date).setHours(hours, minutes, 0, 0);
|
|
1802
|
-
return offsetDate(milliseconds);
|
|
1803
|
-
}
|
|
1804
|
-
function minutesDifference(date1, date2, absolute = true) {
|
|
1805
|
-
const dt1 = new Date(date1);
|
|
1806
|
-
const dt2 = new Date(date2);
|
|
1807
|
-
const diff = (dt2.getTime() - dt1.getTime()) / 1e3 / 60;
|
|
1808
|
-
return absolute ? Math.abs(Math.round(diff)) : Math.round(diff);
|
|
1809
|
-
}
|
|
1810
|
-
function addMinutesToTimeString(timeString, minutes) {
|
|
1811
|
-
const validTimeString = extractTime(timeString);
|
|
1812
|
-
if (!validTimeString)
|
|
1813
|
-
return "00:00";
|
|
1814
|
-
const minutesToAdd = isNaN(minutes) ? 0 : minutes;
|
|
1815
|
-
return extractTime(
|
|
1816
|
-
addMinutes(timeToDate(validTimeString), minutesToAdd).toISOString()
|
|
1817
|
-
);
|
|
1818
|
-
}
|
|
1819
|
-
function addMinutes(startDate, minutes) {
|
|
1820
|
-
const date = new Date(startDate);
|
|
1821
|
-
return new Date(date.getTime() + minutes * 6e4);
|
|
1822
|
-
}
|
|
1823
|
-
function zeroPad(number) {
|
|
1824
|
-
return number.toString()[1] ? number : "0" + number;
|
|
1825
|
-
}
|
|
1826
|
-
function sameDay(date1, date2) {
|
|
1827
|
-
const d1 = new Date(date1);
|
|
1828
|
-
const d2 = new Date(date2);
|
|
1829
|
-
return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();
|
|
1830
|
-
}
|
|
1831
|
-
const dateTime = {
|
|
1832
|
-
addDays,
|
|
1833
|
-
addWeek,
|
|
1834
|
-
addMinutesToTimeString,
|
|
1835
|
-
convertTime,
|
|
1836
|
-
getIsoDateString,
|
|
1837
|
-
getUTCdateString,
|
|
1838
|
-
DateHHMM,
|
|
1839
|
-
extractDate,
|
|
1840
|
-
extractTime,
|
|
1841
|
-
formatDate,
|
|
1842
|
-
getDateByWeek,
|
|
1843
|
-
isISODateString,
|
|
1844
|
-
isDate,
|
|
1845
|
-
isTimeString,
|
|
1846
|
-
offsetDate,
|
|
1847
|
-
offsetTime,
|
|
1848
|
-
sameDay,
|
|
1849
|
-
timeStringMinutes,
|
|
1850
|
-
timeToDate,
|
|
1851
|
-
timeUTC,
|
|
1852
|
-
validTimeValue,
|
|
1853
|
-
validDateString,
|
|
1854
|
-
timeValidation,
|
|
1855
|
-
dateValidation
|
|
1856
|
-
};
|
|
1857
|
-
|
|
1858
|
-
function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
|
|
1859
|
-
if (getProvider().makeDeepCopy)
|
|
1860
|
-
return getProvider().makeDeepCopy(
|
|
1861
|
-
sourceObject,
|
|
1862
|
-
convertExtensions,
|
|
1863
|
-
internalUse,
|
|
1864
|
-
removeExtensions
|
|
1865
|
-
);
|
|
1866
|
-
const deepCopy = deepCopyEnabled();
|
|
1867
|
-
const { stringify, toJSON, ignore, modulate } = deepCopy || {};
|
|
1868
|
-
if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
|
|
1869
|
-
return sourceObject;
|
|
1870
|
-
}
|
|
1871
|
-
const targetObject = Array.isArray(sourceObject) ? [] : {};
|
|
1872
|
-
const sourceObjectKeys = Object.keys(sourceObject).filter(
|
|
1873
|
-
(key) => !internalUse || !ignore || Array.isArray(ignore) && !ignore.includes(key) || typeof ignore === "function" && !ignore(key)
|
|
1874
|
-
);
|
|
1875
|
-
const stringifyValue = (key, value) => {
|
|
1876
|
-
targetObject[key] = typeof value?.toString === "function" ? value.toString() : JSON.stringify(value);
|
|
1877
|
-
};
|
|
1878
|
-
for (const key of sourceObjectKeys) {
|
|
1879
|
-
const value = sourceObject[key];
|
|
1880
|
-
const modulated = typeof modulate === "function" ? modulate(value) : void 0;
|
|
1881
|
-
if (modulated !== void 0) {
|
|
1882
|
-
targetObject[key] = modulated;
|
|
1883
|
-
} else if (convertExtensions && key === "extensions" && Array.isArray(value)) {
|
|
1884
|
-
const extensionConversions = extensionsToAttributes(value);
|
|
1885
|
-
Object.assign(targetObject, ...extensionConversions);
|
|
1886
|
-
} else if (removeExtensions && key === "extensions") {
|
|
1887
|
-
targetObject[key] = [];
|
|
1888
|
-
} else if (Array.isArray(stringify) && stringify.includes(key)) {
|
|
1889
|
-
stringifyValue(key, value);
|
|
1890
|
-
} else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === "function") {
|
|
1891
|
-
targetObject[key] = value.toJSON();
|
|
1892
|
-
} else if (value === null) {
|
|
1893
|
-
targetObject[key] = void 0;
|
|
1894
|
-
} else if (isDateObject(value)) {
|
|
1895
|
-
targetObject[key] = new Date(value).toISOString();
|
|
1896
|
-
} else {
|
|
1897
|
-
targetObject[key] = makeDeepCopy(
|
|
1898
|
-
value,
|
|
1899
|
-
convertExtensions,
|
|
1900
|
-
internalUse,
|
|
1901
|
-
removeExtensions,
|
|
1902
|
-
iteration + 1
|
|
1903
|
-
);
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
return targetObject;
|
|
1907
|
-
}
|
|
1908
|
-
function extensionsToAttributes(extensions) {
|
|
1909
|
-
return extensions?.map((extension) => {
|
|
1910
|
-
const { name, value } = extension;
|
|
1911
|
-
return name && value && { [`_${name}`]: value };
|
|
1912
|
-
}).filter(Boolean);
|
|
1913
|
-
}
|
|
1914
|
-
|
|
1915
|
-
function getAccessorValue({ element, accessor }) {
|
|
1916
|
-
if (typeof accessor !== "string")
|
|
1917
|
-
return { values: [] };
|
|
1918
|
-
const targetElement = makeDeepCopy(element);
|
|
1919
|
-
const attributes = accessor.split(".");
|
|
1920
|
-
const values = [];
|
|
1921
|
-
let value;
|
|
1922
|
-
processKeys({ targetElement, attributes });
|
|
1923
|
-
const result = { value };
|
|
1924
|
-
if (values.length)
|
|
1925
|
-
result.values = values;
|
|
1926
|
-
return result;
|
|
1927
|
-
function processKeys({
|
|
1928
|
-
targetElement: targetElement2,
|
|
1929
|
-
attributes: attributes2 = [],
|
|
1930
|
-
significantCharacters
|
|
1931
|
-
}) {
|
|
1932
|
-
for (const [index, attribute] of attributes2.entries()) {
|
|
1933
|
-
if (targetElement2?.[attribute]) {
|
|
1934
|
-
const remainingKeys = attributes2.slice(index + 1);
|
|
1935
|
-
if (!remainingKeys.length) {
|
|
1936
|
-
if (!value)
|
|
1937
|
-
value = targetElement2[attribute];
|
|
1938
|
-
if (!values.includes(targetElement2[attribute])) {
|
|
1939
|
-
values.push(targetElement2[attribute]);
|
|
1940
|
-
}
|
|
1941
|
-
} else if (Array.isArray(targetElement2[attribute])) {
|
|
1942
|
-
const values2 = targetElement2[attribute];
|
|
1943
|
-
values2.forEach(
|
|
1944
|
-
(nestedTarget) => processKeys({
|
|
1945
|
-
targetElement: nestedTarget,
|
|
1946
|
-
attributes: remainingKeys
|
|
1947
|
-
})
|
|
1948
|
-
);
|
|
1949
|
-
} else {
|
|
1950
|
-
targetElement2 = targetElement2[attribute];
|
|
1951
|
-
checkValue({ targetElement: targetElement2, index });
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
function checkValue({ targetElement: targetElement3, index }) {
|
|
1956
|
-
if (targetElement3 && index === attributes2.length - 1 && ["string", "number"].includes(typeof targetElement3)) {
|
|
1957
|
-
const extractedValue = significantCharacters ? targetElement3.slice(0, significantCharacters) : targetElement3;
|
|
1958
|
-
if (value) {
|
|
1959
|
-
if (!values.includes(extractedValue)) {
|
|
1960
|
-
values.push(extractedValue);
|
|
1961
|
-
}
|
|
1962
|
-
} else {
|
|
1963
|
-
value = extractedValue;
|
|
1964
|
-
values.push(extractedValue);
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
function isString(obj) {
|
|
1972
|
-
return typeof obj === "string";
|
|
1973
|
-
}
|
|
1974
|
-
function isObject(obj) {
|
|
1975
|
-
return obj !== null && typeof obj === "object";
|
|
1976
|
-
}
|
|
1977
|
-
function objShallowEqual(o1, o2) {
|
|
1978
|
-
if (!isObject(o1) || !isObject(o2))
|
|
1979
|
-
return false;
|
|
1980
|
-
const keys1 = Object.keys(o1);
|
|
1981
|
-
const keys2 = Object.keys(o2);
|
|
1982
|
-
if (keys1.length !== keys2.length) {
|
|
1983
|
-
return false;
|
|
1984
|
-
}
|
|
1985
|
-
for (const key of keys1) {
|
|
1986
|
-
if (o1[key] !== o2[key]) {
|
|
1987
|
-
return false;
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
return true;
|
|
1991
|
-
}
|
|
1992
|
-
function createMap(objectArray, attribute) {
|
|
1993
|
-
if (!Array.isArray(objectArray))
|
|
1994
|
-
return {};
|
|
1995
|
-
return Object.assign(
|
|
1996
|
-
{},
|
|
1997
|
-
...(objectArray ?? []).filter(isObject).map((obj) => {
|
|
1998
|
-
return obj[attribute] && {
|
|
1999
|
-
[obj[attribute]]: obj
|
|
2000
|
-
};
|
|
2001
|
-
}).filter(Boolean)
|
|
2002
|
-
);
|
|
2003
|
-
}
|
|
2004
|
-
const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
|
|
2005
|
-
const extractAttributes = (accessor) => (element) => !accessor || typeof element !== "object" ? void 0 : Array.isArray(accessor) && accessor.map((a) => ({
|
|
2006
|
-
[a]: getAccessorValue({ element, accessor: a })?.value
|
|
2007
|
-
})) || typeof accessor === "object" && Object.keys(accessor).map((key) => ({
|
|
2008
|
-
[key]: getAccessorValue({ element, accessor: key })?.value
|
|
2009
|
-
})) || (typeof accessor === "string" && getAccessorValue({ element, accessor }))?.value;
|
|
2010
|
-
function getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays) {
|
|
2011
|
-
return Object.keys(obj).filter(
|
|
2012
|
-
(key) => !ignoreValues.includes(obj[key]) && (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true))
|
|
2013
|
-
);
|
|
2014
|
-
}
|
|
2015
|
-
function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
|
|
2016
|
-
if (typeof obj !== "object" || obj === null)
|
|
2017
|
-
return obj;
|
|
2018
|
-
const deepCopy = deepCopyEnabled();
|
|
2019
|
-
if (!deepCopy?.enabled)
|
|
2020
|
-
shallow = true;
|
|
2021
|
-
const ignoreValues = ["", void 0, null];
|
|
2022
|
-
if (ignoreFalse)
|
|
2023
|
-
ignoreValues.push(false);
|
|
2024
|
-
const definedKeys = getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays);
|
|
2025
|
-
return Object.assign(
|
|
2026
|
-
{},
|
|
2027
|
-
...definedKeys.map((key) => {
|
|
2028
|
-
return Array.isArray(obj[key]) ? {
|
|
2029
|
-
[key]: shallow ? obj[key] : obj[key].map((m) => definedAttributes(m))
|
|
2030
|
-
} : { [key]: shallow ? obj[key] : definedAttributes(obj[key]) };
|
|
2031
|
-
})
|
|
2032
|
-
);
|
|
2033
|
-
}
|
|
2034
|
-
function countKeys(o) {
|
|
2035
|
-
if (Array.isArray(o)) {
|
|
2036
|
-
return o.length + o.map(countKeys).reduce((a, b) => a + b, 0);
|
|
2037
|
-
} else if (typeof o === "object" && o !== null) {
|
|
2038
|
-
return Object.keys(o).length + Object.keys(o).map((k) => countKeys(o[k])).reduce((a, b) => a + b, 0);
|
|
2039
|
-
}
|
|
2040
|
-
return 0;
|
|
2041
|
-
}
|
|
2042
|
-
function generateHashCode(o) {
|
|
2043
|
-
if (o === null || typeof o !== "object")
|
|
2044
|
-
return void 0;
|
|
2045
|
-
const str = JSON.stringify(o);
|
|
2046
|
-
const keyCount = countKeys(o);
|
|
2047
|
-
const charSum = str.split("").reduce((a, b) => a + b.charCodeAt(0), 0);
|
|
2048
|
-
return [str.length, keyCount, charSum].map((e) => e.toString(36)).join("");
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
function attributeFilter(params) {
|
|
2052
|
-
if (params === null)
|
|
2053
|
-
return {};
|
|
2054
|
-
const { source, template } = params || {};
|
|
2055
|
-
if (!template)
|
|
2056
|
-
return source;
|
|
2057
|
-
const target = {};
|
|
2058
|
-
attributeCopy(source, template, target);
|
|
2059
|
-
return target;
|
|
2060
|
-
function attributeCopy(valuesObject, templateObject, outputObject) {
|
|
2061
|
-
if (!valuesObject || !templateObject)
|
|
2062
|
-
return void 0;
|
|
2063
|
-
const vKeys = Object.keys(valuesObject);
|
|
2064
|
-
const oKeys = Object.keys(templateObject);
|
|
2065
|
-
const orMap = Object.assign(
|
|
2066
|
-
{},
|
|
2067
|
-
...oKeys.filter((key) => key.indexOf("||")).map((key) => key.split("||").map((or) => ({ [or]: key }))).flat()
|
|
2068
|
-
);
|
|
2069
|
-
const allKeys = oKeys.concat(...Object.keys(orMap));
|
|
2070
|
-
const wildcard = allKeys.includes("*");
|
|
2071
|
-
for (const vKey of vKeys) {
|
|
2072
|
-
if (allKeys.indexOf(vKey) >= 0 || wildcard) {
|
|
2073
|
-
const templateKey = orMap[vKey] || vKey;
|
|
2074
|
-
const tobj = templateObject[templateKey] || wildcard;
|
|
2075
|
-
const vobj = valuesObject[vKey];
|
|
2076
|
-
if (typeof tobj === "object" && typeof vobj !== "function" && !Array.isArray(tobj)) {
|
|
2077
|
-
if (Array.isArray(vobj)) {
|
|
2078
|
-
const mappedElements = vobj.map((arrayMember) => {
|
|
2079
|
-
const target2 = {};
|
|
2080
|
-
const result = attributeCopy(arrayMember, tobj, target2);
|
|
2081
|
-
return result !== false ? target2 : void 0;
|
|
2082
|
-
}).filter(Boolean);
|
|
2083
|
-
outputObject[vKey] = mappedElements;
|
|
2084
|
-
} else if (vobj) {
|
|
2085
|
-
outputObject[vKey] = {};
|
|
2086
|
-
attributeCopy(vobj, tobj, outputObject[vKey]);
|
|
2087
|
-
}
|
|
2088
|
-
} else {
|
|
2089
|
-
const value = valuesObject[vKey];
|
|
2090
|
-
const exclude = Array.isArray(tobj) && !tobj.includes(value);
|
|
2091
|
-
if (exclude)
|
|
2092
|
-
return false;
|
|
2093
|
-
if (templateObject[vKey] || wildcard && templateObject[vKey] !== false) {
|
|
2094
|
-
outputObject[vKey] = value;
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
return void 0;
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
|
-
function generateTimeCode(index = 0) {
|
|
2104
|
-
const uidate = /* @__PURE__ */ new Date();
|
|
2105
|
-
uidate.setHours(uidate.getHours() + index);
|
|
2106
|
-
return uidate.getTime().toString(36).slice(-6).toUpperCase();
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
function JSON2CSV(arrayOfJSON, config) {
|
|
2110
|
-
if (config && typeof config !== "object")
|
|
2111
|
-
return INVALID_VALUES;
|
|
2112
|
-
let { columnTransform = {} } = config || {};
|
|
2113
|
-
const {
|
|
2114
|
-
includeTransformAccessors,
|
|
2115
|
-
includeHeaderRow = true,
|
|
2116
|
-
returnTransformedJSON,
|
|
2117
|
-
removeEmptyColumns,
|
|
2118
|
-
onlyHeaderRow,
|
|
2119
|
-
columnAccessors = [],
|
|
2120
|
-
functionMap = {},
|
|
2121
|
-
columnMap = {},
|
|
2122
|
-
valuesMap = {},
|
|
2123
|
-
context = {},
|
|
2124
|
-
delimiter = '"',
|
|
2125
|
-
columnJoiner = ",",
|
|
2126
|
-
rowJoiner = "\r\n",
|
|
2127
|
-
keyJoiner = "."
|
|
2128
|
-
} = config || {};
|
|
2129
|
-
if (!Array.isArray(arrayOfJSON) || !Array.isArray(columnAccessors) || typeof context !== "object" || typeof columnMap !== "object" || typeof columnTransform !== "object" || typeof functionMap !== "object" || typeof valuesMap !== "object" || typeof columnJoiner !== "string" || typeof rowJoiner !== "string" || typeof keyJoiner !== "string" || typeof delimiter !== "string")
|
|
2130
|
-
return INVALID_VALUES;
|
|
2131
|
-
columnTransform = Object.assign(
|
|
2132
|
-
{},
|
|
2133
|
-
...Object.keys(columnTransform).reverse().map((key) => ({
|
|
2134
|
-
[key]: Array.isArray(columnTransform[key]) ? columnTransform[key] : [
|
|
2135
|
-
// ensure transform attributes are strings
|
|
2136
|
-
typeof columnTransform[key] === "string" && columnTransform[key]
|
|
2137
|
-
].filter(Boolean)
|
|
2138
|
-
}))
|
|
2139
|
-
);
|
|
2140
|
-
const flattened = arrayOfJSON.filter(Boolean).map((obj) => flattenJSON(obj, keyJoiner));
|
|
2141
|
-
const transformColumns = Object.values(columnTransform).flat();
|
|
2142
|
-
if (includeTransformAccessors)
|
|
2143
|
-
columnAccessors.push(...transformColumns);
|
|
2144
|
-
const headerRow = flattened.reduce(
|
|
2145
|
-
(aggregator, row) => Object.keys(row).every(
|
|
2146
|
-
(key) => !aggregator.includes(key) && aggregator.push(key) || true
|
|
2147
|
-
) && aggregator,
|
|
2148
|
-
[]
|
|
2149
|
-
).filter((key) => !columnAccessors?.length || columnAccessors.includes(key));
|
|
2150
|
-
const accessorMap = Object.assign(
|
|
2151
|
-
{},
|
|
2152
|
-
...Object.keys(columnTransform).reverse().map(
|
|
2153
|
-
(transform) => columnTransform[transform].map((value) => ({ [value]: transform })).flat()
|
|
2154
|
-
).flat()
|
|
2155
|
-
);
|
|
2156
|
-
const sortColumns = (a, b) => !config?.sortOrder ? 0 : config.sortOrder.includes(a) && config.sortOrder.includes(b) && config.sortOrder.indexOf(a) - config.sortOrder.indexOf(b) || !config.sortOrder.includes(b) && -1;
|
|
2157
|
-
const tranformedHeaderRow = headerRow.reduce((def, key) => {
|
|
2158
|
-
const transform = accessorMap[key];
|
|
2159
|
-
if (transform) {
|
|
2160
|
-
if (!def.includes(transform))
|
|
2161
|
-
def.push(transform);
|
|
2162
|
-
} else {
|
|
2163
|
-
def.push(key);
|
|
2164
|
-
}
|
|
2165
|
-
return def;
|
|
2166
|
-
}, []).sort(sortColumns);
|
|
2167
|
-
Object.keys(columnMap).forEach(
|
|
2168
|
-
(columnName) => !tranformedHeaderRow.includes(columnName) && tranformedHeaderRow.unshift(columnName)
|
|
2169
|
-
);
|
|
2170
|
-
Object.keys(columnTransform).forEach(
|
|
2171
|
-
(columnName) => !tranformedHeaderRow.includes(columnName) && tranformedHeaderRow.unshift(columnName)
|
|
2172
|
-
);
|
|
2173
|
-
typeof context === "object" && Object.keys(context).forEach(
|
|
2174
|
-
(columnName) => !tranformedHeaderRow.includes(columnName) && tranformedHeaderRow.unshift(columnName)
|
|
2175
|
-
);
|
|
2176
|
-
let mappedHeaderRow = tranformedHeaderRow.map((key) => columnMap[key] || key);
|
|
2177
|
-
if (onlyHeaderRow)
|
|
2178
|
-
return [mappedHeaderRow];
|
|
2179
|
-
const withDelimiter = (value) => `${delimiter}${value}${delimiter}`;
|
|
2180
|
-
const columnValueCounts = [];
|
|
2181
|
-
const processRow = (row) => {
|
|
2182
|
-
return Object.values(
|
|
2183
|
-
tranformedHeaderRow.reduce((columnsMap, columnName, columnIndex) => {
|
|
2184
|
-
const accessors = columnTransform[columnName];
|
|
2185
|
-
const value = (accessors?.length ? row[accessors.find((accessor) => row[accessor])] : row[columnName]) || context?.[columnName] || "";
|
|
2186
|
-
const mappedValue = valuesMap[columnName]?.[value] || value;
|
|
2187
|
-
const fxValue = typeof functionMap[columnName] === "function" ? functionMap[columnName](mappedValue) : mappedValue;
|
|
2188
|
-
columnsMap[columnName] = withDelimiter(fxValue);
|
|
2189
|
-
if (fxValue) {
|
|
2190
|
-
columnValueCounts[columnIndex] = (columnValueCounts[columnIndex] || 0) + 1;
|
|
2191
|
-
}
|
|
2192
|
-
return columnsMap;
|
|
2193
|
-
}, {})
|
|
2194
|
-
);
|
|
2195
|
-
};
|
|
2196
|
-
let flattenedRows = flattened.map(processRow);
|
|
2197
|
-
const indicesToRemove = removeEmptyColumns && [...columnValueCounts].map((count, index) => !count && index).filter(isNumeric).reverse();
|
|
2198
|
-
if (indicesToRemove) {
|
|
2199
|
-
const purge = (row) => row.filter((_, index) => !indicesToRemove.includes(index));
|
|
2200
|
-
flattenedRows = flattenedRows.map(purge);
|
|
2201
|
-
mappedHeaderRow = purge(mappedHeaderRow);
|
|
2202
|
-
}
|
|
2203
|
-
const rows = flattenedRows.map((row) => row.join(columnJoiner));
|
|
2204
|
-
if (returnTransformedJSON) {
|
|
2205
|
-
return rows.map((row) => {
|
|
2206
|
-
const columnValues = row.split(columnJoiner);
|
|
2207
|
-
return Object.assign(
|
|
2208
|
-
{},
|
|
2209
|
-
...columnValues.map((v, i) => ({ [mappedHeaderRow[i]]: v }))
|
|
2210
|
-
);
|
|
2211
|
-
});
|
|
2212
|
-
}
|
|
2213
|
-
return includeHeaderRow ? [mappedHeaderRow.map(withDelimiter).join(columnJoiner), ...rows].join(
|
|
2214
|
-
rowJoiner
|
|
2215
|
-
) : rows.join(rowJoiner);
|
|
2216
|
-
}
|
|
2217
|
-
function flattenJSON(obj, keyJoiner = ".", path = []) {
|
|
2218
|
-
return typeof obj === "object" && Object.keys(obj).reduce((result, key) => {
|
|
2219
|
-
if (typeof obj[key] !== "object") {
|
|
2220
|
-
result[path.concat(key).join(keyJoiner)] = obj[key];
|
|
2221
|
-
return result;
|
|
2222
|
-
}
|
|
2223
|
-
return Object.assign(
|
|
2224
|
-
result,
|
|
2225
|
-
flattenJSON(obj[key], keyJoiner, path.concat(key))
|
|
2226
|
-
);
|
|
2227
|
-
}, {});
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
function UUIDS(count = 1) {
|
|
2231
|
-
return generateRange(0, count).map(UUID);
|
|
2232
|
-
}
|
|
2233
|
-
function UUID() {
|
|
2234
|
-
const lut = [];
|
|
2235
|
-
for (let i = 0; i < 256; i++) {
|
|
2236
|
-
lut[i] = (i < 16 ? "0" : "") + i.toString(16);
|
|
2237
|
-
}
|
|
2238
|
-
const d0 = Math.random() * 4294967295 | 0;
|
|
2239
|
-
const d1 = Math.random() * 4294967295 | 0;
|
|
2240
|
-
const d2 = Math.random() * 4294967295 | 0;
|
|
2241
|
-
const d3 = Math.random() * 4294967295 | 0;
|
|
2242
|
-
return lut[d0 & 255] + lut[d0 >> 8 & 255] + lut[d0 >> 16 & 255] + lut[d0 >> 24 & 255] + "-" + // eslint-disable-next-line no-mixed-operators
|
|
2243
|
-
lut[d1 & 255] + lut[d1 >> 8 & 255] + "-" + lut[d1 >> 16 & 15 | 64] + lut[d1 >> 24 & 255] + "-" + // eslint-disable-next-line no-mixed-operators
|
|
2244
|
-
lut[d2 & 63 | 128] + lut[d2 >> 8 & 255] + "-" + lut[d2 >> 16 & 255] + lut[d2 >> 24 & 255] + // eslint-disable-next-line no-mixed-operators
|
|
2245
|
-
lut[d3 & 255] + lut[d3 >> 8 & 255] + lut[d3 >> 16 & 255] + lut[d3 >> 24 & 255];
|
|
1546
|
+
function getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays) {
|
|
1547
|
+
return Object.keys(obj).filter(
|
|
1548
|
+
(key) => !ignoreValues.includes(obj[key]) && (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true))
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
|
|
1552
|
+
if (typeof obj !== "object" || obj === null)
|
|
1553
|
+
return obj;
|
|
1554
|
+
const deepCopy = deepCopyEnabled();
|
|
1555
|
+
if (!deepCopy?.enabled)
|
|
1556
|
+
shallow = true;
|
|
1557
|
+
const ignoreValues = ["", void 0, null];
|
|
1558
|
+
if (ignoreFalse)
|
|
1559
|
+
ignoreValues.push(false);
|
|
1560
|
+
const definedKeys = getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays);
|
|
1561
|
+
return Object.assign(
|
|
1562
|
+
{},
|
|
1563
|
+
...definedKeys.map((key) => {
|
|
1564
|
+
return Array.isArray(obj[key]) ? {
|
|
1565
|
+
[key]: shallow ? obj[key] : obj[key].map((m) => definedAttributes(m))
|
|
1566
|
+
} : { [key]: shallow ? obj[key] : definedAttributes(obj[key]) };
|
|
1567
|
+
})
|
|
1568
|
+
);
|
|
2246
1569
|
}
|
|
2247
1570
|
|
|
2248
1571
|
function parse(matchUpFormatCode) {
|
|
@@ -2414,7 +1737,7 @@ const matchUpFormatCode = {
|
|
|
2414
1737
|
};
|
|
2415
1738
|
|
|
2416
1739
|
function factoryVersion() {
|
|
2417
|
-
return "1.9.
|
|
1740
|
+
return "1.9.5";
|
|
2418
1741
|
}
|
|
2419
1742
|
|
|
2420
1743
|
function getObjectTieFormat(obj) {
|
|
@@ -2645,14 +1968,326 @@ function tieFormatGenderValidityCheck(params) {
|
|
|
2645
1968
|
stack
|
|
2646
1969
|
});
|
|
2647
1970
|
}
|
|
2648
|
-
if (referenceGender === ANY && gender === MIXED && matchUpType !== TypeEnum.Doubles)
|
|
2649
|
-
return decorateResult({
|
|
2650
|
-
result: { error: INVALID_GENDER, valid: false },
|
|
2651
|
-
info: anyMixedError,
|
|
2652
|
-
stack
|
|
2653
|
-
});
|
|
2654
|
-
return { valid: true };
|
|
1971
|
+
if (referenceGender === ANY && gender === MIXED && matchUpType !== TypeEnum.Doubles)
|
|
1972
|
+
return decorateResult({
|
|
1973
|
+
result: { error: INVALID_GENDER, valid: false },
|
|
1974
|
+
info: anyMixedError,
|
|
1975
|
+
stack
|
|
1976
|
+
});
|
|
1977
|
+
return { valid: true };
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
const validDateString = /^[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])$/;
|
|
1981
|
+
const validTimeString = /^((0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)([.,][0-9]{3})?$/;
|
|
1982
|
+
const dateValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))([ T](0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
|
|
1983
|
+
const timeValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))?([ T]?(0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
|
|
1984
|
+
|
|
1985
|
+
function getIsoDateString(schedule) {
|
|
1986
|
+
let { scheduledDate } = schedule;
|
|
1987
|
+
if (!scheduledDate && schedule.scheduledTime)
|
|
1988
|
+
scheduledDate = extractDate(schedule.scheduledTime);
|
|
1989
|
+
if (!scheduledDate)
|
|
1990
|
+
return;
|
|
1991
|
+
const extractedTime = extractTime(schedule.scheduledTime);
|
|
1992
|
+
let isoDateString = extractDate(scheduledDate);
|
|
1993
|
+
if (isoDateString && extractedTime)
|
|
1994
|
+
isoDateString += `T${extractedTime}`;
|
|
1995
|
+
return isoDateString;
|
|
1996
|
+
}
|
|
1997
|
+
function isDateObject(value) {
|
|
1998
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
1999
|
+
return false;
|
|
2000
|
+
} else {
|
|
2001
|
+
const datePrototype = Object.prototype.toString.call(value);
|
|
2002
|
+
return datePrototype === "[object Date]";
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
function validTimeValue(value) {
|
|
2006
|
+
const spaceSplit = typeof value === "string" ? value?.split(" ") : [];
|
|
2007
|
+
if (value && spaceSplit?.length > 1 && !["AM", "PM"].includes(spaceSplit[1].toUpperCase()))
|
|
2008
|
+
return false;
|
|
2009
|
+
return !!(!value || timeValidation.test(convertTime(value, true, true)));
|
|
2010
|
+
}
|
|
2011
|
+
function isValidDateString(scheduleDate) {
|
|
2012
|
+
return isISODateString(scheduleDate) || validDateString.test(scheduleDate);
|
|
2013
|
+
}
|
|
2014
|
+
function DateHHMM(date) {
|
|
2015
|
+
const dt = new Date(date);
|
|
2016
|
+
const secs = dt.getSeconds() + 60 * dt.getMinutes() + 60 * 60 * dt.getHours();
|
|
2017
|
+
return HHMMSS(secs, { displaySeconds: false });
|
|
2018
|
+
}
|
|
2019
|
+
function HHMMSS(s, format) {
|
|
2020
|
+
const secondNumber = parseInt(s, 10);
|
|
2021
|
+
const hours = Math.floor(secondNumber / 3600);
|
|
2022
|
+
const minutes = Math.floor((secondNumber - hours * 3600) / 60);
|
|
2023
|
+
const seconds = secondNumber - hours * 3600 - minutes * 60;
|
|
2024
|
+
const displaySeconds = !format || format?.displaySeconds;
|
|
2025
|
+
const timeString = displaySeconds ? hours + ":" + minutes + ":" + seconds : hours + ":" + minutes;
|
|
2026
|
+
return timeString.split(":").map(zeroPad).join(":");
|
|
2027
|
+
}
|
|
2028
|
+
const getUTCdateString = (date) => {
|
|
2029
|
+
const dateDate = isDate(date) || isISODateString(date) ? new Date(date) : /* @__PURE__ */ new Date();
|
|
2030
|
+
const monthNumber = dateDate.getUTCMonth() + 1;
|
|
2031
|
+
const utcMonth = monthNumber < 10 ? `0${monthNumber}` : `${monthNumber}`;
|
|
2032
|
+
return `${dateDate.getUTCFullYear()}-${zeroPad(utcMonth)}-${zeroPad(
|
|
2033
|
+
dateDate.getUTCDate()
|
|
2034
|
+
)}`;
|
|
2035
|
+
};
|
|
2036
|
+
function timeUTC(date) {
|
|
2037
|
+
const dateDate = isDate(date) || isISODateString(date) ? new Date(date) : /* @__PURE__ */ new Date();
|
|
2038
|
+
return Date.UTC(
|
|
2039
|
+
dateDate.getFullYear(),
|
|
2040
|
+
dateDate.getMonth(),
|
|
2041
|
+
dateDate.getDate()
|
|
2042
|
+
);
|
|
2043
|
+
}
|
|
2044
|
+
function formatDate(date, separator = "-", format = "YMD") {
|
|
2045
|
+
if (!date)
|
|
2046
|
+
return "";
|
|
2047
|
+
if (typeof date === "string" && date.indexOf("T") < 0)
|
|
2048
|
+
date = date + "T00:00";
|
|
2049
|
+
const d = new Date(date);
|
|
2050
|
+
let month = "" + (d.getMonth() + 1);
|
|
2051
|
+
let day = "" + d.getDate();
|
|
2052
|
+
const year = d.getFullYear();
|
|
2053
|
+
if (month.length < 2)
|
|
2054
|
+
month = "0" + month;
|
|
2055
|
+
if (day.length < 2)
|
|
2056
|
+
day = "0" + day;
|
|
2057
|
+
if (format === "DMY")
|
|
2058
|
+
return [day, month, year].join(separator);
|
|
2059
|
+
if (format === "MDY")
|
|
2060
|
+
return [month, day, year].join(separator);
|
|
2061
|
+
if (format === "YDM")
|
|
2062
|
+
return [year, day, month].join(separator);
|
|
2063
|
+
if (format === "DYM")
|
|
2064
|
+
return [day, year, month].join(separator);
|
|
2065
|
+
if (format === "MYD")
|
|
2066
|
+
return [month, year, day].join(separator);
|
|
2067
|
+
return [year, month, day].join(separator);
|
|
2068
|
+
}
|
|
2069
|
+
function offsetDate(date) {
|
|
2070
|
+
const targetTime = date ? new Date(date) : /* @__PURE__ */ new Date();
|
|
2071
|
+
const tzDifference = targetTime.getTimezoneOffset();
|
|
2072
|
+
return new Date(targetTime.getTime() - tzDifference * 60 * 1e3);
|
|
2073
|
+
}
|
|
2074
|
+
function offsetTime(date) {
|
|
2075
|
+
return offsetDate(date).getTime();
|
|
2076
|
+
}
|
|
2077
|
+
function isDate(dateArg) {
|
|
2078
|
+
if (typeof dateArg == "boolean")
|
|
2079
|
+
return false;
|
|
2080
|
+
const t = dateArg instanceof Date && dateArg || !isNaN(dateArg) && new Date(dateArg) || false;
|
|
2081
|
+
return t && !isNaN(t.valueOf());
|
|
2082
|
+
}
|
|
2083
|
+
function dateRange(startDt, endDt) {
|
|
2084
|
+
if (!isValidDateString(startDt) || !isValidDateString(endDt))
|
|
2085
|
+
return [];
|
|
2086
|
+
const startDateString = extractDate(startDt) + "T00:00";
|
|
2087
|
+
const endDateString = extractDate(endDt) + "T00:00";
|
|
2088
|
+
const startDate = new Date(startDateString);
|
|
2089
|
+
const endDate = new Date(endDateString);
|
|
2090
|
+
const process = isDate(endDate) && isDate(startDate) && isValidDateRange(startDate, endDate);
|
|
2091
|
+
const between = [];
|
|
2092
|
+
let iterations = 0;
|
|
2093
|
+
if (process) {
|
|
2094
|
+
const currentDate = startDate;
|
|
2095
|
+
let dateSecs = currentDate.getTime();
|
|
2096
|
+
while (dateSecs <= endDate.getTime() && iterations < 300) {
|
|
2097
|
+
iterations += 1;
|
|
2098
|
+
between.push(new Date(currentDate));
|
|
2099
|
+
dateSecs = currentDate.setDate(currentDate.getDate() + 1);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
return between.map((date) => formatDate(date));
|
|
2103
|
+
function isValidDateRange(minDate, maxDate) {
|
|
2104
|
+
return minDate <= maxDate;
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
const re = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
2108
|
+
function isISODateString(dateString) {
|
|
2109
|
+
if (typeof dateString !== "string")
|
|
2110
|
+
return false;
|
|
2111
|
+
return re.test(dateString);
|
|
2112
|
+
}
|
|
2113
|
+
function isTimeString(timeString) {
|
|
2114
|
+
if (typeof timeString !== "string")
|
|
2115
|
+
return false;
|
|
2116
|
+
const noZ = timeString.split("Z")[0];
|
|
2117
|
+
const parts = noZ.split(":");
|
|
2118
|
+
const isNumeric = parts.every((part) => !isNaN(parseInt(part)));
|
|
2119
|
+
const invalid = parts.length < 2 || !isNumeric || parseInt(parts[0]) > 23 || parseInt(parts[1]) > 60;
|
|
2120
|
+
return !invalid;
|
|
2121
|
+
}
|
|
2122
|
+
function timeStringMinutes(timeString) {
|
|
2123
|
+
const validTimeString = extractTime(timeString);
|
|
2124
|
+
if (!validTimeString)
|
|
2125
|
+
return 0;
|
|
2126
|
+
const [hours, minutes] = validTimeString.split(":").map((value) => parseInt(value));
|
|
2127
|
+
return hours * 60 + minutes;
|
|
2128
|
+
}
|
|
2129
|
+
function dayMinutesToTimeString(totalMinutes) {
|
|
2130
|
+
let hours = Math.floor(totalMinutes / 60);
|
|
2131
|
+
const minutes = totalMinutes - hours * 60;
|
|
2132
|
+
if (hours > 23)
|
|
2133
|
+
hours = hours % 24;
|
|
2134
|
+
return [zeroPad(hours), zeroPad(minutes)].join(":");
|
|
2135
|
+
}
|
|
2136
|
+
function tidyTime(timeString) {
|
|
2137
|
+
return isTimeString(timeString) ? timeString.split(":").slice(0, 2).map(zeroPad).join(":") : void 0;
|
|
2138
|
+
}
|
|
2139
|
+
function extractTime(dateString) {
|
|
2140
|
+
return isISODateString(dateString) && dateString.indexOf("T") > 0 ? tidyTime(dateString.split("T").reverse()[0]) : tidyTime(dateString);
|
|
2141
|
+
}
|
|
2142
|
+
function extractDate(dateString) {
|
|
2143
|
+
return isISODateString(dateString) || dateValidation.test(dateString) ? dateString.split("T")[0] : void 0;
|
|
2144
|
+
}
|
|
2145
|
+
function dateStringDaysChange(dateString, daysChange) {
|
|
2146
|
+
const date = new Date(dateString);
|
|
2147
|
+
date.setDate(date.getDate() + daysChange);
|
|
2148
|
+
return extractDate(date.toISOString());
|
|
2149
|
+
}
|
|
2150
|
+
function splitTime(value) {
|
|
2151
|
+
value = typeof value !== "string" ? "00:00" : value;
|
|
2152
|
+
const o = {}, time = {};
|
|
2153
|
+
({ 0: o.time, 1: o.ampm } = value.split(" ") || []);
|
|
2154
|
+
({ 0: time.hours, 1: time.minutes } = o.time.split(":") || []);
|
|
2155
|
+
time.ampm = o.ampm;
|
|
2156
|
+
if (isNaN(time.hours) || isNaN(time.minutes) || time.ampm && !["AM", "PM"].includes(time.ampm.toUpperCase()))
|
|
2157
|
+
return {};
|
|
2158
|
+
return time;
|
|
2159
|
+
}
|
|
2160
|
+
function militaryTime(value) {
|
|
2161
|
+
const time = splitTime(value);
|
|
2162
|
+
if (time.ampm && time.hours) {
|
|
2163
|
+
if (time.ampm.toLowerCase() === "pm" && parseInt(time.hours) < 12)
|
|
2164
|
+
time.hours = (time.hours && parseInt(time.hours) || 0) + 12;
|
|
2165
|
+
if (time.ampm.toLowerCase() === "am" && time.hours === "12")
|
|
2166
|
+
time.hours = "00";
|
|
2167
|
+
}
|
|
2168
|
+
const timeString = `${time.hours || "12"}:${time.minutes || "00"}`;
|
|
2169
|
+
return timeString.split(":").map(zeroPad).join(":");
|
|
2170
|
+
}
|
|
2171
|
+
function regularTime(value) {
|
|
2172
|
+
const time = splitTime(value);
|
|
2173
|
+
if (typeof time === "object" && !Object.keys(time).length)
|
|
2174
|
+
return void 0;
|
|
2175
|
+
if (time.ampm)
|
|
2176
|
+
return value;
|
|
2177
|
+
if (time.hours > 12) {
|
|
2178
|
+
time.hours -= 12;
|
|
2179
|
+
time.ampm = "PM";
|
|
2180
|
+
} else if (time.hours === "12") {
|
|
2181
|
+
time.ampm = "PM";
|
|
2182
|
+
} else if (time.hours === "00") {
|
|
2183
|
+
time.hours = "12";
|
|
2184
|
+
time.ampm = "AM";
|
|
2185
|
+
} else {
|
|
2186
|
+
time.ampm = "AM";
|
|
2187
|
+
}
|
|
2188
|
+
if (time.hours?.[0] === "0") {
|
|
2189
|
+
time.hours = time.hours.slice(1);
|
|
2190
|
+
}
|
|
2191
|
+
return `${time.hours || "12"}:${time.minutes || "00"} ${time.ampm}`;
|
|
2192
|
+
}
|
|
2193
|
+
function convertTime(value, time24, keepDate) {
|
|
2194
|
+
const hasDate = extractDate(value);
|
|
2195
|
+
const timeString = extractTime(value);
|
|
2196
|
+
const timeValue = hasDate ? timeString : value;
|
|
2197
|
+
return !value ? void 0 : time24 && (hasDate && keepDate && value || militaryTime(timeValue)) || regularTime(timeValue);
|
|
2198
|
+
}
|
|
2199
|
+
function timeSort(a, b) {
|
|
2200
|
+
const as = splitTime(a);
|
|
2201
|
+
const bs = splitTime(b);
|
|
2202
|
+
if (parseInt(as.hours) < parseInt(bs.hours))
|
|
2203
|
+
return -1;
|
|
2204
|
+
if (parseInt(as.hours) > parseInt(bs.hours))
|
|
2205
|
+
return 1;
|
|
2206
|
+
if (as.hours === bs.hours) {
|
|
2207
|
+
if (parseInt(as.minutes) < parseInt(bs.minutes))
|
|
2208
|
+
return -1;
|
|
2209
|
+
if (parseInt(as.minutes) > parseInt(bs.minutes))
|
|
2210
|
+
return 1;
|
|
2211
|
+
}
|
|
2212
|
+
return 0;
|
|
2213
|
+
}
|
|
2214
|
+
function addDays(date, days = 7) {
|
|
2215
|
+
const universalDate = extractDate(date) + "T00:00";
|
|
2216
|
+
const now = new Date(universalDate);
|
|
2217
|
+
const adjustedDate = new Date(now.setDate(now.getDate() + days));
|
|
2218
|
+
return formatDate(adjustedDate);
|
|
2219
|
+
}
|
|
2220
|
+
function addWeek(date) {
|
|
2221
|
+
return addDays(date);
|
|
2222
|
+
}
|
|
2223
|
+
function getDateByWeek(week, year, dateFormat, sunday = false) {
|
|
2224
|
+
const date = new Date(year, 0, 1 + (week - 1) * 7);
|
|
2225
|
+
const startValue = sunday ? 0 : 1;
|
|
2226
|
+
date.setDate(date.getDate() + (startValue - date.getDay()));
|
|
2227
|
+
return formatDate(date, dateFormat);
|
|
2228
|
+
}
|
|
2229
|
+
function dateFromDay(year, day, dateFormat) {
|
|
2230
|
+
const date = new Date(year, 0);
|
|
2231
|
+
return formatDate(new Date(date.setDate(day)), dateFormat);
|
|
2232
|
+
}
|
|
2233
|
+
function timeToDate(timeString, date = void 0) {
|
|
2234
|
+
const [hours, minutes] = (timeString || "00:00").split(":").map(zeroPad);
|
|
2235
|
+
const milliseconds = offsetDate(date).setHours(hours, minutes, 0, 0);
|
|
2236
|
+
return offsetDate(milliseconds);
|
|
2237
|
+
}
|
|
2238
|
+
function minutesDifference(date1, date2, absolute = true) {
|
|
2239
|
+
const dt1 = new Date(date1);
|
|
2240
|
+
const dt2 = new Date(date2);
|
|
2241
|
+
const diff = (dt2.getTime() - dt1.getTime()) / 1e3 / 60;
|
|
2242
|
+
return absolute ? Math.abs(Math.round(diff)) : Math.round(diff);
|
|
2243
|
+
}
|
|
2244
|
+
function addMinutesToTimeString(timeString, minutes) {
|
|
2245
|
+
const validTimeString = extractTime(timeString);
|
|
2246
|
+
if (!validTimeString)
|
|
2247
|
+
return "00:00";
|
|
2248
|
+
const minutesToAdd = isNaN(minutes) ? 0 : minutes;
|
|
2249
|
+
return extractTime(
|
|
2250
|
+
addMinutes(timeToDate(validTimeString), minutesToAdd).toISOString()
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
function addMinutes(startDate, minutes) {
|
|
2254
|
+
const date = new Date(startDate);
|
|
2255
|
+
return new Date(date.getTime() + minutes * 6e4);
|
|
2256
|
+
}
|
|
2257
|
+
function zeroPad(number) {
|
|
2258
|
+
return number.toString()[1] ? number : "0" + number;
|
|
2259
|
+
}
|
|
2260
|
+
function sameDay(date1, date2) {
|
|
2261
|
+
const d1 = new Date(date1);
|
|
2262
|
+
const d2 = new Date(date2);
|
|
2263
|
+
return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();
|
|
2655
2264
|
}
|
|
2265
|
+
const dateTime = {
|
|
2266
|
+
addDays,
|
|
2267
|
+
addWeek,
|
|
2268
|
+
addMinutesToTimeString,
|
|
2269
|
+
convertTime,
|
|
2270
|
+
getIsoDateString,
|
|
2271
|
+
getUTCdateString,
|
|
2272
|
+
DateHHMM,
|
|
2273
|
+
extractDate,
|
|
2274
|
+
extractTime,
|
|
2275
|
+
formatDate,
|
|
2276
|
+
getDateByWeek,
|
|
2277
|
+
isISODateString,
|
|
2278
|
+
isDate,
|
|
2279
|
+
isTimeString,
|
|
2280
|
+
offsetDate,
|
|
2281
|
+
offsetTime,
|
|
2282
|
+
sameDay,
|
|
2283
|
+
timeStringMinutes,
|
|
2284
|
+
timeToDate,
|
|
2285
|
+
timeUTC,
|
|
2286
|
+
validTimeValue,
|
|
2287
|
+
validDateString,
|
|
2288
|
+
timeValidation,
|
|
2289
|
+
dateValidation
|
|
2290
|
+
};
|
|
2656
2291
|
|
|
2657
2292
|
const typeMatch = (arr, type) => arr.filter(Boolean).every((i) => typeof i === type);
|
|
2658
2293
|
const allNumeric = (arr) => arr.filter(Boolean).every(isNumeric);
|
|
@@ -2798,31 +2433,200 @@ function getCategoryAgeDetails(params) {
|
|
|
2798
2433
|
} else {
|
|
2799
2434
|
addError(`Invalid combined age range ${ageCategoryCode}`);
|
|
2800
2435
|
}
|
|
2801
|
-
} else if (isBetween) {
|
|
2802
|
-
ageCategoryCode?.split("-").forEach(processCode);
|
|
2803
|
-
} else if (isCoded) {
|
|
2804
|
-
processCode(ageCategoryCode);
|
|
2805
|
-
} else {
|
|
2806
|
-
if (ageMin)
|
|
2807
|
-
oPre(ageMin);
|
|
2808
|
-
if (ageMax)
|
|
2809
|
-
uPost(ageMax);
|
|
2436
|
+
} else if (isBetween) {
|
|
2437
|
+
ageCategoryCode?.split("-").forEach(processCode);
|
|
2438
|
+
} else if (isCoded) {
|
|
2439
|
+
processCode(ageCategoryCode);
|
|
2440
|
+
} else {
|
|
2441
|
+
if (ageMin)
|
|
2442
|
+
oPre(ageMin);
|
|
2443
|
+
if (ageMax)
|
|
2444
|
+
uPost(ageMax);
|
|
2445
|
+
}
|
|
2446
|
+
if (ageMax && category.ageMin && category.ageMin > ageMax) {
|
|
2447
|
+
addError(`Invalid submitted ageMin: ${category.ageMin}`);
|
|
2448
|
+
ageMin = void 0;
|
|
2449
|
+
}
|
|
2450
|
+
const result = definedAttributes({
|
|
2451
|
+
consideredDate,
|
|
2452
|
+
combinedAge,
|
|
2453
|
+
ageMaxDate,
|
|
2454
|
+
ageMinDate,
|
|
2455
|
+
ageMax,
|
|
2456
|
+
ageMin
|
|
2457
|
+
});
|
|
2458
|
+
if (errors.length)
|
|
2459
|
+
result.errors = errors;
|
|
2460
|
+
return result;
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
|
|
2464
|
+
if (getProvider().makeDeepCopy)
|
|
2465
|
+
return getProvider().makeDeepCopy(
|
|
2466
|
+
sourceObject,
|
|
2467
|
+
convertExtensions,
|
|
2468
|
+
internalUse,
|
|
2469
|
+
removeExtensions
|
|
2470
|
+
);
|
|
2471
|
+
const deepCopy = deepCopyEnabled();
|
|
2472
|
+
const { stringify, toJSON, ignore, modulate } = deepCopy || {};
|
|
2473
|
+
if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
|
|
2474
|
+
return sourceObject;
|
|
2475
|
+
}
|
|
2476
|
+
const targetObject = Array.isArray(sourceObject) ? [] : {};
|
|
2477
|
+
const sourceObjectKeys = Object.keys(sourceObject).filter(
|
|
2478
|
+
(key) => !internalUse || !ignore || Array.isArray(ignore) && !ignore.includes(key) || typeof ignore === "function" && !ignore(key)
|
|
2479
|
+
);
|
|
2480
|
+
const stringifyValue = (key, value) => {
|
|
2481
|
+
targetObject[key] = typeof value?.toString === "function" ? value.toString() : JSON.stringify(value);
|
|
2482
|
+
};
|
|
2483
|
+
for (const key of sourceObjectKeys) {
|
|
2484
|
+
const value = sourceObject[key];
|
|
2485
|
+
const modulated = typeof modulate === "function" ? modulate(value) : void 0;
|
|
2486
|
+
if (modulated !== void 0) {
|
|
2487
|
+
targetObject[key] = modulated;
|
|
2488
|
+
} else if (convertExtensions && key === "extensions" && Array.isArray(value)) {
|
|
2489
|
+
const extensionConversions = extensionsToAttributes(value);
|
|
2490
|
+
Object.assign(targetObject, ...extensionConversions);
|
|
2491
|
+
} else if (removeExtensions && key === "extensions") {
|
|
2492
|
+
targetObject[key] = [];
|
|
2493
|
+
} else if (Array.isArray(stringify) && stringify.includes(key)) {
|
|
2494
|
+
stringifyValue(key, value);
|
|
2495
|
+
} else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === "function") {
|
|
2496
|
+
targetObject[key] = value.toJSON();
|
|
2497
|
+
} else if (value === null) {
|
|
2498
|
+
targetObject[key] = void 0;
|
|
2499
|
+
} else if (isDateObject(value)) {
|
|
2500
|
+
targetObject[key] = new Date(value).toISOString();
|
|
2501
|
+
} else {
|
|
2502
|
+
targetObject[key] = makeDeepCopy(
|
|
2503
|
+
value,
|
|
2504
|
+
convertExtensions,
|
|
2505
|
+
internalUse,
|
|
2506
|
+
removeExtensions,
|
|
2507
|
+
iteration + 1
|
|
2508
|
+
);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
return targetObject;
|
|
2512
|
+
}
|
|
2513
|
+
function extensionsToAttributes(extensions) {
|
|
2514
|
+
return extensions?.map((extension) => {
|
|
2515
|
+
const { name, value } = extension;
|
|
2516
|
+
return name && value && { [`_${name}`]: value };
|
|
2517
|
+
}).filter(Boolean);
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
function getAccessorValue({ element, accessor }) {
|
|
2521
|
+
if (typeof accessor !== "string")
|
|
2522
|
+
return { values: [] };
|
|
2523
|
+
const targetElement = makeDeepCopy(element);
|
|
2524
|
+
const attributes = accessor.split(".");
|
|
2525
|
+
const values = [];
|
|
2526
|
+
let value;
|
|
2527
|
+
processKeys({ targetElement, attributes });
|
|
2528
|
+
const result = { value };
|
|
2529
|
+
if (values.length)
|
|
2530
|
+
result.values = values;
|
|
2531
|
+
return result;
|
|
2532
|
+
function processKeys({
|
|
2533
|
+
targetElement: targetElement2,
|
|
2534
|
+
attributes: attributes2 = [],
|
|
2535
|
+
significantCharacters
|
|
2536
|
+
}) {
|
|
2537
|
+
for (const [index, attribute] of attributes2.entries()) {
|
|
2538
|
+
if (targetElement2?.[attribute]) {
|
|
2539
|
+
const remainingKeys = attributes2.slice(index + 1);
|
|
2540
|
+
if (!remainingKeys.length) {
|
|
2541
|
+
if (!value)
|
|
2542
|
+
value = targetElement2[attribute];
|
|
2543
|
+
if (!values.includes(targetElement2[attribute])) {
|
|
2544
|
+
values.push(targetElement2[attribute]);
|
|
2545
|
+
}
|
|
2546
|
+
} else if (Array.isArray(targetElement2[attribute])) {
|
|
2547
|
+
const values2 = targetElement2[attribute];
|
|
2548
|
+
values2.forEach(
|
|
2549
|
+
(nestedTarget) => processKeys({
|
|
2550
|
+
targetElement: nestedTarget,
|
|
2551
|
+
attributes: remainingKeys
|
|
2552
|
+
})
|
|
2553
|
+
);
|
|
2554
|
+
} else {
|
|
2555
|
+
targetElement2 = targetElement2[attribute];
|
|
2556
|
+
checkValue({ targetElement: targetElement2, index });
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
function checkValue({ targetElement: targetElement3, index }) {
|
|
2561
|
+
if (targetElement3 && index === attributes2.length - 1 && ["string", "number"].includes(typeof targetElement3)) {
|
|
2562
|
+
const extractedValue = significantCharacters ? targetElement3.slice(0, significantCharacters) : targetElement3;
|
|
2563
|
+
if (value) {
|
|
2564
|
+
if (!values.includes(extractedValue)) {
|
|
2565
|
+
values.push(extractedValue);
|
|
2566
|
+
}
|
|
2567
|
+
} else {
|
|
2568
|
+
value = extractedValue;
|
|
2569
|
+
values.push(extractedValue);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
function isString(obj) {
|
|
2577
|
+
return typeof obj === "string";
|
|
2578
|
+
}
|
|
2579
|
+
function isObject(obj) {
|
|
2580
|
+
return obj !== null && typeof obj === "object";
|
|
2581
|
+
}
|
|
2582
|
+
function objShallowEqual(o1, o2) {
|
|
2583
|
+
if (!isObject(o1) || !isObject(o2))
|
|
2584
|
+
return false;
|
|
2585
|
+
const keys1 = Object.keys(o1);
|
|
2586
|
+
const keys2 = Object.keys(o2);
|
|
2587
|
+
if (keys1.length !== keys2.length) {
|
|
2588
|
+
return false;
|
|
2589
|
+
}
|
|
2590
|
+
for (const key of keys1) {
|
|
2591
|
+
if (o1[key] !== o2[key]) {
|
|
2592
|
+
return false;
|
|
2593
|
+
}
|
|
2810
2594
|
}
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2595
|
+
return true;
|
|
2596
|
+
}
|
|
2597
|
+
function createMap(objectArray, attribute) {
|
|
2598
|
+
if (!Array.isArray(objectArray))
|
|
2599
|
+
return {};
|
|
2600
|
+
return Object.assign(
|
|
2601
|
+
{},
|
|
2602
|
+
...(objectArray ?? []).filter(isObject).map((obj) => {
|
|
2603
|
+
return obj[attribute] && {
|
|
2604
|
+
[obj[attribute]]: obj
|
|
2605
|
+
};
|
|
2606
|
+
}).filter(Boolean)
|
|
2607
|
+
);
|
|
2608
|
+
}
|
|
2609
|
+
const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
|
|
2610
|
+
const extractAttributes = (accessor) => (element) => !accessor || typeof element !== "object" ? void 0 : Array.isArray(accessor) && accessor.map((a) => ({
|
|
2611
|
+
[a]: getAccessorValue({ element, accessor: a })?.value
|
|
2612
|
+
})) || typeof accessor === "object" && Object.keys(accessor).map((key) => ({
|
|
2613
|
+
[key]: getAccessorValue({ element, accessor: key })?.value
|
|
2614
|
+
})) || (typeof accessor === "string" && getAccessorValue({ element, accessor }))?.value;
|
|
2615
|
+
function countKeys(o) {
|
|
2616
|
+
if (Array.isArray(o)) {
|
|
2617
|
+
return o.length + o.map(countKeys).reduce((a, b) => a + b, 0);
|
|
2618
|
+
} else if (typeof o === "object" && o !== null) {
|
|
2619
|
+
return Object.keys(o).length + Object.keys(o).map((k) => countKeys(o[k])).reduce((a, b) => a + b, 0);
|
|
2814
2620
|
}
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
result.errors = errors;
|
|
2825
|
-
return result;
|
|
2621
|
+
return 0;
|
|
2622
|
+
}
|
|
2623
|
+
function generateHashCode(o) {
|
|
2624
|
+
if (o === null || typeof o !== "object")
|
|
2625
|
+
return void 0;
|
|
2626
|
+
const str = JSON.stringify(o);
|
|
2627
|
+
const keyCount = countKeys(o);
|
|
2628
|
+
const charSum = str.split("").reduce((a, b) => a + b.charCodeAt(0), 0);
|
|
2629
|
+
return [str.length, keyCount, charSum].map((e) => e.toString(36)).join("");
|
|
2826
2630
|
}
|
|
2827
2631
|
|
|
2828
2632
|
function validateCategory({ category }) {
|
|
@@ -2885,6 +2689,203 @@ function mustBeAnArray(value) {
|
|
|
2885
2689
|
return `${value} must be an array`;
|
|
2886
2690
|
}
|
|
2887
2691
|
|
|
2692
|
+
function attributeFilter(params) {
|
|
2693
|
+
if (params === null)
|
|
2694
|
+
return {};
|
|
2695
|
+
const { source, template } = params || {};
|
|
2696
|
+
if (!template)
|
|
2697
|
+
return source;
|
|
2698
|
+
const target = {};
|
|
2699
|
+
attributeCopy(source, template, target);
|
|
2700
|
+
return target;
|
|
2701
|
+
function attributeCopy(valuesObject, templateObject, outputObject) {
|
|
2702
|
+
if (!valuesObject || !templateObject)
|
|
2703
|
+
return void 0;
|
|
2704
|
+
const vKeys = Object.keys(valuesObject);
|
|
2705
|
+
const oKeys = Object.keys(templateObject);
|
|
2706
|
+
const orMap = Object.assign(
|
|
2707
|
+
{},
|
|
2708
|
+
...oKeys.filter((key) => key.indexOf("||")).map((key) => key.split("||").map((or) => ({ [or]: key }))).flat()
|
|
2709
|
+
);
|
|
2710
|
+
const allKeys = oKeys.concat(...Object.keys(orMap));
|
|
2711
|
+
const wildcard = allKeys.includes("*");
|
|
2712
|
+
for (const vKey of vKeys) {
|
|
2713
|
+
if (allKeys.indexOf(vKey) >= 0 || wildcard) {
|
|
2714
|
+
const templateKey = orMap[vKey] || vKey;
|
|
2715
|
+
const tobj = templateObject[templateKey] || wildcard;
|
|
2716
|
+
const vobj = valuesObject[vKey];
|
|
2717
|
+
if (typeof tobj === "object" && typeof vobj !== "function" && !Array.isArray(tobj)) {
|
|
2718
|
+
if (Array.isArray(vobj)) {
|
|
2719
|
+
const mappedElements = vobj.map((arrayMember) => {
|
|
2720
|
+
const target2 = {};
|
|
2721
|
+
const result = attributeCopy(arrayMember, tobj, target2);
|
|
2722
|
+
return result !== false ? target2 : void 0;
|
|
2723
|
+
}).filter(Boolean);
|
|
2724
|
+
outputObject[vKey] = mappedElements;
|
|
2725
|
+
} else if (vobj) {
|
|
2726
|
+
outputObject[vKey] = {};
|
|
2727
|
+
attributeCopy(vobj, tobj, outputObject[vKey]);
|
|
2728
|
+
}
|
|
2729
|
+
} else {
|
|
2730
|
+
const value = valuesObject[vKey];
|
|
2731
|
+
const exclude = Array.isArray(tobj) && !tobj.includes(value);
|
|
2732
|
+
if (exclude)
|
|
2733
|
+
return false;
|
|
2734
|
+
if (templateObject[vKey] || wildcard && templateObject[vKey] !== false) {
|
|
2735
|
+
outputObject[vKey] = value;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
return void 0;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
function generateTimeCode(index = 0) {
|
|
2745
|
+
const uidate = /* @__PURE__ */ new Date();
|
|
2746
|
+
uidate.setHours(uidate.getHours() + index);
|
|
2747
|
+
return uidate.getTime().toString(36).slice(-6).toUpperCase();
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
function JSON2CSV(arrayOfJSON, config) {
|
|
2751
|
+
if (config && typeof config !== "object")
|
|
2752
|
+
return INVALID_VALUES;
|
|
2753
|
+
let { columnTransform = {} } = config || {};
|
|
2754
|
+
const {
|
|
2755
|
+
includeTransformAccessors,
|
|
2756
|
+
includeHeaderRow = true,
|
|
2757
|
+
returnTransformedJSON,
|
|
2758
|
+
removeEmptyColumns,
|
|
2759
|
+
onlyHeaderRow,
|
|
2760
|
+
columnAccessors = [],
|
|
2761
|
+
functionMap = {},
|
|
2762
|
+
columnMap = {},
|
|
2763
|
+
valuesMap = {},
|
|
2764
|
+
context = {},
|
|
2765
|
+
delimiter = '"',
|
|
2766
|
+
columnJoiner = ",",
|
|
2767
|
+
rowJoiner = "\r\n",
|
|
2768
|
+
keyJoiner = "."
|
|
2769
|
+
} = config || {};
|
|
2770
|
+
if (!Array.isArray(arrayOfJSON) || !Array.isArray(columnAccessors) || typeof context !== "object" || typeof columnMap !== "object" || typeof columnTransform !== "object" || typeof functionMap !== "object" || typeof valuesMap !== "object" || typeof columnJoiner !== "string" || typeof rowJoiner !== "string" || typeof keyJoiner !== "string" || typeof delimiter !== "string")
|
|
2771
|
+
return INVALID_VALUES;
|
|
2772
|
+
columnTransform = Object.assign(
|
|
2773
|
+
{},
|
|
2774
|
+
...Object.keys(columnTransform).reverse().map((key) => ({
|
|
2775
|
+
[key]: Array.isArray(columnTransform[key]) ? columnTransform[key] : [
|
|
2776
|
+
// ensure transform attributes are strings
|
|
2777
|
+
typeof columnTransform[key] === "string" && columnTransform[key]
|
|
2778
|
+
].filter(Boolean)
|
|
2779
|
+
}))
|
|
2780
|
+
);
|
|
2781
|
+
const flattened = arrayOfJSON.filter(Boolean).map((obj) => flattenJSON(obj, keyJoiner));
|
|
2782
|
+
const transformColumns = Object.values(columnTransform).flat();
|
|
2783
|
+
if (includeTransformAccessors)
|
|
2784
|
+
columnAccessors.push(...transformColumns);
|
|
2785
|
+
const headerRow = flattened.reduce(
|
|
2786
|
+
(aggregator, row) => Object.keys(row).every(
|
|
2787
|
+
(key) => !aggregator.includes(key) && aggregator.push(key) || true
|
|
2788
|
+
) && aggregator,
|
|
2789
|
+
[]
|
|
2790
|
+
).filter((key) => !columnAccessors?.length || columnAccessors.includes(key));
|
|
2791
|
+
const accessorMap = Object.assign(
|
|
2792
|
+
{},
|
|
2793
|
+
...Object.keys(columnTransform).reverse().map(
|
|
2794
|
+
(transform) => columnTransform[transform].map((value) => ({ [value]: transform })).flat()
|
|
2795
|
+
).flat()
|
|
2796
|
+
);
|
|
2797
|
+
const sortColumns = (a, b) => !config?.sortOrder ? 0 : config.sortOrder.includes(a) && config.sortOrder.includes(b) && config.sortOrder.indexOf(a) - config.sortOrder.indexOf(b) || !config.sortOrder.includes(b) && -1;
|
|
2798
|
+
const tranformedHeaderRow = headerRow.reduce((def, key) => {
|
|
2799
|
+
const transform = accessorMap[key];
|
|
2800
|
+
if (transform) {
|
|
2801
|
+
if (!def.includes(transform))
|
|
2802
|
+
def.push(transform);
|
|
2803
|
+
} else {
|
|
2804
|
+
def.push(key);
|
|
2805
|
+
}
|
|
2806
|
+
return def;
|
|
2807
|
+
}, []).sort(sortColumns);
|
|
2808
|
+
Object.keys(columnMap).forEach(
|
|
2809
|
+
(columnName) => !tranformedHeaderRow.includes(columnName) && tranformedHeaderRow.unshift(columnName)
|
|
2810
|
+
);
|
|
2811
|
+
Object.keys(columnTransform).forEach(
|
|
2812
|
+
(columnName) => !tranformedHeaderRow.includes(columnName) && tranformedHeaderRow.unshift(columnName)
|
|
2813
|
+
);
|
|
2814
|
+
typeof context === "object" && Object.keys(context).forEach(
|
|
2815
|
+
(columnName) => !tranformedHeaderRow.includes(columnName) && tranformedHeaderRow.unshift(columnName)
|
|
2816
|
+
);
|
|
2817
|
+
let mappedHeaderRow = tranformedHeaderRow.map((key) => columnMap[key] || key);
|
|
2818
|
+
if (onlyHeaderRow)
|
|
2819
|
+
return [mappedHeaderRow];
|
|
2820
|
+
const withDelimiter = (value) => `${delimiter}${value}${delimiter}`;
|
|
2821
|
+
const columnValueCounts = [];
|
|
2822
|
+
const processRow = (row) => {
|
|
2823
|
+
return Object.values(
|
|
2824
|
+
tranformedHeaderRow.reduce((columnsMap, columnName, columnIndex) => {
|
|
2825
|
+
const accessors = columnTransform[columnName];
|
|
2826
|
+
const value = (accessors?.length ? row[accessors.find((accessor) => row[accessor])] : row[columnName]) || context?.[columnName] || "";
|
|
2827
|
+
const mappedValue = valuesMap[columnName]?.[value] || value;
|
|
2828
|
+
const fxValue = typeof functionMap[columnName] === "function" ? functionMap[columnName](mappedValue) : mappedValue;
|
|
2829
|
+
columnsMap[columnName] = withDelimiter(fxValue);
|
|
2830
|
+
if (fxValue) {
|
|
2831
|
+
columnValueCounts[columnIndex] = (columnValueCounts[columnIndex] || 0) + 1;
|
|
2832
|
+
}
|
|
2833
|
+
return columnsMap;
|
|
2834
|
+
}, {})
|
|
2835
|
+
);
|
|
2836
|
+
};
|
|
2837
|
+
let flattenedRows = flattened.map(processRow);
|
|
2838
|
+
const indicesToRemove = removeEmptyColumns && [...columnValueCounts].map((count, index) => !count && index).filter(isNumeric).reverse();
|
|
2839
|
+
if (indicesToRemove) {
|
|
2840
|
+
const purge = (row) => row.filter((_, index) => !indicesToRemove.includes(index));
|
|
2841
|
+
flattenedRows = flattenedRows.map(purge);
|
|
2842
|
+
mappedHeaderRow = purge(mappedHeaderRow);
|
|
2843
|
+
}
|
|
2844
|
+
const rows = flattenedRows.map((row) => row.join(columnJoiner));
|
|
2845
|
+
if (returnTransformedJSON) {
|
|
2846
|
+
return rows.map((row) => {
|
|
2847
|
+
const columnValues = row.split(columnJoiner);
|
|
2848
|
+
return Object.assign(
|
|
2849
|
+
{},
|
|
2850
|
+
...columnValues.map((v, i) => ({ [mappedHeaderRow[i]]: v }))
|
|
2851
|
+
);
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
return includeHeaderRow ? [mappedHeaderRow.map(withDelimiter).join(columnJoiner), ...rows].join(
|
|
2855
|
+
rowJoiner
|
|
2856
|
+
) : rows.join(rowJoiner);
|
|
2857
|
+
}
|
|
2858
|
+
function flattenJSON(obj, keyJoiner = ".", path = []) {
|
|
2859
|
+
return typeof obj === "object" && Object.keys(obj).reduce((result, key) => {
|
|
2860
|
+
if (typeof obj[key] !== "object") {
|
|
2861
|
+
result[path.concat(key).join(keyJoiner)] = obj[key];
|
|
2862
|
+
return result;
|
|
2863
|
+
}
|
|
2864
|
+
return Object.assign(
|
|
2865
|
+
result,
|
|
2866
|
+
flattenJSON(obj[key], keyJoiner, path.concat(key))
|
|
2867
|
+
);
|
|
2868
|
+
}, {});
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
function UUIDS(count = 1) {
|
|
2872
|
+
return generateRange(0, count).map(UUID);
|
|
2873
|
+
}
|
|
2874
|
+
function UUID() {
|
|
2875
|
+
const lut = [];
|
|
2876
|
+
for (let i = 0; i < 256; i++) {
|
|
2877
|
+
lut[i] = (i < 16 ? "0" : "") + i.toString(16);
|
|
2878
|
+
}
|
|
2879
|
+
const d0 = Math.random() * 4294967295 | 0;
|
|
2880
|
+
const d1 = Math.random() * 4294967295 | 0;
|
|
2881
|
+
const d2 = Math.random() * 4294967295 | 0;
|
|
2882
|
+
const d3 = Math.random() * 4294967295 | 0;
|
|
2883
|
+
return lut[d0 & 255] + lut[d0 >> 8 & 255] + lut[d0 >> 16 & 255] + lut[d0 >> 24 & 255] + "-" + // eslint-disable-next-line no-mixed-operators
|
|
2884
|
+
lut[d1 & 255] + lut[d1 >> 8 & 255] + "-" + lut[d1 >> 16 & 15 | 64] + lut[d1 >> 24 & 255] + "-" + // eslint-disable-next-line no-mixed-operators
|
|
2885
|
+
lut[d2 & 63 | 128] + lut[d2 >> 8 & 255] + "-" + lut[d2 >> 16 & 255] + lut[d2 >> 24 & 255] + // eslint-disable-next-line no-mixed-operators
|
|
2886
|
+
lut[d3 & 255] + lut[d3 >> 8 & 255] + lut[d3 >> 16 & 255] + lut[d3 >> 24 & 255];
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2888
2889
|
function validateTieFormat(params) {
|
|
2889
2890
|
const checkCategory = !!(params?.enforceCategory !== false && params?.category);
|
|
2890
2891
|
const checkGender = !!(params?.enforceGender !== false && params?.gender);
|