@harbortouch/skytab-analytics-report-utils 0.7.2 → 0.8.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/index.cjs CHANGED
@@ -1525,8 +1525,12 @@ function calculateReportTotals(data, fieldConfig, opts) {
1525
1525
  }
1526
1526
  } else {
1527
1527
  derivedFields.push({ field, calc });
1528
- if (calc.numeratorField) fieldsToSum.add(calc.numeratorField);
1529
- if (calc.denominatorField) fieldsToSum.add(calc.denominatorField);
1528
+ if (calc.numeratorField) {
1529
+ fieldsToSum.add(calc.numeratorField);
1530
+ }
1531
+ if (calc.denominatorField) {
1532
+ fieldsToSum.add(calc.denominatorField);
1533
+ }
1530
1534
  }
1531
1535
  }
1532
1536
  const sums = {};
@@ -1605,48 +1609,75 @@ var dailySalesTaxesConfig = {
1605
1609
  };
1606
1610
 
1607
1611
  // src/formatting.ts
1612
+ var dateFormatterCache = /* @__PURE__ */ new Map();
1613
+ var timeFormatterCache = /* @__PURE__ */ new Map();
1614
+ var moneyFormatterCache = /* @__PURE__ */ new Map();
1615
+ var numberFormatterCache = /* @__PURE__ */ new Map();
1616
+ var getDateFormatter = (locale, timeZone) => {
1617
+ const key = `${locale}-${timeZone}`;
1618
+ let fmt = dateFormatterCache.get(key);
1619
+ if (!fmt) {
1620
+ fmt = new Intl.DateTimeFormat(locale, { dateStyle: "short", timeZone });
1621
+ dateFormatterCache.set(key, fmt);
1622
+ }
1623
+ return fmt;
1624
+ };
1625
+ var getTimeFormatter = (locale, timeZone, format) => {
1626
+ const key = `${locale}-${timeZone}-${format}`;
1627
+ let fmt = timeFormatterCache.get(key);
1628
+ if (!fmt) {
1629
+ if (format === "00:00") {
1630
+ fmt = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit", timeZone });
1631
+ } else if (format === "00:00-24H") {
1632
+ fmt = new Intl.DateTimeFormat(locale, {
1633
+ hour: "2-digit",
1634
+ minute: "2-digit",
1635
+ hour12: false,
1636
+ hourCycle: "h23",
1637
+ timeZone
1638
+ });
1639
+ } else {
1640
+ fmt = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit", second: "2-digit", timeZone });
1641
+ }
1642
+ timeFormatterCache.set(key, fmt);
1643
+ }
1644
+ return fmt;
1645
+ };
1646
+ var getMoneyFormatter = (locale, currency, decimals) => {
1647
+ const key = `${locale}-${currency}-${decimals}`;
1648
+ let fmt = moneyFormatterCache.get(key);
1649
+ if (!fmt) {
1650
+ fmt = new Intl.NumberFormat(locale, {
1651
+ style: "currency",
1652
+ currency,
1653
+ minimumFractionDigits: decimals,
1654
+ maximumFractionDigits: decimals
1655
+ });
1656
+ moneyFormatterCache.set(key, fmt);
1657
+ }
1658
+ return fmt;
1659
+ };
1660
+ var getNumberFormatter = (locale, decimals) => {
1661
+ const key = `${locale}-${decimals}`;
1662
+ let fmt = numberFormatterCache.get(key);
1663
+ if (!fmt) {
1664
+ fmt = new Intl.NumberFormat(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
1665
+ numberFormatterCache.set(key, fmt);
1666
+ }
1667
+ return fmt;
1668
+ };
1608
1669
  var formatDate = (date, options = {}) => {
1609
1670
  const { locale = "en-US", timeZone = "UTC" } = options;
1610
- const d = new Date(date);
1611
- return new Intl.DateTimeFormat(locale, {
1612
- dateStyle: "short",
1613
- timeZone
1614
- }).format(d);
1671
+ return getDateFormatter(locale, timeZone).format(date);
1615
1672
  };
1616
1673
  var formatTime = (date, options) => {
1617
1674
  const { locale = "en-US", timeZone = "UTC", format } = options;
1618
1675
  const d = new Date(date);
1619
- if (format === "00:00") {
1620
- return new Intl.DateTimeFormat(locale, {
1621
- hour: "2-digit",
1622
- minute: "2-digit",
1623
- timeZone
1624
- }).format(d);
1625
- }
1626
- if (format === "00:00-24H") {
1627
- return new Intl.DateTimeFormat(locale, {
1628
- hour: "2-digit",
1629
- minute: "2-digit",
1630
- hour12: false,
1631
- hourCycle: "h23",
1632
- timeZone
1633
- }).format(d);
1634
- }
1635
- return new Intl.DateTimeFormat(locale, {
1636
- hour: "2-digit",
1637
- minute: "2-digit",
1638
- second: "2-digit",
1639
- timeZone
1640
- }).format(d);
1676
+ return getTimeFormatter(locale, timeZone, format).format(d);
1641
1677
  };
1642
1678
  var formatMoney = (amount, options = {}) => {
1643
1679
  const { locale = "en-US", currency = "USD", decimals = 2 } = options;
1644
- return new Intl.NumberFormat(locale, {
1645
- style: "currency",
1646
- currency,
1647
- minimumFractionDigits: decimals,
1648
- maximumFractionDigits: decimals
1649
- }).format(amount);
1680
+ return getMoneyFormatter(locale, currency, decimals).format(amount);
1650
1681
  };
1651
1682
  var formatPercent = (value, decimals = 2) => `${value.toFixed(decimals)}%`;
1652
1683
  var formatInteger = (value) => Math.round(value).toString();
@@ -1667,10 +1698,7 @@ var getDateToFormat = (value) => {
1667
1698
  };
1668
1699
  var formatMoneyWithoutSymbol = (amount, options = {}) => {
1669
1700
  const { locale = "en-US", decimals = 2 } = options;
1670
- return new Intl.NumberFormat(locale, {
1671
- minimumFractionDigits: decimals,
1672
- maximumFractionDigits: decimals
1673
- }).format(amount);
1701
+ return getNumberFormatter(locale, decimals).format(amount);
1674
1702
  };
1675
1703
  var getReportFormattingLocaleOptions = (locations) => {
1676
1704
  if (locations.length === 0) {