json-toon-parser 1.1.1 β†’ 1.1.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [1.1.0] - 2025-11-22
6
+
7
+ ### Added
8
+ - 🌐 **Web UI Server** - Beautiful browser-based interface for JSON to TOON conversion
9
+ - ⚑ **`serve` Command** - Start a local web server with `json-toon serve`
10
+ - πŸ“Š **Real-time Conversion** - Instant token analysis and optimization in the browser
11
+ - πŸ’Ύ **Download Feature** - Download converted TOON files directly from the UI
12
+ - 🎨 **Sample Data** - Pre-loaded examples (Simple, Array, Nested, Complex)
13
+ - πŸ“‹ **Copy/Paste** - Easy copy buttons for JSON and TOON output
14
+ - ✨ **JSON Formatter** - Auto-format messy JSON with one click
15
+ - πŸ“± **Responsive Design** - Works on desktop, tablet, and mobile devices
16
+
17
+ ### Changed
18
+ - Updated CLI with new `serve` command
19
+ - Enhanced README with Web UI documentation
20
+ - Updated package description
21
+ - Added `public/` directory to published files
22
+ - Improved server output with beautiful ASCII art banner
23
+
24
+ ### Technical
25
+ - Added `server.ts` for HTTP server functionality
26
+ - Created standalone `public/index.html` with embedded TOON library
27
+ - Updated TypeScript build configuration
28
+ - Added new npm scripts: `serve` and `dev`
29
+
30
+ ## [1.0.1] - Previous Release
31
+
32
+ ### Features
33
+ - CLI tool for JSON to TOON conversion
34
+ - Compare, convert, and update commands
35
+ - Token efficiency analysis
36
+ - Programmatic API support
package/README.md CHANGED
@@ -1,18 +1,25 @@
1
1
  # json-toon-parser
2
2
 
3
- πŸš€ Compare and convert JSON to TOON format with token efficiency analysis.
3
+ **Version:** 1.1.2 β€’ **License:** MIT β€’ **Format:** TOON
4
+
5
+ High-efficiency conversion and analysis toolkit: JSON β†’ TOON with CLI, API, and Web UI server for real‑time token savings. Ideal for reducing LLM prompt payload size and optimizing costs.
4
6
 
5
7
  ## Installation
8
+ Global (CLI + Web UI):
6
9
  ```bash
7
10
  npm install -g json-toon-parser
8
11
  ```
12
+ Project (Programmatic API):
13
+ ```bash
14
+ npm install json-toon-parser
15
+ ```
9
16
 
10
- ## Quick Start - Web UI
11
- After installation, start the web server:
17
+ ## Quick Start – Web UI
18
+ Start the local server:
12
19
  ```bash
13
20
  json-toon serve
14
21
  ```
15
- Then open your browser to `http://localhost:3000` and start converting JSON to TOON with a beautiful interface!
22
+ Browse to: `http://localhost:3000` β†’ paste JSON β†’ convert β†’ copy/download TOON.
16
23
 
17
24
  ## CLI Usage
18
25
  ```bash
@@ -50,16 +57,18 @@ const toonString = jsonToToon({ hello: "world" });
50
57
 
51
58
  ## Features
52
59
 
53
- - 🌐 **Web UI** - Beautiful web interface for easy conversion
54
- - βœ… Convert JSON to TOON format
55
- - πŸ“Š Compare token efficiency between formats
56
- - πŸ’Ύ Auto-save TOON files with timestamps
57
- - πŸ”§ CLI tool for easy usage
58
- - πŸ“¦ Programmatic API for Node.js
59
- - 🎯 TypeScript support with full type definitions
60
- - ⚑ Real-time conversion with live stats
60
+ - 🌐 Web UI – Responsive, modern conversion dashboard
61
+ - βœ… Direct JSON β†’ TOON conversion (string or file)
62
+ - πŸ“Š Token efficiency metrics (JSON vs TOON counts, savings %)
63
+ - πŸ’Ύ Timestamped output file generation
64
+ - πŸ”§ CLI commands: `serve`, `compare`, `convert`, `update`
65
+ - πŸ“¦ Programmatic API with types & tree-shakeable exports
66
+ - ⚑ Real-time stats + sample datasets in UI
67
+ - πŸ§ͺ GPT-style token counting via `gpt-3-encoder`
61
68
 
62
- ## API
69
+ ## API (Summary)
70
+
71
+ Full reference: see `docs/API.md`.
63
72
 
64
73
  ### `compare(jsonData, options?)`
65
74
  Compare JSON data with TOON format and calculate token efficiency.
@@ -89,7 +98,7 @@ Update JSON file and generate TOON comparison.
89
98
  ### `formatResult(result)`
90
99
  Format comparison result for display.
91
100
 
92
- ## Example Output
101
+ ## Example CLI Output
93
102
  ```
