@chartts/json 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/README.md +79 -0
  2. package/package.json +5 -4
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ <p align="center">
2
+ <a href="https://www.npmjs.com/package/@chartts/json"><img src="https://img.shields.io/npm/v/@chartts/json?color=06B6D4&label=npm" alt="npm version" /></a>
3
+ <a href="https://github.com/chartts/chartts/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-06B6D4" alt="MIT License" /></a>
4
+ <a href="https://chartts.com"><img src="https://img.shields.io/badge/docs-chartts.com-06B6D4" alt="Documentation" /></a>
5
+ </p>
6
+
7
+ # @chartts/json
8
+
9
+ JSON adapter for Chartts. Convert between JSON and chart data.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @chartts/json @chartts/core
15
+ ```
16
+
17
+ Zero dependencies.
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { fromJSON, toJSON } from "@chartts/json"
23
+
24
+ // Array of objects
25
+ const data = fromJSON([
26
+ { month: "Jan", sales: 4200, costs: 3100 },
27
+ { month: "Feb", sales: 5800, costs: 3900 },
28
+ { month: "Mar", sales: 7100, costs: 4200 },
29
+ ])
30
+
31
+ // Columnar format
32
+ const data2 = fromJSON({
33
+ labels: ["Jan", "Feb", "Mar"],
34
+ sales: [4200, 5800, 7100],
35
+ costs: [3100, 3900, 4200],
36
+ })
37
+
38
+ // ChartData passthrough (already valid)
39
+ const data3 = fromJSON({ labels: [...], series: [...] })
40
+
41
+ // Export
42
+ const rows = toJSON(chart.data) // array of objects
43
+ const cols = toJSON(chart.data, { format: "columnar" })
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `fromJSON(input, options?)`
49
+
50
+ Parses JSON into `ChartData`. Accepts a string or object. Auto-detects three shapes:
51
+
52
+ - **Array of objects** — `[{month: "Jan", sales: 10}, ...]`
53
+ - **Columnar** — `{labels: [...], sales: [...], costs: [...]}`
54
+ - **ChartData** — passed through as-is
55
+
56
+ | Option | Type | Default | Description |
57
+ |--------|------|---------|-------------|
58
+ | `labelKey` | `string` | auto-detect | Key to use as labels |
59
+ | `seriesKeys` | `string[]` | all numeric keys | Keys to use as series |
60
+
61
+ ### `toJSON(data, options?)`
62
+
63
+ Converts `ChartData` to JSON.
64
+
65
+ | Option | Type | Default | Description |
66
+ |--------|------|---------|-------------|
67
+ | `format` | `"rows" \| "columnar"` | `"rows"` | Output shape |
68
+
69
+ ## Part of Chartts
70
+
71
+ Beautiful charts. Tiny bundle. Every framework.
72
+
73
+ - [Documentation](https://chartts.com/docs)
74
+ - [GitHub](https://github.com/chartts/chartts)
75
+ - [All packages](https://www.npmjs.com/org/chartts)
76
+
77
+ ## License
78
+
79
+ MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chartts/json",
3
- "version": "0.1.3",
4
- "description": "JSON import and export for Chartts",
3
+ "version": "0.1.4",
4
+ "description": "JSON adapter for Chartts. Convert between JSON and chart data.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -14,11 +14,12 @@
14
14
  }
15
15
  },
16
16
  "files": [
17
- "dist"
17
+ "dist",
18
+ "README.md"
18
19
  ],
19
20
  "sideEffects": false,
20
21
  "peerDependencies": {
21
- "@chartts/core": "0.1.3"
22
+ "@chartts/core": "0.1.4"
22
23
  },
23
24
  "license": "MIT",
24
25
  "repository": {