@harbortouch/skytab-analytics-report-utils 0.15.0 → 0.16.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/README.md CHANGED
@@ -33,19 +33,34 @@ Requires **Node ≥ 22.6.0** and **pnpm ≥ 9.0.0**.
33
33
  ## Usage
34
34
 
35
35
  ```typescript
36
- // Import everything from the main entry point
37
36
  import {
38
- salesSummaryConfig,
39
- COLUMN_REGISTRY,
40
- getColumnAlignment,
41
- calculateReportTotals,
37
+ salesSummaryConfig,
38
+ COLUMN_REGISTRY,
39
+ getColumnAlignment,
40
+ calculateReportTotals,
42
41
  } from '@harbortouch/skytab-analytics-report-utils';
42
+ ```
43
+
44
+ ### Exporting report data to CSV
45
+
46
+ Import from the `/csv` sub-path. This keeps `csv-stringify` out of frontend bundles — it is only included when this import is actually used.
47
+
48
+ ```typescript
49
+ import { CsvExporter } from '@harbortouch/skytab-analytics-report-utils/csv';
50
+
51
+ const exporter = new CsvExporter();
52
+ const csv = exporter.generate(reportRows);
53
+ // returns a UTF-8 BOM-prefixed CSV string (compatible with Excel)
43
54
 
44
- // Sub-path imports for smaller bundles
45
- import { COLUMN_REGISTRY } from '@harbortouch/skytab-analytics-report-utils/columns';
46
- import { salesSummaryConfig } from '@harbortouch/skytab-analytics-report-utils/reports';
55
+ // With overrides (any csv-stringify option)
56
+ const tsv = new CsvExporter({ delimiter: '\t', bom: false });
57
+ const output = tsv.generate(reportRows);
47
58
  ```
48
59
 
60
+ `CsvExporter` accepts an array of plain objects. Object keys become the header row; all keys are included in their original order. Returns a BOM-only string for empty input (or an empty string when `bom: false` is set).
61
+
62
+ > **Note:** `csv-stringify` is a dependency of this library — consuming projects do not need to install it separately.
63
+
49
64
  ### Integrating with the frontend (React + TanStack Table)
50
65
 
51
66
  ```typescript
@@ -61,9 +76,9 @@ const FIELD_CONFIG = salesSummaryConfig.fields as Record<keyof SalesSummaryRecor
61
76
  import { calculateReportTotals, salesSummaryConfig } from '@harbortouch/skytab-analytics-report-utils';
62
77
 
63
78
  const totals = calculateReportTotals(
64
- data, // row data array
65
- salesSummaryConfig.fields, // field config from this library
66
- { labelField: 'groupByName', label: 'Total' },
79
+ data, // row data array
80
+ salesSummaryConfig.fields, // field config from this library
81
+ { labelField: 'groupByName', label: 'Total' },
67
82
  );
68
83
  ```
69
84
 
@@ -76,6 +91,8 @@ src/
76
91
  ├── types.ts — Core interfaces (FieldType, ColumnPresentationConfig, ReportConfig, …)
77
92
  ├── columns/
78
93
  │ └── index.ts — ReportColumnKey union type + COLUMN_REGISTRY (i18n keys)
94
+ ├── csv/
95
+ │ └── index.ts — CsvExporter — published as the ./csv sub-path export
79
96
  ├── reports/
80
97
  │ ├── salesSummary.ts
81
98
  │ ├── ticketSummary.ts
@@ -94,14 +111,14 @@ src/
94
111
 
95
112
  ## Available reports
96
113
 
97
- | Export | Report |
98
- |---|---|
99
- | `salesSummaryConfig` | Sales Summary |
114
+ | Export | Report |
115
+ | --------------------- | -------------- |
116
+ | `salesSummaryConfig` | Sales Summary |
100
117
  | `ticketSummaryConfig` | Ticket Summary |
101
- | `ticketLiveConfig` | Ticket Live |
102
- | `productMixConfig` | Product Mix |
103
- | `modifierMixConfig` | Modifier Mix |
104
- | `itemTaxConfig` | Item Tax |
118
+ | `ticketLiveConfig` | Ticket Live |
119
+ | `productMixConfig` | Product Mix |
120
+ | `modifierMixConfig` | Modifier Mix |
121
+ | `itemTaxConfig` | Item Tax |
105
122
 
106
123
  ---
107
124
 
@@ -111,26 +128,26 @@ src/
111
128
 
112
129
  Governs both formatting and alignment for a column:
113
130
 
