@harbortouch/skytab-analytics-report-utils 0.6.2 → 0.7.0
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/columns/columns.test.d.ts +1 -0
- package/dist/formatting.d.ts +34 -0
- package/dist/formatting.test.d.ts +1 -0
- package/dist/index.cjs +95 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +85 -0
- package/dist/totals.test.d.ts +1 -0
- package/dist/utils/alignment.test.d.ts +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type TimeFormat = '00:00' | '00:00:00' | '00:00-24H';
|
|
2
|
+
export interface LocaleOptions {
|
|
3
|
+
currency: string;
|
|
4
|
+
locale: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FormatDateOptions {
|
|
7
|
+
locale?: string;
|
|
8
|
+
timeZone?: string;
|
|
9
|
+
format?: TimeFormat;
|
|
10
|
+
}
|
|
11
|
+
export interface FormatTimeOptions {
|
|
12
|
+
locale?: string;
|
|
13
|
+
timeZone?: string;
|
|
14
|
+
format: TimeFormat;
|
|
15
|
+
}
|
|
16
|
+
export interface FormatMoneyOptions {
|
|
17
|
+
locale?: string;
|
|
18
|
+
currency?: string;
|
|
19
|
+
decimals?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare const formatDate: (date: Date, options?: FormatDateOptions) => string;
|
|
22
|
+
export declare const formatTime: (date: Date | string | number, options: FormatTimeOptions) => string;
|
|
23
|
+
export declare const formatMoney: (amount: number, options?: FormatMoneyOptions) => string;
|
|
24
|
+
export declare const formatPercent: (value: number, decimals?: number) => string;
|
|
25
|
+
export declare const formatInteger: (value: number) => string;
|
|
26
|
+
export declare const formatFixedNumber: (value: number, decimals?: number) => string;
|
|
27
|
+
export declare const formatString: (value: unknown) => string;
|
|
28
|
+
export declare const getNumberToFormat: (value: unknown) => number;
|
|
29
|
+
export declare const getDateToFormat: (value?: unknown) => Date | null;
|
|
30
|
+
export declare const getReportFormattingLocaleOptions: (locations: {
|
|
31
|
+
currency: string;
|
|
32
|
+
countryCode: string;
|
|
33
|
+
language: string;
|
|
34
|
+
}[]) => LocaleOptions[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -59,10 +59,20 @@ __export(index_exports, {
|
|
|
59
59
|
dailySalesTaxesConfig: () => dailySalesTaxesConfig,
|
|
60
60
|
dailySalesTrendsConfig: () => dailySalesTrendsConfig,
|
|
61
61
|
employeeTimecardConfig: () => employeeTimecardConfig,
|
|
62
|
+
formatDate: () => formatDate,
|
|
63
|
+
formatFixedNumber: () => formatFixedNumber,
|
|
64
|
+
formatInteger: () => formatInteger,
|
|
65
|
+
formatMoney: () => formatMoney,
|
|
66
|
+
formatPercent: () => formatPercent,
|
|
67
|
+
formatString: () => formatString,
|
|
68
|
+
formatTime: () => formatTime,
|
|
62
69
|
getColumnAlignment: () => getColumnAlignment,
|
|
63
70
|
getColumnExportHeaderLabel: () => getColumnExportHeaderLabel,
|
|
64
71
|
getColumnMetadata: () => getColumnMetadata,
|
|
72
|
+
getDateToFormat: () => getDateToFormat,
|
|
73
|
+
getNumberToFormat: () => getNumberToFormat,
|
|
65
74
|
getReportConfig: () => getReportConfig,
|
|
75
|
+
getReportFormattingLocaleOptions: () => getReportFormattingLocaleOptions,
|
|
66
76
|
isNumericType: () => isNumericType,
|
|
67
77
|
itemTaxConfig: () => itemTaxConfig,
|
|
68
78
|
modifierMixConfig: () => modifierMixConfig,
|
|
@@ -1587,6 +1597,81 @@ var dailySalesTaxesConfig = {
|
|
|
1587
1597
|
availableColumns: DAILY_SALES_TAXES_AVAILABLE_COLUMNS,
|
|
1588
1598
|
defaultVisibleColumns: DAILY_SALES_TAXES_DEFAULT_VISIBLE_COLUMNS
|
|
1589
1599
|
};
|
|
1600
|
+
|
|
1601
|
+
// src/formatting.ts
|
|
1602
|
+
var formatDate = (date, options = {}) => {
|
|
1603
|
+
const { locale = "en-US", timeZone = "UTC" } = options;
|
|
1604
|
+
const d = new Date(date);
|
|
1605
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1606
|
+
dateStyle: "short",
|
|
1607
|
+
timeZone
|
|
1608
|
+
}).format(d);
|
|
1609
|
+
};
|
|
1610
|
+
var formatTime = (date, options) => {
|
|
1611
|
+
const { locale = "en-US", timeZone = "UTC", format } = options;
|
|
1612
|
+
const d = new Date(date);
|
|
1613
|
+
if (format === "00:00") {
|
|
1614
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1615
|
+
hour: "2-digit",
|
|
1616
|
+
minute: "2-digit",
|
|
1617
|
+
timeZone
|
|
1618
|
+
}).format(d);
|
|
1619
|
+
}
|
|
1620
|
+
if (format === "00:00-24H") {
|
|
1621
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1622
|
+
hour: "2-digit",
|
|
1623
|
+
minute: "2-digit",
|
|
1624
|
+
hour12: false,
|
|
1625
|
+
hourCycle: "h23",
|
|
1626
|
+
timeZone
|
|
1627
|
+
}).format(d);
|
|
1628
|
+
}
|
|
1629
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1630
|
+
hour: "2-digit",
|
|
1631
|
+
minute: "2-digit",
|
|
1632
|
+
second: "2-digit",
|
|
1633
|
+
timeZone
|
|
1634
|
+
}).format(d);
|
|
1635
|
+
};
|
|
1636
|
+
var formatMoney = (amount, options = {}) => {
|
|
1637
|
+
const { locale = "en-US", currency = "USD", decimals = 2 } = options;
|
|
1638
|
+
return new Intl.NumberFormat(locale, {
|
|
1639
|
+
style: "currency",
|
|
1640
|
+
currency,
|
|
1641
|
+
minimumFractionDigits: decimals,
|
|
1642
|
+
maximumFractionDigits: decimals
|
|
1643
|
+
}).format(amount);
|
|
1644
|
+
};
|
|
1645
|
+
var formatPercent = (value, decimals = 2) => `${value.toFixed(decimals)}%`;
|
|
1646
|
+
var formatInteger = (value) => Math.round(value).toString();
|
|
1647
|
+
var formatFixedNumber = (value, decimals = 2) => value.toFixed(decimals);
|
|
1648
|
+
var formatString = (value) => {
|
|
1649
|
+
return value == null ? "" : typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
1650
|
+
};
|
|
1651
|
+
var getNumberToFormat = (value) => typeof value === "number" ? value : 0;
|
|
1652
|
+
var getDateToFormat = (value) => {
|
|
1653
|
+
if (value instanceof Date) {
|
|
1654
|
+
return isNaN(value.getTime()) ? null : value;
|
|
1655
|
+
}
|
|
1656
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
1657
|
+
const d = new Date(value);
|
|
1658
|
+
return isNaN(d.getTime()) ? null : d;
|
|
1659
|
+
}
|
|
1660
|
+
return null;
|
|
1661
|
+
};
|
|
1662
|
+
var getReportFormattingLocaleOptions = (locations) => {
|
|
1663
|
+
if (locations.length === 0) {
|
|
1664
|
+
return [{ currency: "USD", locale: "en-US" }];
|
|
1665
|
+
}
|
|
1666
|
+
return Array.from(
|
|
1667
|
+
new Map(
|
|
1668
|
+
locations.map((loc) => ({
|
|
1669
|
+
currency: loc.currency,
|
|
1670
|
+
locale: `${loc.language ?? "en"}-${loc.countryCode}`
|
|
1671
|
+
})).map((item) => [`${item.currency}-${item.locale}`, item])
|
|
1672
|
+
).values()
|
|
1673
|
+
);
|
|
1674
|
+
};
|
|
1590
1675
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1591
1676
|
0 && (module.exports = {
|
|
1592
1677
|
COLUMN_REGISTRY,
|
|
@@ -1628,10 +1713,20 @@ var dailySalesTaxesConfig = {
|
|
|
1628
1713
|
dailySalesTaxesConfig,
|
|
1629
1714
|
dailySalesTrendsConfig,
|
|
1630
1715
|
employeeTimecardConfig,
|
|
1716
|
+
formatDate,
|
|
1717
|
+
formatFixedNumber,
|
|
1718
|
+
formatInteger,
|
|
1719
|
+
formatMoney,
|
|
1720
|
+
formatPercent,
|
|
1721
|
+
formatString,
|
|
1722
|
+
formatTime,
|
|
1631
1723
|
getColumnAlignment,
|
|
1632
1724
|
getColumnExportHeaderLabel,
|
|
1633
1725
|
getColumnMetadata,
|
|
1726
|
+
getDateToFormat,
|
|
1727
|
+
getNumberToFormat,
|
|
1634
1728
|
getReportConfig,
|
|
1729
|
+
getReportFormattingLocaleOptions,
|
|
1635
1730
|
isNumericType,
|
|
1636
1731
|
itemTaxConfig,
|
|
1637
1732
|
modifierMixConfig,
|
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +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, LocaleOptions } from './formatting';
|
|
21
|
+
export { formatDate, formatTime, formatMoney, formatPercent, formatInteger, formatFixedNumber, formatString, getNumberToFormat, getDateToFormat, getReportFormattingLocaleOptions, } from './formatting';
|
package/dist/index.js
CHANGED
|
@@ -1511,6 +1511,81 @@ var dailySalesTaxesConfig = {
|
|
|
1511
1511
|
availableColumns: DAILY_SALES_TAXES_AVAILABLE_COLUMNS,
|
|
1512
1512
|
defaultVisibleColumns: DAILY_SALES_TAXES_DEFAULT_VISIBLE_COLUMNS
|
|
1513
1513
|
};
|
|
1514
|
+
|
|
1515
|
+
// src/formatting.ts
|
|
1516
|
+
var formatDate = (date, options = {}) => {
|
|
1517
|
+
const { locale = "en-US", timeZone = "UTC" } = options;
|
|
1518
|
+
const d = new Date(date);
|
|
1519
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1520
|
+
dateStyle: "short",
|
|
1521
|
+
timeZone
|
|
1522
|
+
}).format(d);
|
|
1523
|
+
};
|
|
1524
|
+
var formatTime = (date, options) => {
|
|
1525
|
+
const { locale = "en-US", timeZone = "UTC", format } = options;
|
|
1526
|
+
const d = new Date(date);
|
|
1527
|
+
if (format === "00:00") {
|
|
1528
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1529
|
+
hour: "2-digit",
|
|
1530
|
+
minute: "2-digit",
|
|
1531
|
+
timeZone
|
|
1532
|
+
}).format(d);
|
|
1533
|
+
}
|
|
1534
|
+
if (format === "00:00-24H") {
|
|
1535
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1536
|
+
hour: "2-digit",
|
|
1537
|
+
minute: "2-digit",
|
|
1538
|
+
hour12: false,
|
|
1539
|
+
hourCycle: "h23",
|
|
1540
|
+
timeZone
|
|
1541
|
+
}).format(d);
|
|
1542
|
+
}
|
|
1543
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1544
|
+
hour: "2-digit",
|
|
1545
|
+
minute: "2-digit",
|
|
1546
|
+
second: "2-digit",
|
|
1547
|
+
timeZone
|
|
1548
|
+
}).format(d);
|
|
1549
|
+
};
|
|
1550
|
+
var formatMoney = (amount, options = {}) => {
|
|
1551
|
+
const { locale = "en-US", currency = "USD", decimals = 2 } = options;
|
|
1552
|
+
return new Intl.NumberFormat(locale, {
|
|
1553
|
+
style: "currency",
|
|
1554
|
+
currency,
|
|
1555
|
+
minimumFractionDigits: decimals,
|
|
1556
|
+
maximumFractionDigits: decimals
|
|
1557
|
+
}).format(amount);
|
|
1558
|
+
};
|
|
1559
|
+
var formatPercent = (value, decimals = 2) => `${value.toFixed(decimals)}%`;
|
|
1560
|
+
var formatInteger = (value) => Math.round(value).toString();
|
|
1561
|
+
var formatFixedNumber = (value, decimals = 2) => value.toFixed(decimals);
|
|
1562
|
+
var formatString = (value) => {
|
|
1563
|
+
return value == null ? "" : typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
1564
|
+
};
|
|
1565
|
+
var getNumberToFormat = (value) => typeof value === "number" ? value : 0;
|
|
1566
|
+
var getDateToFormat = (value) => {
|
|
1567
|
+
if (value instanceof Date) {
|
|
1568
|
+
return isNaN(value.getTime()) ? null : value;
|
|
1569
|
+
}
|
|
1570
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
1571
|
+
const d = new Date(value);
|
|
1572
|
+
return isNaN(d.getTime()) ? null : d;
|
|
1573
|
+
}
|
|
1574
|
+
return null;
|
|
1575
|
+
};
|
|
1576
|
+
var getReportFormattingLocaleOptions = (locations) => {
|
|
1577
|
+
if (locations.length === 0) {
|
|
1578
|
+
return [{ currency: "USD", locale: "en-US" }];
|
|
1579
|
+
}
|
|
1580
|
+
return Array.from(
|
|
1581
|
+
new Map(
|
|
1582
|
+
locations.map((loc) => ({
|
|
1583
|
+
currency: loc.currency,
|
|
1584
|
+
locale: `${loc.language ?? "en"}-${loc.countryCode}`
|
|
1585
|
+
})).map((item) => [`${item.currency}-${item.locale}`, item])
|
|
1586
|
+
).values()
|
|
1587
|
+
);
|
|
1588
|
+
};
|
|
1514
1589
|
export {
|
|
1515
1590
|
COLUMN_REGISTRY,
|
|
1516
1591
|
DAILY_SALES_AVAILABLE_COLUMNS,
|
|
@@ -1551,10 +1626,20 @@ export {
|
|
|
1551
1626
|
dailySalesTaxesConfig,
|
|
1552
1627
|
dailySalesTrendsConfig,
|
|
1553
1628
|
employeeTimecardConfig,
|
|
1629
|
+
formatDate,
|
|
1630
|
+
formatFixedNumber,
|
|
1631
|
+
formatInteger,
|
|
1632
|
+
formatMoney,
|
|
1633
|
+
formatPercent,
|
|
1634
|
+
formatString,
|
|
1635
|
+
formatTime,
|
|
1554
1636
|
getColumnAlignment,
|
|
1555
1637
|
getColumnExportHeaderLabel,
|
|
1556
1638
|
getColumnMetadata,
|
|
1639
|
+
getDateToFormat,
|
|
1640
|
+
getNumberToFormat,
|
|
1557
1641
|
getReportConfig,
|
|
1642
|
+
getReportFormattingLocaleOptions,
|
|
1558
1643
|
isNumericType,
|
|
1559
1644
|
itemTaxConfig,
|
|
1560
1645
|
modifierMixConfig,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harbortouch/skytab-analytics-report-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Centralized report column presentation configuration for SkyTab Analytics",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.6.0",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"lint:js": "eslint src",
|
|
27
27
|
"lint:js:fix": "eslint src --fix",
|
|
28
28
|
"lint:types": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run",
|
|
29
30
|
"typecheck": "tsc --noEmit",
|
|
30
31
|
"prepare": "husky"
|
|
31
32
|
},
|
|
@@ -41,7 +42,8 @@
|
|
|
41
42
|
"pretty-quick": "^4.2.2",
|
|
42
43
|
"tsup": "^8.0.0",
|
|
43
44
|
"typescript": "^5.9.3",
|
|
44
|
-
"typescript-eslint": "^8.53.1"
|
|
45
|
+
"typescript-eslint": "^8.53.1",
|
|
46
|
+
"vitest": "^4.1.5"
|
|
45
47
|
},
|
|
46
48
|
"packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a"
|
|
47
49
|
}
|