csv-charts-ai 1.7.0 → 1.9.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 +81 -18
- package/dist/charts.d.ts +69 -0
- package/dist/charts.js +978 -0
- package/dist/charts.js.map +1 -0
- package/dist/constants-hUsrIT8W.d.ts +59 -0
- package/dist/index.d.ts +130 -128
- package/dist/index.js +421 -813
- package/dist/index.js.map +1 -1
- package/package.json +16 -10
package/README.md
CHANGED
|
@@ -7,10 +7,12 @@ AI-powered CSV analysis, chart generation, and interactive visualization. Built
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
pnpm add csv-charts-ai
|
|
10
|
+
pnpm add csv-charts-ai
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
All AI SDKs (`ai`, `zod`, `@ai-sdk/openai`, `@ai-sdk/anthropic`, `@ai-sdk/google`, `@ai-sdk/mistral`) and `read-excel-file` are bundled — no extra installs needed.
|
|
14
|
+
|
|
15
|
+
**Optional peer dependencies** (only for React chart components): `react`, `recharts`, `lucide-react`.
|
|
14
16
|
|
|
15
17
|
## Quick Start
|
|
16
18
|
|
|
@@ -67,6 +69,33 @@ console.log(data.columns); // [{ name: "name", type: "string", index: 0 }, ...
|
|
|
67
69
|
|
|
68
70
|
> For very large files or exotic encodings, consider using [PapaParse](https://www.papaparse.com/) and passing the result as `TabularData` directly.
|
|
69
71
|
|
|
72
|
+
## XLSX Parsing
|
|
73
|
+
|
|
74
|
+
Parse Excel (.xlsx) files into the same `TabularData` format. `read-excel-file` is bundled.
|
|
75
|
+
|
|
76
|
+
### Browser
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { parseXLSX } from "csv-charts-ai";
|
|
80
|
+
|
|
81
|
+
const data = await parseXLSX(file); // File from <input> or drag-and-drop
|
|
82
|
+
console.log(data.headers, data.rowCount);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Node.js / Universal
|
|
86
|
+
|
|
87
|
+
Use `convertXLSXRows` with any XLSX reader — it takes raw row arrays and has zero dependencies:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import readXlsxFile from "read-excel-file/node";
|
|
91
|
+
import { convertXLSXRows } from "csv-charts-ai";
|
|
92
|
+
|
|
93
|
+
const rows = await readXlsxFile("data.xlsx");
|
|
94
|
+
const data = convertXLSXRows(rows);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Options: `{ hasHeader?: boolean, skipEmpty?: boolean }` — same defaults as `parseCSV`.
|
|
98
|
+
|
|
70
99
|
## AI Functions
|
|
71
100
|
|
|
72
101
|
All AI functions accept either a simple config object or a pre-built `LanguageModel` from the Vercel AI SDK. All support an optional `signal` (AbortSignal) for cancellation.
|
|
@@ -247,14 +276,19 @@ useEffect(() => {
|
|
|
247
276
|
}, [data]);
|
|
248
277
|
```
|
|
249
278
|
|
|
250
|
-
## React Components
|
|
279
|
+
## React Components (`csv-charts-ai/charts`)
|
|
251
280
|
|
|
252
|
-
|
|
281
|
+
Chart components are available as a **separate entry point** so projects that only need AI/parsing don't pull in React, Recharts, or Lucide.
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Optional peer dependencies — only needed if you import from csv-charts-ai/charts
|
|
285
|
+
pnpm add react recharts lucide-react
|
|
286
|
+
```
|
|
253
287
|
|
|
254
288
|
### Display Charts
|
|
255
289
|
|
|
256
290
|
```tsx
|
|
257
|
-
import { ChartDisplay } from "csv-charts-ai";
|
|
291
|
+
import { ChartDisplay } from "csv-charts-ai/charts";
|
|
258
292
|
|
|
259
293
|
<ChartDisplay data={data} charts={charts} />
|
|
260
294
|
```
|
|
@@ -262,7 +296,7 @@ import { ChartDisplay } from "csv-charts-ai";
|
|
|
262
296
|
### With Theme
|
|
263
297
|
|
|
264
298
|
```tsx
|
|
265
|
-
import { ChartDisplay, defaultLightTheme } from "csv-charts-ai";
|
|
299
|
+
import { ChartDisplay, defaultLightTheme } from "csv-charts-ai/charts";
|
|
266
300
|
|
|
267
301
|
<ChartDisplay data={data} charts={charts} theme={defaultLightTheme} />
|
|
268
302
|
```
|
|
@@ -270,6 +304,9 @@ import { ChartDisplay, defaultLightTheme } from "csv-charts-ai";
|
|
|
270
304
|
### Custom Card Wrapper
|
|
271
305
|
|
|
272
306
|
```tsx
|
|
307
|
+
import { ChartDisplay } from "csv-charts-ai/charts";
|
|
308
|
+
import { repairChart } from "csv-charts-ai";
|
|
309
|
+
|
|
273
310
|
<ChartDisplay
|
|
274
311
|
data={data}
|
|
275
312
|
charts={charts}
|
|
@@ -309,7 +346,7 @@ You can also pass `className` to any component to add classes alongside the buil
|
|
|
309
346
|
|
|
310
347
|
### Headless Usage (No React)
|
|
311
348
|
|
|
312
|
-
The
|
|
349
|
+
The core entry point (`csv-charts-ai`) works without React — use it in Node.js scripts, APIs, or CLI tools:
|
|
313
350
|
|
|
314
351
|
```ts
|
|
315
352
|
import { parseCSV, analyzeData } from "csv-charts-ai";
|
|
@@ -326,7 +363,7 @@ const result = await analyzeData({
|
|
|
326
363
|
console.log(result.summary.keyInsights);
|
|
327
364
|
```
|
|
328
365
|
|
|
329
|
-
## Components Reference
|
|
366
|
+
## Components Reference (`csv-charts-ai/charts`)
|
|
330
367
|
|
|
331
368
|
| Export | Description |
|
|
332
369
|
|--------|-------------|
|
|
@@ -355,9 +392,14 @@ console.log(result.summary.keyInsights);
|
|
|
355
392
|
| Export | Description |
|
|
356
393
|
|--------|-------------|
|
|
357
394
|
| `parseCSV(csv, options?)` | Parse CSV string into `TabularData` |
|
|
395
|
+
| `parseXLSX(file, options?)` | Parse XLSX file into `TabularData` (browser) |
|
|
396
|
+
| `convertXLSXRows(rows, options?)` | Convert raw XLSX rows into `TabularData` (universal) |
|
|
397
|
+
| `computeDiff(dataA, dataB, options)` | Compare two datasets (index, key, or content matching) |
|
|
358
398
|
| `createModel(config)` | Create a LanguageModel from an AIConfig |
|
|
359
|
-
| `
|
|
360
|
-
| `
|
|
399
|
+
| `createAppModel(config)` | Create a LanguageModel from multi-provider app config |
|
|
400
|
+
| `resolveModel(input)` | Resolve AIConfig, AppModelConfig, or LanguageModel |
|
|
401
|
+
| `generateDataSummary(data)` | Detailed human-readable data summary with sample rows |
|
|
402
|
+
| `summarizeTabularData(data)` | Compact data summary for AI prompt consumption |
|
|
361
403
|
| `getAIErrorMessage(error)` | Extract user-friendly error messages |
|
|
362
404
|
| `processChartData(data, chart)` | Process and aggregate chart data |
|
|
363
405
|
| `processChartDataMultiSeries(data, chart)` | Multi-series data processing |
|
|
@@ -380,16 +422,37 @@ Multi-series supported via `groupBy` for bar, line, and area charts.
|
|
|
380
422
|
|
|
381
423
|
`sum` | `avg` | `count` | `min` | `max` | `none`
|
|
382
424
|
|
|
425
|
+
## CSV Diff
|
|
426
|
+
|
|
427
|
+
Compare two datasets and detect added, removed, and changed rows:
|
|
428
|
+
|
|
429
|
+
```ts
|
|
430
|
+
import { computeDiff } from "csv-charts-ai";
|
|
431
|
+
|
|
432
|
+
const diff = computeDiff(dataA, dataB, { matchMode: "key", keyColumn: "id" });
|
|
433
|
+
|
|
434
|
+
console.log(diff.counts); // { same: 10, changed: 3, added: 2, removed: 1 }
|
|
435
|
+
diff.rows.forEach(r => {
|
|
436
|
+
if (r.status === "changed") {
|
|
437
|
+
console.log(`Row ${r.indexA}: changed columns: ${[...r.changedCols].join(", ")}`);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Match modes: `"index"` (positional), `"key"` (by column value), `"content"` (full row match).
|
|
443
|
+
|
|
383
444
|
## Provider Support
|
|
384
445
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
|
388
|
-
|
|
389
|
-
|
|
|
390
|
-
| Anthropic | `{ provider: "anthropic", apiKey, model }` |
|
|
391
|
-
| Google | `{ provider: "google", apiKey, model }` |
|
|
392
|
-
|
|
|
446
|
+
All provider SDKs are bundled — no extra installs needed.
|
|
447
|
+
|
|
448
|
+
| Provider | Config |
|
|
449
|
+
|----------|--------|
|
|
450
|
+
| OpenAI | `{ apiKey, model }` |
|
|
451
|
+
| Anthropic | `{ provider: "anthropic", apiKey, model }` |
|
|
452
|
+
| Google | `{ provider: "google", apiKey, model }` |
|
|
453
|
+
| Mistral | `{ provider: "mistral", apiKey, model }` |
|
|
454
|
+
| Ollama / vLLM / LM Studio | `{ apiKey: "", model, baseURL }` |
|
|
455
|
+
| Any LanguageModel | Pass instance directly |
|
|
393
456
|
|
|
394
457
|
## License
|
|
395
458
|
|
package/dist/charts.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { T as TabularData, C as ChartConfig, c as ChartTheme, d as ChartType, S as SortOrder } from './constants-hUsrIT8W.js';
|
|
3
|
+
export { A as AggregationType, a as COLORS, b as ChartDataPoint, P as ProcessedChartResult, e as defaultDarkTheme, f as defaultLightTheme, p as processChartData, g as processChartDataMultiSeries } from './constants-hUsrIT8W.js';
|
|
4
|
+
|
|
5
|
+
interface ChartDisplayProps {
|
|
6
|
+
data: TabularData;
|
|
7
|
+
charts: ChartConfig[];
|
|
8
|
+
onRegenerate?: (chart: ChartConfig) => Promise<void>;
|
|
9
|
+
/** Optional wrapper component for each chart card */
|
|
10
|
+
cardWrapper?: React.ComponentType<{
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
title?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
}>;
|
|
15
|
+
/** Optional theme override */
|
|
16
|
+
theme?: ChartTheme;
|
|
17
|
+
/** Additional CSS class for the outer container */
|
|
18
|
+
className?: string;
|
|
19
|
+
/** Additional CSS class for each chart card */
|
|
20
|
+
chartClassName?: string;
|
|
21
|
+
/** Additional CSS class for chart title */
|
|
22
|
+
titleClassName?: string;
|
|
23
|
+
/** Additional CSS class for chart description */
|
|
24
|
+
descriptionClassName?: string;
|
|
25
|
+
/** When true, removes all built-in Tailwind classes. You must style everything yourself. */
|
|
26
|
+
unstyled?: boolean;
|
|
27
|
+
}
|
|
28
|
+
declare function ChartDisplay({ data, charts, onRegenerate, cardWrapper: CardWrapper, theme, className, chartClassName, titleClassName, descriptionClassName, unstyled, }: ChartDisplayProps): react_jsx_runtime.JSX.Element | null;
|
|
29
|
+
|
|
30
|
+
interface SingleChartProps {
|
|
31
|
+
data: TabularData;
|
|
32
|
+
chart: ChartConfig;
|
|
33
|
+
onRegenerate?: (chart: ChartConfig) => Promise<void>;
|
|
34
|
+
/** Additional CSS class for the chart container */
|
|
35
|
+
className?: string;
|
|
36
|
+
/** When true, removes all built-in Tailwind classes from toolbar and metadata tags */
|
|
37
|
+
unstyled?: boolean;
|
|
38
|
+
}
|
|
39
|
+
declare function SingleChart({ data, chart, onRegenerate, className, unstyled }: SingleChartProps): react_jsx_runtime.JSX.Element;
|
|
40
|
+
|
|
41
|
+
interface ChartToolbarProps {
|
|
42
|
+
chartType: ChartType;
|
|
43
|
+
sortOrder: SortOrder;
|
|
44
|
+
limitResults: number;
|
|
45
|
+
showBrush: boolean;
|
|
46
|
+
showTrendline: boolean;
|
|
47
|
+
isRegenerating: boolean;
|
|
48
|
+
hasRegenerate: boolean;
|
|
49
|
+
onToggleSort: () => void;
|
|
50
|
+
onLimitChange: (limit: number) => void;
|
|
51
|
+
onToggleBrush: () => void;
|
|
52
|
+
onToggleTrendline: () => void;
|
|
53
|
+
onExportCSV: () => void;
|
|
54
|
+
onExportPNG: () => void;
|
|
55
|
+
onRegenerate: () => void;
|
|
56
|
+
/** Additional CSS class for the toolbar container */
|
|
57
|
+
className?: string;
|
|
58
|
+
/** When true, removes all built-in Tailwind classes */
|
|
59
|
+
unstyled?: boolean;
|
|
60
|
+
}
|
|
61
|
+
declare function ChartToolbar({ chartType, sortOrder, limitResults, showBrush, showTrendline, isRegenerating, hasRegenerate, onToggleSort, onLimitChange, onToggleBrush, onToggleTrendline, onExportCSV, onExportPNG, onRegenerate, className, unstyled, }: ChartToolbarProps): react_jsx_runtime.JSX.Element;
|
|
62
|
+
|
|
63
|
+
declare function ChartThemeProvider({ theme, children, }: {
|
|
64
|
+
theme: ChartTheme;
|
|
65
|
+
children: React.ReactNode;
|
|
66
|
+
}): react_jsx_runtime.JSX.Element;
|
|
67
|
+
declare function useChartTheme(): ChartTheme;
|
|
68
|
+
|
|
69
|
+
export { ChartConfig, ChartDisplay, type ChartDisplayProps, ChartTheme, ChartThemeProvider, ChartToolbar, ChartType, SingleChart, type SingleChartProps, SortOrder, TabularData, useChartTheme };
|