diff --git a/README.md b/README.md index a93208c..b862d27 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ AI is becoming cheaper and more accessible, but larger context windows allow for | 🏷️ User with tags | 48 | 28 | 20 | **41.7%** | | 📦 Small product catalog | 117 | 49 | 68 | **58.1%** | | 👥 API response with users | 123 | 53 | 70 | **56.9%** | -| ⚙️ Nested configuration | 67 | 41 | 26 | **38.8%** | +| ⚙️ Nested configuration | 68 | 42 | 26 | **38.2%** | | 🛒 E-commerce order | 163 | 94 | 69 | **42.3%** | | 📊 Analytics data | 209 | 94 | 115 | **55.0%** | | 📈 Large dataset (50 records) | 2159 | 762 | 1397 | **64.7%** | -| **Total** | **2917** | **1139** | **1778** | **61.0%** | +| **Total** | **2918** | **1140** | **1778** | **60.9%** |
View detailed results @@ -233,7 +233,7 @@ const data = { user: { id: 123, name: 'Ada', - tags: ['admin', 'ops'], + tags: ['reading', 'gaming'], active: true, preferences: [] } @@ -248,7 +248,7 @@ Output: user: id: 123 name: Ada - tags[2]: admin,ops + tags[2]: reading,gaming active: true preferences[0]: ``` @@ -465,7 +465,7 @@ String values are quoted when any of the following is true: ``` note: "hello, world" -items[3]: x,"true","- item" +items[3]: foo,"true","- item" hello 👋 world // unquoted " padded " // quoted value: null // null value @@ -614,7 +614,7 @@ The `lengthMarker` option adds an optional hash (`#`) prefix to array lengths to import { encode } from '@byjohann/toon' const data = { - tags: ['admin', 'ops', 'dev'], + tags: ['reading', 'gaming', 'coding'], items: [ { sku: 'A1', qty: 2, price: 9.99 }, { sku: 'B2', qty: 1, price: 14.5 }, @@ -622,14 +622,14 @@ const data = { } console.log(encode(data, { lengthMarker: '#' })) -// tags[#3]: admin,ops,dev +// tags[#3]: reading,gaming,coding // items[#2]{sku,qty,price}: // A1,2,9.99 // B2,1,14.5 // Works with custom delimiters console.log(encode(data, { lengthMarker: '#', delimiter: '|' })) -// tags[#3|]: admin|ops|dev +// tags[#3|]: reading|gaming|coding // items[#2|]{sku|qty|price}: // A1|2|9.99 // B2|1|14.5 @@ -669,7 +669,7 @@ When incorporating TOON into your LLM workflows: id: 1 // Primitive array (inline) -{ tags: ['a', 'b'] } → tags[2]: a,b +{ tags: ['foo', 'bar'] } → tags[2]: foo,bar // Tabular array (uniform objects) { items: [ → items[2]{id,qty}: diff --git a/docs/benchmarks.md b/docs/benchmarks.md index ad99f1a..146fbed 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -4,11 +4,11 @@ | 🏷️ User with tags | 48 | 28 | 20 | **41.7%** | | 📦 Small product catalog | 117 | 49 | 68 | **58.1%** | | 👥 API response with users | 123 | 53 | 70 | **56.9%** | -| ⚙️ Nested configuration | 67 | 41 | 26 | **38.8%** | +| ⚙️ Nested configuration | 68 | 42 | 26 | **38.2%** | | 🛒 E-commerce order | 163 | 94 | 69 | **42.3%** | | 📊 Analytics data | 209 | 94 | 115 | **55.0%** | | 📈 Large dataset (50 records) | 2159 | 762 | 1397 | **64.7%** | -| **Total** | **2917** | **1139** | **1778** | **61.0%** | +| **Total** | **2918** | **1140** | **1778** | **60.9%** |
View detailed results diff --git a/scripts/generate-bench.ts b/scripts/generate-bench.ts index e5dc26d..a4d8950 100644 --- a/scripts/generate-bench.ts +++ b/scripts/generate-bench.ts @@ -34,7 +34,7 @@ const BENCHMARK_EXAMPLES = [ user: { id: 123, name: 'Ada', - tags: ['admin', 'ops', 'developer'], + tags: ['reading', 'gaming', 'coding'], active: true, }, }, @@ -71,7 +71,7 @@ const BENCHMARK_EXAMPLES = [ host: 'localhost', port: 5432, credentials: { - username: 'admin', + username: 'dbuser', password: 'secret123', }, }, diff --git a/test/index.test.ts b/test/index.test.ts index 72ba02f..9ffaedf 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -156,8 +156,8 @@ describe('nested objects', () => { describe('arrays of primitives', () => { it('encodes string arrays inline', () => { - const obj = { tags: ['admin', 'ops'] } - expect(encode(obj)).toBe('tags[2]: admin,ops') + const obj = { tags: ['reading', 'gaming'] } + expect(encode(obj)).toBe('tags[2]: reading,gaming') }) it('encodes number arrays inline', () => { @@ -491,7 +491,7 @@ describe('complex structures', () => { user: { id: 123, name: 'Ada', - tags: ['admin', 'ops'], + tags: ['reading', 'gaming'], active: true, prefs: [], }, @@ -500,7 +500,7 @@ describe('complex structures', () => { 'user:\n' + ' id: 123\n' + ' name: Ada\n' - + ' tags[2]: admin,ops\n' + + ' tags[2]: reading,gaming\n' + ' active: true\n' + ' prefs[0]:', ) @@ -592,11 +592,11 @@ describe('non-JSON-serializable values', () => { describe('delimiter options', () => { describe('basic delimiter usage', () => { it.each([ - { delimiter: '\t' as const, name: 'tab', expected: 'admin\tops\tdev' }, - { delimiter: '|' as const, name: 'pipe', expected: 'admin|ops|dev' }, - { delimiter: ',' as const, name: 'comma', expected: 'admin,ops,dev' }, + { delimiter: '\t' as const, name: 'tab', expected: 'reading\tgaming\tcoding' }, + { delimiter: '|' as const, name: 'pipe', expected: 'reading|gaming|coding' }, + { delimiter: ',' as const, name: 'comma', expected: 'reading,gaming,coding' }, ])('encodes primitive arrays with $name', ({ delimiter, expected }) => { - const obj = { tags: ['admin', 'ops', 'dev'] } + const obj = { tags: ['reading', 'gaming', 'coding'] } expect(encode(obj, { delimiter })).toBe(`tags[3${delimiter !== ',' ? delimiter : ''}]: ${expected}`) }) @@ -734,8 +734,8 @@ describe('delimiter options', () => { describe('length marker option', () => { it('adds length marker to primitive arrays', () => { - const obj = { tags: ['admin', 'ops', 'dev'] } - expect(encode(obj, { lengthMarker: '#' })).toBe('tags[#3]: admin,ops,dev') + const obj = { tags: ['reading', 'gaming', 'coding'] } + expect(encode(obj, { lengthMarker: '#' })).toBe('tags[#3]: reading,gaming,coding') }) it('handles empty arrays', () => { @@ -758,12 +758,12 @@ describe('length marker option', () => { }) it('works with delimiter option', () => { - const obj = { tags: ['admin', 'ops', 'dev'] } - expect(encode(obj, { lengthMarker: '#', delimiter: '|' })).toBe('tags[#3|]: admin|ops|dev') + const obj = { tags: ['reading', 'gaming', 'coding'] } + expect(encode(obj, { lengthMarker: '#', delimiter: '|' })).toBe('tags[#3|]: reading|gaming|coding') }) it('default is false (no length marker)', () => { - const obj = { tags: ['admin', 'ops', 'dev'] } - expect(encode(obj)).toBe('tags[3]: admin,ops,dev') + const obj = { tags: ['reading', 'gaming', 'coding'] } + expect(encode(obj)).toBe('tags[3]: reading,gaming,coding') }) })