94
103
  ============================================================
95
104
  COMPARISON RESULTS
@@ -104,15 +113,21 @@ Output File: output/data_DateTime.toon
104
113
 
105
114
  ## Use Cases
106
115
 
107
- - πŸ” **Token Analysis**: Compare token efficiency between formats
108
- - πŸ’Ύ **Data Compression**: Convert JSON to more efficient TOON format
109
- - πŸ“Š **Batch Processing**: Process multiple JSON files
110
- - πŸ› οΈ **CI/CD Integration**: Automate format conversion
111
- - πŸ“ˆ **Cost Optimization**: Reduce API token usage for LLMs
116
+ - πŸ” Token Analysis – Quantify savings before sending payloads
117
+ - πŸ’Ύ Payload Compression – Minimize size for storage or transfer
118
+ - πŸ“Š Batch Conversion – Automate directory/file transformations
119
+ - πŸ› οΈ CI Integration – Enforce efficiency gates in pipelines
120
+ - πŸ“ˆ LLM Cost Reduction – Lower prompt token usage dramatically
112
121
 
113
122
  ## Requirements
114
123
 
115
- - Node.js >= 18.0.0
124
+ - Node.js β‰₯ 18.0.0
125
+
126
+ ## Contributing & Support
127
+
128
+ Issues / feature requests: https://github.com/bhushan44/json-toon-parser/issues
129
+ API Reference: `docs/API.md`
130
+ Quick Start Guide: `QUICKSTART.md`
116
131
 
117
132
  ## License
118
133
 
package/dist/cli.js CHANGED
@@ -7,10 +7,20 @@ import path from "node:path";
7
7
  const __filename = fileURLToPath(import.meta.url);
8
8
  const __dirname = path.dirname(__filename);
9
9
  const program = new Command();
10
+ // Dynamically derive version from package.json to avoid manual sync issues.
11
+ import { createRequire } from "node:module";
12
+ const require = createRequire(import.meta.url);
13
+ let pkgVersion = "0.0.0";
14
+ try {
15
+ const pkg = require("../package.json");
16
+ pkgVersion = pkg.version || pkgVersion;
17
+ }
18
+ catch {
19
+ }
10
20
  program
11
21
  .name("json-toon")
12
22
  .description("Compare and convert JSON to TOON format")
13
- .version("1.0.1");
23
+ .version(pkgVersion);
14
24
  program
15
25
  .command("compare")
