@harbortouch/skytab-analytics-report-utils 0.7.0 → 0.7.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/formatting.d.ts +5 -2
- package/dist/index.cjs +35 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -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,
|
|
@@ -1659,6 +1661,13 @@ var getDateToFormat = (value) => {
|
|
|
1659
1661
|
}
|
|
1660
1662
|
return null;
|
|
1661
1663
|
};
|
|
1664
|
+
var formatMoneyWithoutSymbol = (amount, options = {}) => {
|
|
1665
|
+
const { locale = "en-US", decimals = 2 } = options;
|
|
1666
|
+
return new Intl.NumberFormat(locale, {
|
|
1667
|
+
minimumFractionDigits: decimals,
|
|
1668
|
+
maximumFractionDigits: decimals
|
|
1669
|
+
}).format(amount);
|
|
1670
|
+
};
|
|
1662
1671
|
var getReportFormattingLocaleOptions = (locations) => {
|
|
1663
1672
|
if (locations.length === 0) {
|
|
1664
1673
|
return [{ currency: "USD", locale: "en-US" }];
|
|
@@ -1672,6 +1681,30 @@ var getReportFormattingLocaleOptions = (locations) => {
|
|
|
1672
1681
|
).values()
|
|
1673
1682
|
);
|
|
1674
1683
|
};
|
|
1684
|
+
var formatFieldValue = (value, type, localeOptions) => {
|
|
1685
|
+
const { currency, locale } = localeOptions;
|
|
1686
|
+
switch (type) {
|
|
1687
|
+
case "string":
|
|
1688
|
+
return formatString(value);
|
|
1689
|
+
case "money":
|
|
1690
|
+
return formatMoney(getNumberToFormat(value), { currency, locale });
|
|
1691
|
+
case "percent":
|
|
1692
|
+
return formatPercent(getNumberToFormat(value) * 100);
|
|
1693
|
+
case "fixedNumber":
|
|
1694
|
+
return formatFixedNumber(getNumberToFormat(value));
|
|
1695
|
+
case "date": {
|
|
1696
|
+
const d = getDateToFormat(value);
|
|
1697
|
+
return d ? formatDate(d, { locale }) : "";
|
|
1698
|
+
}
|
|
1699
|
+
case "time": {
|
|
1700
|
+
const d = getDateToFormat(value);
|
|
1701
|
+
return d ? formatTime(d, { locale, format: "00:00:00" }) : "";
|
|
1702
|
+
}
|
|
1703
|
+
case "number":
|
|
1704
|
+
default:
|
|
1705
|
+
return String(getNumberToFormat(value));
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1675
1708
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1676
1709
|
0 && (module.exports = {
|
|
1677
1710
|
COLUMN_REGISTRY,
|
|
@@ -1714,9 +1747,11 @@ var getReportFormattingLocaleOptions = (locations) => {
|
|
|
1714
1747
|
dailySalesTrendsConfig,
|
|
1715
1748
|
employeeTimecardConfig,
|
|
1716
1749
|
formatDate,
|
|
1750
|
+
formatFieldValue,
|
|
1717
1751
|
formatFixedNumber,
|
|
1718
1752
|
formatInteger,
|
|
1719
1753
|
formatMoney,
|
|
1754
|
+
formatMoneyWithoutSymbol,
|
|
1720
1755
|
formatPercent,
|
|
1721
1756
|
formatString,
|
|
1722
1757
|
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
|
@@ -1573,6 +1573,13 @@ var getDateToFormat = (value) => {
|
|
|
1573
1573
|
}
|
|
1574
1574
|
return null;
|
|
1575
1575
|
};
|
|
1576
|
+
var formatMoneyWithoutSymbol = (amount, options = {}) => {
|
|
1577
|
+
const { locale = "en-US", decimals = 2 } = options;
|
|
1578
|
+
return new Intl.NumberFormat(locale, {
|
|
1579
|
+
minimumFractionDigits: decimals,
|
|
1580
|
+
maximumFractionDigits: decimals
|
|
1581
|
+
}).format(amount);
|
|
1582
|
+
};
|
|
1576
1583
|
var getReportFormattingLocaleOptions = (locations) => {
|
|
1577
1584
|
if (locations.length === 0) {
|
|
1578
1585
|
return [{ currency: "USD", locale: "en-US" }];
|
|
@@ -1586,6 +1593,30 @@ var getReportFormattingLocaleOptions = (locations) => {
|
|
|
1586
1593
|
).values()
|
|
1587
1594
|
);
|
|
1588
1595
|
};
|
|
1596
|
+
var formatFieldValue = (value, type, localeOptions) => {
|
|
1597
|
+
const { currency, locale } = localeOptions;
|
|
1598
|
+
switch (type) {
|
|
1599
|
+
case "string":
|
|
1600
|
+
return formatString(value);
|
|
1601
|
+
case "money":
|
|
1602
|
+
return formatMoney(getNumberToFormat(value), { currency, locale });
|
|
1603
|
+
case "percent":
|
|
1604
|
+
return formatPercent(getNumberToFormat(value) * 100);
|
|
1605
|
+
case "fixedNumber":
|
|
1606
|
+
return formatFixedNumber(getNumberToFormat(value));
|
|
1607
|
+
case "date": {
|
|
1608
|
+
const d = getDateToFormat(value);
|
|
1609
|
+
return d ? formatDate(d, { locale }) : "";
|
|
1610
|
+
}
|
|
1611
|
+
case "time": {
|
|
1612
|
+
const d = getDateToFormat(value);
|
|
1613
|
+
return d ? formatTime(d, { locale, format: "00:00:00" }) : "";
|
|
1614
|
+
}
|
|
1615
|
+
case "number":
|
|
1616
|
+
default:
|
|
1617
|
+
return String(getNumberToFormat(value));
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1589
1620
|
export {
|
|
1590
1621
|
COLUMN_REGISTRY,
|
|
1591
1622
|
DAILY_SALES_AVAILABLE_COLUMNS,
|
|
@@ -1627,9 +1658,11 @@ export {
|
|
|
1627
1658
|
dailySalesTrendsConfig,
|
|
1628
1659
|
employeeTimecardConfig,
|
|
1629
1660
|
formatDate,
|
|
1661
|
+
formatFieldValue,
|
|
1630
1662
|
formatFixedNumber,
|
|
1631
1663
|
formatInteger,
|
|
1632
1664
|
formatMoney,
|
|
1665
|
+
formatMoneyWithoutSymbol,
|
|
1633
1666
|
formatPercent,
|
|
1634
1667
|
formatString,
|
|
1635
1668
|
formatTime,
|