toon-to-json
v0.1.1
Published
A package to convert from TOON to JSON
Readme
toon-to-json
Convert TOON to JSON, from the command line or from TypeScript/JavaScript.
CLI
toon-to-json -i input.toon # file → stdout (pretty, colored on a terminal)
toon-to-json -i input.toon -o output.json # file → file
cat input.toon | toon-to-json # stdin → stdout
toon-to-json < input.toon # redirected stdin → stdout
toon-to-json -t 'tags[2]: a,b' # inline TOON → stdout
toon-to-json # paste TOON, then press Ctrl+D
toon-to-json -i input.toon --copy # also copy the JSON to the clipboard| Option | Description |
| --- | --- |
| -i, --input <file> | Read TOON from a file (- reads stdin) |
| -t, --text <toon> | Convert TOON given directly as an argument |
| -o, --output <file> | Write the JSON to a file instead of stdout |
| -c, --copy | Also copy the JSON to the clipboard |
| --indent <n> | Spaces per indentation level (0-10), or tab. Default: 2 |
| --compact | Print JSON on a single line (same as --indent 0) |
| --no-color | Disable syntax highlighting (NO_COLOR is honored too) |
| -v, --version | Print the version number |
| -h, --help | Show help |
Library
import { parseToon, toonToJson, ToonParser } from "toon-to-json";
parseToon("tags[2]: a,b"); // { tags: ["a", "b"] }
toonToJson("name: Ada"); // '{\n "name": "Ada"\n}'
toonToJson("name: Ada", { indent: 0 }); // '{"name":"Ada"}'
new ToonParser().convert("name: Ada"); // { name: "Ada" }Both functions throw an Error with the line number when the input is malformed.
