@harbortouch/skytab-analytics-report-utils 0.7.0 → 0.7.2
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/formatting.d.ts +5 -2
- package/dist/index.cjs +41 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -2
- package/dist/report.d.ts +2 -0
- package/package.json +1 -1
package/dist/formatting.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { FieldType } from './types';
|
|
1
2
|
export type TimeFormat = '00:00' | '00:00:00' | '00:00-24H';
|
|
2
|
-
export interface
|
|
3
|
+
export interface LocaleOption {
|
|
3
4
|
currency: string;
|
|
4
5
|
locale: string;
|
|
5
6
|
}
|
|
@@ -27,8 +28,10 @@ export declare const formatFixedNumber: (value: number, decimals?: number) => st
|
|
|
27
28
|
export declare const formatString: (value: unknown) => string;
|
|
28
29
|
export declare const getNumberToFormat: (value: unknown) => number;
|
|
29
30
|
export declare const getDateToFormat: (value?: unknown) => Date | null;
|
|
31
|
+
export declare const formatMoneyWithoutSymbol: (amount: number, options?: FormatMoneyOptions) => string;
|
|
30
32
|
export declare const getReportFormattingLocaleOptions: (locations: {
|
|
31
33
|
currency: string;
|
|
32
34
|
countryCode: string;
|
|
33
35
|
language: string;
|
|
34
|
-
}[]) =>
|
|
36
|
+
}[]) => LocaleOption[];
|
|
37
|
+
export declare const formatFieldValue: (value: unknown, type: FieldType, localeOptions: LocaleOption) => string;
|
package/dist/index.cjs
CHANGED
|
@@ -60,9 +60,11 @@ __export(index_exports, {
|
|
|
60
60
|
dailySalesTrendsConfig: () => dailySalesTrendsConfig,
|
|
61
61
|
employeeTimecardConfig: () => employeeTimecardConfig,
|
|
62
62
|
formatDate: () => formatDate,
|
|
63
|
+
formatFieldValue: () => formatFieldValue,
|
|
63
64
|
formatFixedNumber: () => formatFixedNumber,
|
|
64
65
|
formatInteger: () => formatInteger,
|
|
65
66
|
formatMoney: () => formatMoney,
|
|
67
|
+
formatMoneyWithoutSymbol: () => formatMoneyWithoutSymbol,
|
|
66
68
|
formatPercent: () => formatPercent,
|
|
67
69
|
formatString: () => formatString,
|
|
68
70
|
formatTime: () => formatTime,
|
|
@@ -817,7 +819,9 @@ var Report = {
|
|
|
817
819
|
ITEM_TAX: "item-tax",
|
|
818
820
|
EMPLOYEE_TIMECARD: "employee-timecard",
|
|
819
821
|
EMPLOYEE_TIP: "employee-tip",
|
|
820
|
-
SALES_BY_ITEM: "sales-by-item"
|
|
822
|
+
SALES_BY_ITEM: "sales-by-item",
|
|
823
|
+
DAILY_SALES: "daily-sales",
|
|
824
|
+
DAILY_SALES_LIVE: "daily-sales-live"
|
|
821
825
|
};
|
|
822
826
|
var REPORT_CONFIG_MAP = {
|
|
823
827
|
"sales-summary": salesSummaryConfig,
|
|
@@ -828,7 +832,9 @@ var REPORT_CONFIG_MAP = {
|
|
|
828
832
|
"item-tax": itemTaxConfig,
|
|
829
833
|
"employee-timecard": employeeTimecardConfig,
|
|
830
834
|
"employee-tip": null,
|
|
831
|
-
"sales-by-item": salesByItemDetailConfig
|
|
835
|
+
"sales-by-item": salesByItemDetailConfig,
|
|
836
|
+
"daily-sales": dailySalesConfig,
|
|
837
|
+
"daily-sales-live": null
|
|
832
838
|
};
|
|
833
839
|
var getReportConfig = (reportType) => REPORT_CONFIG_MAP[reportType];
|
|
834
840
|
|
|
@@ -1659,6 +1665,13 @@ var getDateToFormat = (value) => {
|
|
|
1659
1665
|
}
|
|
1660
1666
|
return null;
|
|
1661
1667
|
};
|
|
1668
|
+
var formatMoneyWithoutSymbol = (amount, options = {}) => {
|
|
1669
|
+
const { locale = "en-US", decimals = 2 } = options;
|
|
1670
|
+
return new Intl.NumberFormat(locale, {
|
|
1671
|
+
minimumFractionDigits: decimals,
|
|
1672
|
+
maximumFractionDigits: decimals
|
|
1673
|
+
}).format(amount);
|
|
1674
|
+
};
|
|
1662
1675
|
var getReportFormattingLocaleOptions = (locations) => {
|
|
1663
1676
|
if (locations.length === 0) {
|
|
1664
1677
|
return [{ currency: "USD", locale: "en-US" }];
|
|
@@ -1672,6 +1685,30 @@ var getReportFormattingLocaleOptions = (locations) => {
|
|
|
1672
1685
|
).values()
|
|
1673
1686
|
);
|
|
1674
1687
|
};
|
|
1688
|
+
var formatFieldValue = (value, type, localeOptions) => {
|
|
1689
|
+
const { currency, locale } = localeOptions;
|
|
1690
|
+
switch (type) {
|
|
1691
|
+
case "string":
|
|
1692
|
+
return formatString(value);
|
|
1693
|
+
case "money":
|
|
1694
|
+
return formatMoney(getNumberToFormat(value), { currency, locale });
|
|
1695
|
+
case "percent":
|
|
1696
|
+
return formatPercent(getNumberToFormat(value) * 100);
|
|
1697
|
+
case "fixedNumber":
|
|
1698
|
+
return formatFixedNumber(getNumberToFormat(value));
|
|
1699
|
+
case "date": {
|
|
1700
|
+
const d = getDateToFormat(value);
|
|
1701
|
+
return d ? formatDate(d, { locale }) : "";
|
|
1702
|
+
}
|
|
1703
|
+
case "time": {
|
|
1704
|
+
const d = getDateToFormat(value);
|
|
1705
|
+
return d ? formatTime(d, { locale, format: "00:00:00" }) : "";
|
|
1706
|
+
}
|
|
1707
|
+
case "number":
|
|
1708
|
+
default:
|
|
1709
|
+
return String(getNumberToFormat(value));
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1675
1712
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1676
1713
|
0 && (module.exports = {
|
|
1677
1714
|
COLUMN_REGISTRY,
|
|
@@ -1714,9 +1751,11 @@ var getReportFormattingLocaleOptions = (locations) => {
|
|
|
1714
1751
|
dailySalesTrendsConfig,
|
|
1715
1752
|
employeeTimecardConfig,
|
|
1716
1753
|
formatDate,
|
|
1754
|
+
formatFieldValue,
|
|
1717
1755
|
formatFixedNumber,
|
|
1718
1756
|
formatInteger,
|
|
1719
1757
|
formatMoney,
|
|
1758
|
+
formatMoneyWithoutSymbol,
|
|
1720
1759
|
formatPercent,
|
|
1721
1760
|
formatString,
|
|
1722
1761
|
formatTime,
|
package/dist/index.d.ts
CHANGED
|
@@ -17,5 +17,5 @@ export { dailySalesRefundsVoidsConfig, DAILY_SALES_REFUNDS_VOIDS_AVAILABLE_COLUM
|
|
|
17
17
|
export { dailySalesTaxesConfig, DAILY_SALES_TAXES_AVAILABLE_COLUMNS, DAILY_SALES_TAXES_DEFAULT_VISIBLE_COLUMNS, } from './reports/dailySalesTaxes';
|
|
18
18
|
export { employeeTimecardConfig, EMPLOYEE_TIMECARD_AVAILABLE_COLUMNS, EMPLOYEE_TIMECARD_DEFAULT_VISIBLE_COLUMNS, } from './reports/employeeTimecard';
|
|
19
19
|
export { salesByItemDetailConfig, SALES_BY_ITEM_DETAIL_AVAILABLE_COLUMNS, SALES_BY_ITEM_DETAIL_DEFAULT_VISIBLE_COLUMNS, } from './reports/salesByItemDetail';
|
|
20
|
-
export type { FormatDateOptions, FormatTimeOptions, FormatMoneyOptions,
|
|
21
|
-
export { formatDate, formatTime, formatMoney, formatPercent, formatInteger, formatFixedNumber, formatString, getNumberToFormat, getDateToFormat, getReportFormattingLocaleOptions, } from './formatting';
|
|
20
|
+
export type { FormatDateOptions, FormatTimeOptions, FormatMoneyOptions, LocaleOption, TimeFormat } from './formatting';
|
|
21
|
+
export { formatDate, formatTime, formatMoney, formatPercent, formatInteger, formatFixedNumber, formatString, getNumberToFormat, getDateToFormat, getReportFormattingLocaleOptions, formatMoneyWithoutSymbol, formatFieldValue, } from './formatting';
|
package/dist/index.js
CHANGED
|
@@ -731,7 +731,9 @@ var Report = {
|
|
|
731
731
|
ITEM_TAX: "item-tax",
|
|
732
732
|
EMPLOYEE_TIMECARD: "employee-timecard",
|
|
733
733
|
EMPLOYEE_TIP: "employee-tip",
|
|
734
|
-
SALES_BY_ITEM: "sales-by-item"
|
|
734
|
+
SALES_BY_ITEM: "sales-by-item",
|
|
735
|
+
DAILY_SALES: "daily-sales",
|
|
736
|
+
DAILY_SALES_LIVE: "daily-sales-live"
|
|
735
737
|
};
|
|
736
738
|
var REPORT_CONFIG_MAP = {
|
|
737
739
|
"sales-summary": salesSummaryConfig,
|
|
@@ -742,7 +744,9 @@ var REPORT_CONFIG_MAP = {
|
|
|
742
744
|
"item-tax": itemTaxConfig,
|
|
743
745
|
"employee-timecard": employeeTimecardConfig,
|
|
744
746
|
"employee-tip": null,
|
|
745
|
-
"sales-by-item": salesByItemDetailConfig
|
|
747
|
+
"sales-by-item": salesByItemDetailConfig,
|
|
748
|
+
"daily-sales": dailySalesConfig,
|
|
749
|
+
"daily-sales-live": null
|
|
746
750
|
};
|
|
747
751
|
var getReportConfig = (reportType) => REPORT_CONFIG_MAP[reportType];
|
|
748
752
|
|
|
@@ -1573,6 +1577,13 @@ var getDateToFormat = (value) => {
|
|
|
1573
1577
|
}
|
|
1574
1578
|
return null;
|
|
1575
1579
|
};
|
|
1580
|
+
var formatMoneyWithoutSymbol = (amount, options = {}) => {
|
|
1581
|
+
const { locale = "en-US", decimals = 2 } = options;
|
|
1582
|
+
return new Intl.NumberFormat(locale, {
|
|
1583
|
+
minimumFractionDigits: decimals,
|
|
1584
|
+
maximumFractionDigits: decimals
|
|
1585
|
+
}).format(amount);
|
|
1586
|
+
};
|
|
1576
1587
|
var getReportFormattingLocaleOptions = (locations) => {
|
|
1577
1588
|
if (locations.length === 0) {
|
|
1578
1589
|
return [{ currency: "USD", locale: "en-US" }];
|
|
@@ -1586,6 +1597,30 @@ var getReportFormattingLocaleOptions = (locations) => {
|
|
|
1586
1597
|
).values()
|
|
1587
1598
|
);
|
|
1588
1599
|
};
|
|
1600
|
+
var formatFieldValue = (value, type, localeOptions) => {
|
|
1601
|
+
const { currency, locale } = localeOptions;
|
|
1602
|
+
switch (type) {
|
|
1603
|
+
case "string":
|
|
1604
|
+
return formatString(value);
|
|
1605
|
+
case "money":
|
|
1606
|
+
return formatMoney(getNumberToFormat(value), { currency, locale });
|
|
1607
|
+
case "percent":
|
|
1608
|
+
return formatPercent(getNumberToFormat(value) * 100);
|
|
1609
|
+
case "fixedNumber":
|
|
1610
|
+
return formatFixedNumber(getNumberToFormat(value));
|
|
1611
|
+
case "date": {
|
|
1612
|
+
const d = getDateToFormat(value);
|
|
1613
|
+
return d ? formatDate(d, { locale }) : "";
|
|
1614
|
+
}
|
|
1615
|
+
case "time": {
|
|
1616
|
+
const d = getDateToFormat(value);
|
|
1617
|
+
return d ? formatTime(d, { locale, format: "00:00:00" }) : "";
|
|
1618
|
+
}
|
|
1619
|
+
case "number":
|
|
1620
|
+
default:
|
|
1621
|
+
return String(getNumberToFormat(value));
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1589
1624
|
export {
|
|
1590
1625
|
COLUMN_REGISTRY,
|
|
1591
1626
|
DAILY_SALES_AVAILABLE_COLUMNS,
|
|
@@ -1627,9 +1662,11 @@ export {
|
|
|
1627
1662
|
dailySalesTrendsConfig,
|
|
1628
1663
|
employeeTimecardConfig,
|
|
1629
1664
|
formatDate,
|
|
1665
|
+
formatFieldValue,
|
|
1630
1666
|
formatFixedNumber,
|
|
1631
1667
|
formatInteger,
|
|
1632
1668
|
formatMoney,
|
|
1669
|
+
formatMoneyWithoutSymbol,
|
|
1633
1670
|
formatPercent,
|
|
1634
1671
|
formatString,
|
|
1635
1672
|
formatTime,
|
package/dist/report.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare const Report: {
|
|
|
9
9
|
readonly EMPLOYEE_TIMECARD: "employee-timecard";
|
|
10
10
|
readonly EMPLOYEE_TIP: "employee-tip";
|
|
11
11
|
readonly SALES_BY_ITEM: "sales-by-item";
|
|
12
|
+
readonly DAILY_SALES: "daily-sales";
|
|
13
|
+
readonly DAILY_SALES_LIVE: "daily-sales-live";
|
|
12
14
|
};
|
|
13
15
|
export type ReportType = (typeof Report)[keyof typeof Report];
|
|
14
16
|
export declare const getReportConfig: (reportType: ReportType) => ReportConfig<string> | null;
|