16
26
  .description("Compare JSON file with TOON format")
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1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,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
package/docs/API.md ADDED
@@ -0,0 +1,185 @@
1
+ # json-toon-parser API Documentation
2
+
3
+ Version: 1.1.2
4
+
5
+ The `json-toon-parser` package provides utilities to convert JSON data into the TOON format and analyze token efficiency. It exposes a CLI, programmatic API, and a Web UI server.
6
+
7
+ ## Table of Contents
8
+ - Core Concepts
9
+ - Installation
10
+ - CLI Usage
11
+ - Web UI Server
12
+ - Programmatic API
13
+ - compare
14
+ - compareFile
15
+ - jsonToToon
16
+ - convertFile
17
+ - updateJsonFile
18
+ - formatResult
19
+ - Types
20
+ - Error Handling
21
+ - Performance Notes
22
+ - Examples
23
+
24
+ ---
25
+ ## Core Concepts
26
+ TOON is a compact serialization format aimed at reducing token counts when sending structured data to LLMs. This library allows:
27
+ - Measuring token savings between pretty JSON and TOON.
28
+ - Converting individual JSON objects or whole files.
29
+ - Serving a browser-based interface for interactive conversion.
30
+
31
+ ## Installation
32
+ ```bash
33
+ npm install -g json-toon-parser
34
+ # or locally
35
+ npm install json-toon-parser
36
+ ```
37
+
38
+ ## CLI Usage
39
+ ```bash
40
+ # Start Web UI on default port 3000
41
+ json-toon serve
42
+ # Custom port
43
+ json-toon serve --port 8080
44
+
45
+ # Compare a JSON file and save TOON output
46
+ json-toon compare data.json --save
47
+
48
+ # Convert JSON file directly
49
+ json-toon convert data.json output.toon
50
+
51
+ # Update JSON file and output comparison stats
52
+ json-toon update data.json
53
+ ```
54
+
55
+ ## Web UI Server
56
+ The `serve` command launches a lightweight HTTP server that serves `public/index.html` and provides a POST `/api/convert` endpoint.
57
+ - Interactive editor for JSON input and TOON output.
58
+ - Shows token metrics: JSON tokens, TOON tokens, savings, efficiency percentage.
59
+ - Provides sample datasets, formatting, copy, and download capabilities.
60
+
61
+ ## Programmatic API
62
+ Import functions from the root export:
63
+ ```ts
64
+ import { compare, compareFile, jsonToToon, convertFile, updateJsonFile, formatResult } from 'json-to-toon-parser';
65
+ ```
66
+
67
+ ### compare(jsonData, options?)
68
+ Compares raw JSON-serializable data to its TOON representation.
69
+
70
+ Parameters:
71
+ - `jsonData: unknown` – Any serializable data.
72
+ - `options?: CompareOptions`
73
+ - `outputDir?: string` (default `output`) – Directory for saved TOON file.
74
+ - `saveToFile?: boolean` (default `false`) – Whether to write TOON to disk.
75
+ - `prettyJson?: boolean` (default `true`) – Whether to pretty-print JSON when counting tokens.
76
+ - `fileName?: string` – Custom base file name.
77
+
78
+ Returns `ComparisonResult`:
79
+ - `jsonTokens: number`
80
+ - `toonTokens: number`
81
+ - `savings: number`
82
+ - `savingsPercentage: number`
83
+ - `toonOutput: string`
84
+ - `toonOutputPath?: string`
85
+
86
+ Usage:
87
+ ```ts
88
+ const res = compare({ user: 'alice', roles: ['admin','editor'] }, { saveToFile: true });
89
+ console.log(res.savingsPercentage);
90
+ ```
91
+
92
+ ### compareFile(filePath, options?)
93
+ Loads JSON from a file, performs comparison, and always saves TOON output.
94
+
95
+ ```ts
96
+ const res = compareFile('data/input.json', { outputDir: 'out' });
97
+ ```
98
+ Throws if the file does not exist or contains invalid JSON.
99
+
100
+ ### jsonToToon(jsonData)
101
+ Returns only the TOON string.
102
+ ```ts
103
+ const toon = jsonToToon({ a: 1, b: 2 });
104
+ ```
105
+
106
+ ### convertFile(inputPath, outputPath?)
107
+ Converts a JSON file to TOON and writes the result. Generates a timestamped path when `outputPath` is omitted.
108
+ ```ts
109
+ const outPath = convertFile('data/input.json');
110
+ ```
111
+
112
+ ### updateJsonFile(filePath, outputPath?)
113
+ Runs comparison on the existing JSON file and then rewrites (or copies) the JSON file (not mutated contentβ€”kept formatted). Returns `ComparisonResult & { updatedJsonPath: string }`.
114
+ ```ts
115
+ const updated = updateJsonFile('data/input.json');
116
+ ```
117
+
118
+ ### formatResult(result)
119
+ Formats a `ComparisonResult` into a readable multiline string for terminal output.
120
+ ```ts
121
+ console.log(formatResult(res));
122
+ ```
123
+
124
+ ## Types
125
+ ```ts
126
+ interface ComparisonResult {
127
+ jsonTokens: number;
128
+ toonTokens: number;
129
+ savings: number;
130
+ savingsPercentage: number;
131
+ toonOutput: string;
132
+ toonOutputPath?: string;
133
+ }
134
+
135
+ interface CompareOptions {
136
+ outputDir?: string;
137
+ saveToFile?: boolean;
138
+ prettyJson?: boolean;
139
+ fileName?: string;
140
+ }
141
+ ```
142
+
143
+ ## Error Handling
144
+ - File operations throw when paths are invalid.
145
+ - JSON parsing errors surface with native `SyntaxError` messages.
146
+ - Always wrap CLI or programmatic calls in try/catch for robustness.
147
+
148
+ ## Performance Notes
149
+ - Token counting uses `gpt-3-encoder` for approximate GPT token metrics.
150
+ - Pretty-printing JSON increases token count slightly; disable with `{ prettyJson: false }` for raw comparison.
151
+ - TOON encoding efficiency improves with deeply nested or repetitive structures.
152
+
153
+ ## Examples
154
+ ```ts
155
+ import { compareFile } from 'json-to-toon-parser';
156
+ const result = compareFile('data/big.json', { outputDir: 'analysis' });
157
+ console.log(`Saved ${result.savings} tokens (${result.savingsPercentage.toFixed(2)}%)`);
158
+ ```
159
+
160
+ ```ts
161
+ import { jsonToToon } from 'json-to-toon-parser';
162
+ const payload = { items: Array.from({ length: 50 }, (_, i) => ({ id: i, flag: i % 2 === 0 })) };
163
+ const toon = jsonToToon(payload);
164
+ // Send toon to LLM or store compactly
165
+ ```
166
+
167
+ ## Decoding (If Needed)
168
+ If you need to restore JSON later, use the underlying TOON library directly:
169
+ ```ts
170
+ import { decode } from '@toon-format/toon';
171
+ const original = decode(toonString);
172
+ ```
173
+
174
+ ## Versioning Policy
175
+ - Patch: Internal fixes / metadata.
176
+ - Minor: New features (e.g., Web UI server added in 1.1.x).
177
+ - Major: Breaking API or CLI changes.
178
+
179
+ ## Contributing
180
+ 1. Fork & branch (`feat/my-feature`).
181
+ 2. Run `npm run build` before submitting PRs.
182
+ 3. Add tests/examples where relevant.
183
+
184
+ ## License
185
+ MIT Β© Bhushan Chaudhari
package/package.json CHANGED
@@ -1,9 +1,18 @@
1
1
  {
2
2
  "name": "json-toon-parser",
3
- "version": "1.1.1",
4
- "description": "Compare and convert JSON to TOON format with token efficiency analysis - Now with Web UI!",
3
+ "version": "1.1.2",
4
+ "description": "Compare and convert JSON to TOON format with token efficiency analysis – includes CLI, API, and Web UI server.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "./server": {
13
+ "import": "./dist/server.js"
14
+ }
15
+ },
7
16
  "bin": {
8
17
  "json-toon": "./dist/cli.js"
9
18
  },
