@toon-format/toon
Advanced tools
+17
-55
@@ -59,16 +59,2 @@ //#region src/constants.d.ts | ||
| /** | ||
| * Enable key folding to collapse single-key wrapper chains. | ||
| * When set to 'safe', nested objects with single keys are collapsed into dotted paths | ||
| * (e.g., data.metadata.items instead of nested indentation). | ||
| * @default 'off' | ||
| */ | ||
| keyFolding?: "off" | "safe"; | ||
| /** | ||
| * Maximum number of segments to fold when keyFolding is enabled. | ||
| * Controls how deep the folding can go in single-key chains. | ||
| * Values 0 or 1 have no practical effect (treated as effectively disabled). | ||
| * @default Infinity | ||
| */ | ||
| flattenDepth?: number; | ||
| /** | ||
| * A function to transform or filter values during encoding. | ||
@@ -93,10 +79,2 @@ * Called for the root value and every nested property/element. | ||
| strict?: boolean; | ||
| /** | ||
| * Enable path expansion to reconstruct dotted keys into nested objects. | ||
| * When set to 'safe', keys containing dots are expanded into nested structures | ||
| * if all segments are valid identifiers (e.g., data.metadata.items becomes nested objects). | ||
| * Pairs with keyFolding='safe' for lossless round-trips. | ||
| * @default 'off' | ||
| */ | ||
| expandPaths?: "off" | "safe"; | ||
| } | ||
@@ -106,13 +84,4 @@ type ResolvedDecodeOptions = Readonly<Required<DecodeOptions>>; | ||
| * Options for streaming decode operations. | ||
| * | ||
| * @remarks | ||
| * Path expansion is not supported in streaming mode. | ||
| */ | ||
| interface DecodeStreamOptions extends Omit<DecodeOptions, "expandPaths"> { | ||
| /** | ||
| * Path expansion is not supported in streaming decode. | ||
| * This option is explicitly omitted. | ||
| */ | ||
| expandPaths?: never; | ||
| } | ||
| type DecodeStreamOptions = DecodeOptions; | ||
| type JsonStreamEvent = { | ||
@@ -130,3 +99,2 @@ type: "startObject"; | ||
| key: string; | ||
| wasQuoted?: boolean; | ||
| } | { | ||
@@ -166,4 +134,4 @@ type: "primitive"; | ||
| * ```ts | ||
| * encode({ name: 'Alice', age: 30 }) | ||
| * // name: Alice | ||
| * encode({ name: 'Ada', age: 30 }) | ||
| * // name: Ada | ||
| * // age: 30 | ||
@@ -179,3 +147,3 @@ * | ||
| * | ||
| * encode(data, { indent: 4, keyFolding: 'safe' }) | ||
| * encode(data, { indent: 4 }) | ||
| * ``` | ||
@@ -193,4 +161,4 @@ */ | ||
| * ```ts | ||
| * decode('name: Alice\nage: 30') | ||
| * // { name: 'Alice', age: 30 } | ||
| * decode('name: Ada\nage: 30') | ||
| * // { name: 'Ada', age: 30 } | ||
| * | ||
@@ -203,3 +171,3 @@ * decode('users[2]:\n - id: 1\n - id: 2') | ||
| * | ||
| * decode(toonString, { strict: false, expandPaths: 'safe' }) | ||
| * decode(toonString, { strict: false }) | ||
| * ``` | ||
@@ -221,3 +189,3 @@ */ | ||
| * // Stream to stdout | ||
| * for (const line of encodeLines({ name: 'Alice', age: 30 })) { | ||
| * for (const line of encodeLines({ name: 'Ada', age: 30 })) { | ||
| * console.log(line) | ||
@@ -239,6 +207,6 @@ * } | ||
| * the full value in memory. Useful when you already have lines as an array | ||
| * or iterable and want the standard decode behavior with path expansion support. | ||
| * or iterable and want the standard decode behavior. | ||
| * | ||
| * @param lines - Iterable of TOON lines (without newlines) | ||
| * @param options - Optional decoding configuration (supports expandPaths) | ||
| * @param options - Optional decoding configuration | ||
| * @returns Parsed JavaScript value (object, array, or primitive) | ||
@@ -248,5 +216,5 @@ * | ||
| * ```ts | ||
| * const lines = ['name: Alice', 'age: 30'] | ||
| * const lines = ['name: Ada', 'age: 30'] | ||
| * decodeFromLines(lines) | ||
| * // { name: 'Alice', age: 30 } | ||
| * // { name: 'Ada', age: 30 } | ||
| * ``` | ||
@@ -262,7 +230,4 @@ */ | ||
| * | ||
| * @remarks | ||
| * Path expansion (`expandPaths: 'safe'`) is not supported in streaming mode. | ||
| * | ||
| * @param lines - Iterable of TOON lines (without newlines) | ||
| * @param options - Optional decoding configuration (expandPaths not supported) | ||
| * @param options - Optional decoding configuration | ||
| * @returns Iterable of JSON stream events | ||
@@ -272,3 +237,3 @@ * | ||
| * ```ts | ||
| * const lines = ['name: Alice', 'age: 30'] | ||
| * const lines = ['name: Ada', 'age: 30'] | ||
| * for (const event of decodeStreamSync(lines)) { | ||
@@ -278,3 +243,3 @@ * console.log(event) | ||
| * // { type: 'key', key: 'name' } | ||
| * // { type: 'primitive', value: 'Alice' } | ||
| * // { type: 'primitive', value: 'Ada' } | ||
| * // ... | ||
@@ -293,7 +258,4 @@ * } | ||
| * | ||
| * @remarks | ||
| * Path expansion (`expandPaths: 'safe'`) is not supported in streaming mode. | ||
| * | ||
| * @param source - Async or sync iterable of TOON lines (without newlines) | ||
| * @param options - Optional decoding configuration (expandPaths not supported) | ||
| * @param options - Optional decoding configuration | ||
| * @returns Async iterable of JSON stream events | ||
@@ -310,3 +272,3 @@ * | ||
| * // { type: 'key', key: 'name' } | ||
| * // { type: 'primitive', value: 'Alice' } | ||
| * // { type: 'primitive', value: 'Ada' } | ||
| * // ... | ||
@@ -313,0 +275,0 @@ * } |
+2
-2
| { | ||
| "name": "@toon-format/toon", | ||
| "type": "module", | ||
| "version": "2.3.1", | ||
| "version": "4.0.0", | ||
| "description": "Token-Oriented Object Notation (TOON) – Compact, human-readable, schema-aware encoding of JSON for LLM prompts", | ||
@@ -36,3 +36,3 @@ "author": "Johann Schopplich <hello@johannschopplich.com>", | ||
| "devDependencies": { | ||
| "@toon-format/spec": "^3.3.0" | ||
| "@toon-format/spec": "^4.0.0" | ||
| }, | ||
@@ -39,0 +39,0 @@ "scripts": { |
+5
-5
@@ -7,3 +7,3 @@  | ||
| [](https://www.npmjs.com/package/@toon-format/toon) | ||
| [](https://github.com/toon-format/spec) | ||
| [](https://github.com/toon-format/spec) | ||
| [](https://www.npmjs.com/package/@toon-format/toon) | ||
@@ -762,3 +762,3 @@ [](./LICENSE) | ||
| users: [ | ||
| { id: 1, name: 'Alice', role: 'admin' }, | ||
| { id: 1, name: 'Ada', role: 'admin' }, | ||
| { id: 2, name: 'Bob', role: 'user' } | ||
@@ -770,3 +770,3 @@ ] | ||
| // users[2]{id,name,role}: | ||
| // 1,Alice,admin | ||
| // 1,Ada,admin | ||
| // 2,Bob,user | ||
@@ -797,7 +797,7 @@ ``` | ||
| // Remove sensitive fields | ||
| const user = { name: 'Alice', password: 'secret', email: 'alice@example.com' } | ||
| const user = { name: 'Ada', password: 'secret', email: 'ada@example.com' } | ||
| const safe = encode(user, { | ||
| replacer: (key, value) => key === 'password' ? undefined : value | ||
| }) | ||
| // name: Alice | ||
| // name: Ada | ||
| // email: alice@example.com | ||
@@ -804,0 +804,0 @@ |
Sorry, the diff of this file is too big to display
123915
1.08%2168
4.94%