114
- | Type | Alignment | Description |
115
- |---|---|---|
116
- | `string` | left | Plain text |
117
- | `date` | left | Calendar date |
118
- | `time` | left | Time of day |
119
- | `boolean` | right | True/false flag |
120
- | `money` | right | Currency value |
121
- | `number` | right | Integer or generic numeric |
122
- | `fixedNumber` | right | Decimal with fixed precision |
123
- | `percent` | right | Ratio displayed as percentage (×100) |
131
+ | Type | Alignment | Description |
132
+ | ------------- | --------- | ------------------------------------ |
133
+ | `string` | left | Plain text |
134
+ | `date` | left | Calendar date |
135
+ | `time` | left | Time of day |
136
+ | `boolean` | right | True/false flag |
137
+ | `money` | right | Currency value |
138
+ | `number` | right | Integer or generic numeric |
139
+ | `fixedNumber` | right | Decimal with fixed precision |
140
+ | `percent` | right | Ratio displayed as percentage (×100) |
124
141
 
125
142
  ### `FooterCalculation`
126
143
 
127
144
  Declarative aggregation for totals rows:
128
145
 
129
- | Type | Formula |
130
- |---|---|
131
- | `sum` | `Σ row[field]` |
146
+ | Type | Formula |
147
+ | --------------- | ----------------------------------------------- |
148
+ | `sum` | `Σ row[field]` |
132
149
  | `percentChange` | `(Σ numerator − Σ denominator) / Σ denominator` |
133
- | `average` | `Σ numerator / Σ denominator` |
150
+ | `average` | `Σ numerator / Σ denominator` |
134
151
 
135
152
  ### Column Registry
136
153
 
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/csv/index.ts
21
+ var csv_exports = {};
22
+ __export(csv_exports, {
23
+ CsvExporter: () => CsvExporter
24
+ });
25
+ module.exports = __toCommonJS(csv_exports);
26
+ var import_sync = require("csv-stringify/sync");
27
+ var CsvExporter = class {
28
+ constructor(options = {}) {
29
+ this.options = options;
30
+ }
31
+ generate(rows) {
32
+ const opts = { header: true, delimiter: ",", bom: true, ...this.options };
33
+ if (!rows.length) {
34
+ return opts.bom ? "\uFEFF" : "";
35
+ }
36
+ return (0, import_sync.stringify)(rows, opts);
37
+ }
38
+ };
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ CsvExporter
42
+ });
@@ -0,0 +1,9 @@
1
+ import { OptionsNormalized, Input } from 'csv-stringify/sync';
2
+
3
+ declare class CsvExporter {
4
+ private readonly options;
5
+ constructor(options?: Partial<OptionsNormalized>);
6
+ generate(rows: Input): string;
7
+ }
8
+
9
+ export { CsvExporter };
@@ -0,0 +1,9 @@
1
+ import { OptionsNormalized, Input } from 'csv-stringify/sync';
2
+
3
+ declare class CsvExporter {
4
+ private readonly options;
5
+ constructor(options?: Partial<OptionsNormalized>);
6
+ generate(rows: Input): string;
7
+ }
8
+
9
+ export { CsvExporter };
@@ -0,0 +1,17 @@
1
+ // src/csv/index.ts
2
+ import { stringify } from "csv-stringify/sync";
3
+ var CsvExporter = class {
4
+ constructor(options = {}) {
5
+ this.options = options;
6
+ }
7
+ generate(rows) {
8
+ const opts = { header: true, delimiter: ",", bom: true, ...this.options };
9
+ if (!rows.length) {
10
+ return opts.bom ? "\uFEFF" : "";
11
+ }
12
+ return stringify(rows, opts);
13
+ }
14
+ };
15
+ export {
16
+ CsvExporter
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harbortouch/skytab-analytics-report-utils",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Centralized report column presentation configuration for SkyTab Analytics",
5
5
  "engines": {
6
6
  "node": ">=22.6.0",
@@ -14,6 +14,11 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js",
16
16
  "require": "./dist/index.cjs"
17
+ },
18
+ "./csv": {
19
+ "types": "./dist/csv/index.d.ts",
20
+ "import": "./dist/csv/index.js",
21
+ "require": "./dist/csv/index.cjs"
17
22
  }
18
23
  },
19
24
  "files": [
@@ -45,5 +50,8 @@
45
50
  "typescript-eslint": "^8.53.1",
46
51
  "vitest": "^4.1.5"
47
52
  },
48
- "packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a"
53
+ "packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a",
54
+ "dependencies": {
55
+ "csv-stringify": "^6.8.1"
56
+ }
49
57
  }