@@ -20,8 +29,18 @@
20
29
  "dist",
21
30
  "public",
22
31
  "README.md",
23
- "LICENSE"
32
+ "LICENSE",
33
+ "CHANGELOG.md",
34
+ "docs"
24
35
  ],
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/bhushan44/json-toon-parser.git"
39
+ },
40
+ "homepage": "https://github.com/bhushan44/json-toon-parser#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/bhushan44/json-toon-parser/issues"
43
+ },
25
44
  "keywords": [
26
45
  "json",
27
46
  "toon",
@@ -32,16 +51,16 @@
32
51
  "compression",
33
52
  "format",
34
53
  "efficiency",
35
- "token-optimization"
54
+ "token-optimization",
55
+ "webui",
56
+ "cli"
36
57
  ],
37
58
  "author": "Bhushan Chaudhari <bhushanschaudhari4@gmail.com>",
38
59
  "license": "MIT",
39
60
  "dependencies": {
40
61
  "@toon-format/toon": "^1.0.0",
41
- "1.0.1": "^1.0.0",
42
62
  "commander": "^12.0.0",
43
- "gpt-3-encoder": "^1.1.4",
44
- "json-toon-parser": "^1.0.1"
63
+ "gpt-3-encoder": "^1.1.4"
45
64
  },
46
65
  "devDependencies": {
47
66
  "@types/node": "^20.0.0",