diff --git a/README.md b/README.md index 4a8b4d3..c3fe809 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ users[2]{id,name,role}: ## Key Features - ๐Ÿ’ธ **Token-efficient:** typically 30โ€“60% fewer tokens than JSON -- ๐Ÿคฟ **LLM-friendly guardrails:** explicit lengths and field lists help models validate output +- ๐Ÿคฟ **LLM-friendly guardrails:** explicit lengths and fields enable validation - ๐Ÿฑ **Minimal syntax:** removes redundant punctuation (braces, brackets, most quotes) -- ๐Ÿ“ **Indentation-based structure:** replaces braces with whitespace for better readability -- ๐Ÿงบ **Tabular arrays:** declare keys once, then stream rows without repetition +- ๐Ÿ“ **Indentation-based structure:** like YAML, uses whitespace instead of braces +- ๐Ÿงบ **Tabular arrays:** declare keys once, stream data as rows ## Benchmarks diff --git a/cli/src/index.ts b/cli/src/index.ts index b33a6f3..4c76857 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -1,15 +1,15 @@ -import type { DecodeOptions, EncodeOptions } from '../../src' +import type { DecodeOptions, Delimiter, EncodeOptions } from '../../src' import * as fsp from 'node:fs/promises' import * as path from 'node:path' import process from 'node:process' import { defineCommand, runMain } from 'citty' import { consola } from 'consola' -import { version } from '../../package.json' with { type: 'json' } -import { decode, DELIMITERS, encode } from '../../src' +import { name, version } from '../../package.json' with { type: 'json' } +import { decode, DEFAULT_DELIMITER, DELIMITERS, encode } from '../../src' const main = defineCommand({ meta: { - name: 'toon', + name, description: 'TOON CLI โ€” Convert between JSON and TOON formats', version, }, @@ -71,8 +71,8 @@ const main = defineCommand({ } // Validate delimiter - const delimiter = args.delimiter || ',' - if (!Object.values(DELIMITERS).includes(delimiter as any)) { + const delimiter = args.delimiter || DEFAULT_DELIMITER + if (!(Object.values(DELIMITERS)).includes(delimiter as Delimiter)) { throw new Error(`Invalid delimiter "${delimiter}". Valid delimiters are: comma (,), tab (\\t), pipe (|)`) } @@ -83,7 +83,7 @@ const main = defineCommand({ await encodeToToon({ input: inputPath, output: outputPath, - delimiter: delimiter as ',' | '\t' | '|', + delimiter: delimiter as Delimiter, indent, lengthMarker: args.lengthMarker === true ? '#' : false, }) @@ -128,9 +128,9 @@ function detectMode( async function encodeToToon(config: { input: string output?: string - delimiter: ',' | '\t' | '|' + delimiter: Delimiter indent: number - lengthMarker: '#' | false + lengthMarker: NonNullable }) { const jsonContent = await fsp.readFile(config.input, 'utf-8')