mirror of
https://github.com/voson-wang/toon.git
synced 2026-01-29 23:34:10 +08:00
test: update example values
This commit is contained in:
18
README.md
18
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%** |
|
| 🏷️ User with tags | 48 | 28 | 20 | **41.7%** |
|
||||||
| 📦 Small product catalog | 117 | 49 | 68 | **58.1%** |
|
| 📦 Small product catalog | 117 | 49 | 68 | **58.1%** |
|
||||||
| 👥 API response with users | 123 | 53 | 70 | **56.9%** |
|
| 👥 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%** |
|
| 🛒 E-commerce order | 163 | 94 | 69 | **42.3%** |
|
||||||
| 📊 Analytics data | 209 | 94 | 115 | **55.0%** |
|
| 📊 Analytics data | 209 | 94 | 115 | **55.0%** |
|
||||||
| 📈 Large dataset (50 records) | 2159 | 762 | 1397 | **64.7%** |
|
| 📈 Large dataset (50 records) | 2159 | 762 | 1397 | **64.7%** |
|
||||||
| **Total** | **2917** | **1139** | **1778** | **61.0%** |
|
| **Total** | **2918** | **1140** | **1778** | **60.9%** |
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary><strong>View detailed results</strong></summary>
|
<summary><strong>View detailed results</strong></summary>
|
||||||
@@ -233,7 +233,7 @@ const data = {
|
|||||||
user: {
|
user: {
|
||||||
id: 123,
|
id: 123,
|
||||||
name: 'Ada',
|
name: 'Ada',
|
||||||
tags: ['admin', 'ops'],
|
tags: ['reading', 'gaming'],
|
||||||
active: true,
|
active: true,
|
||||||
preferences: []
|
preferences: []
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ Output:
|
|||||||
user:
|
user:
|
||||||
id: 123
|
id: 123
|
||||||
name: Ada
|
name: Ada
|
||||||
tags[2]: admin,ops
|
tags[2]: reading,gaming
|
||||||
active: true
|
active: true
|
||||||
preferences[0]:
|
preferences[0]:
|
||||||
```
|
```
|
||||||
@@ -465,7 +465,7 @@ String values are quoted when any of the following is true:
|
|||||||
|
|
||||||
```
|
```
|
||||||
note: "hello, world"
|
note: "hello, world"
|
||||||
items[3]: x,"true","- item"
|
items[3]: foo,"true","- item"
|
||||||
hello 👋 world // unquoted
|
hello 👋 world // unquoted
|
||||||
" padded " // quoted
|
" padded " // quoted
|
||||||
value: null // null value
|
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'
|
import { encode } from '@byjohann/toon'
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
tags: ['admin', 'ops', 'dev'],
|
tags: ['reading', 'gaming', 'coding'],
|
||||||
items: [
|
items: [
|
||||||
{ sku: 'A1', qty: 2, price: 9.99 },
|
{ sku: 'A1', qty: 2, price: 9.99 },
|
||||||
{ sku: 'B2', qty: 1, price: 14.5 },
|
{ sku: 'B2', qty: 1, price: 14.5 },
|
||||||
@@ -622,14 +622,14 @@ const data = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(encode(data, { lengthMarker: '#' }))
|
console.log(encode(data, { lengthMarker: '#' }))
|
||||||
// tags[#3]: admin,ops,dev
|
// tags[#3]: reading,gaming,coding
|
||||||
// items[#2]{sku,qty,price}:
|
// items[#2]{sku,qty,price}:
|
||||||
// A1,2,9.99
|
// A1,2,9.99
|
||||||
// B2,1,14.5
|
// B2,1,14.5
|
||||||
|
|
||||||
// Works with custom delimiters
|
// Works with custom delimiters
|
||||||
console.log(encode(data, { lengthMarker: '#', delimiter: '|' }))
|
console.log(encode(data, { lengthMarker: '#', delimiter: '|' }))
|
||||||
// tags[#3|]: admin|ops|dev
|
// tags[#3|]: reading|gaming|coding
|
||||||
// items[#2|]{sku|qty|price}:
|
// items[#2|]{sku|qty|price}:
|
||||||
// A1|2|9.99
|
// A1|2|9.99
|
||||||
// B2|1|14.5
|
// B2|1|14.5
|
||||||
@@ -669,7 +669,7 @@ When incorporating TOON into your LLM workflows:
|
|||||||
id: 1
|
id: 1
|
||||||
|
|
||||||
// Primitive array (inline)
|
// Primitive array (inline)
|
||||||
{ tags: ['a', 'b'] } → tags[2]: a,b
|
{ tags: ['foo', 'bar'] } → tags[2]: foo,bar
|
||||||
|
|
||||||
// Tabular array (uniform objects)
|
// Tabular array (uniform objects)
|
||||||
{ items: [ → items[2]{id,qty}:
|
{ items: [ → items[2]{id,qty}:
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
| 🏷️ User with tags | 48 | 28 | 20 | **41.7%** |
|
| 🏷️ User with tags | 48 | 28 | 20 | **41.7%** |
|
||||||
| 📦 Small product catalog | 117 | 49 | 68 | **58.1%** |
|
| 📦 Small product catalog | 117 | 49 | 68 | **58.1%** |
|
||||||
| 👥 API response with users | 123 | 53 | 70 | **56.9%** |
|
| 👥 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%** |
|
| 🛒 E-commerce order | 163 | 94 | 69 | **42.3%** |
|
||||||
| 📊 Analytics data | 209 | 94 | 115 | **55.0%** |
|
| 📊 Analytics data | 209 | 94 | 115 | **55.0%** |
|
||||||
| 📈 Large dataset (50 records) | 2159 | 762 | 1397 | **64.7%** |
|
| 📈 Large dataset (50 records) | 2159 | 762 | 1397 | **64.7%** |
|
||||||
| **Total** | **2917** | **1139** | **1778** | **61.0%** |
|
| **Total** | **2918** | **1140** | **1778** | **60.9%** |
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary><strong>View detailed results</strong></summary>
|
<summary><strong>View detailed results</strong></summary>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const BENCHMARK_EXAMPLES = [
|
|||||||
user: {
|
user: {
|
||||||
id: 123,
|
id: 123,
|
||||||
name: 'Ada',
|
name: 'Ada',
|
||||||
tags: ['admin', 'ops', 'developer'],
|
tags: ['reading', 'gaming', 'coding'],
|
||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -71,7 +71,7 @@ const BENCHMARK_EXAMPLES = [
|
|||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 5432,
|
port: 5432,
|
||||||
credentials: {
|
credentials: {
|
||||||
username: 'admin',
|
username: 'dbuser',
|
||||||
password: 'secret123',
|
password: 'secret123',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ describe('nested objects', () => {
|
|||||||
|
|
||||||
describe('arrays of primitives', () => {
|
describe('arrays of primitives', () => {
|
||||||
it('encodes string arrays inline', () => {
|
it('encodes string arrays inline', () => {
|
||||||
const obj = { tags: ['admin', 'ops'] }
|
const obj = { tags: ['reading', 'gaming'] }
|
||||||
expect(encode(obj)).toBe('tags[2]: admin,ops')
|
expect(encode(obj)).toBe('tags[2]: reading,gaming')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('encodes number arrays inline', () => {
|
it('encodes number arrays inline', () => {
|
||||||
@@ -491,7 +491,7 @@ describe('complex structures', () => {
|
|||||||
user: {
|
user: {
|
||||||
id: 123,
|
id: 123,
|
||||||
name: 'Ada',
|
name: 'Ada',
|
||||||
tags: ['admin', 'ops'],
|
tags: ['reading', 'gaming'],
|
||||||
active: true,
|
active: true,
|
||||||
prefs: [],
|
prefs: [],
|
||||||
},
|
},
|
||||||
@@ -500,7 +500,7 @@ describe('complex structures', () => {
|
|||||||
'user:\n'
|
'user:\n'
|
||||||
+ ' id: 123\n'
|
+ ' id: 123\n'
|
||||||
+ ' name: Ada\n'
|
+ ' name: Ada\n'
|
||||||
+ ' tags[2]: admin,ops\n'
|
+ ' tags[2]: reading,gaming\n'
|
||||||
+ ' active: true\n'
|
+ ' active: true\n'
|
||||||
+ ' prefs[0]:',
|
+ ' prefs[0]:',
|
||||||
)
|
)
|
||||||
@@ -592,11 +592,11 @@ describe('non-JSON-serializable values', () => {
|
|||||||
describe('delimiter options', () => {
|
describe('delimiter options', () => {
|
||||||
describe('basic delimiter usage', () => {
|
describe('basic delimiter usage', () => {
|
||||||
it.each([
|
it.each([
|
||||||
{ delimiter: '\t' as const, name: 'tab', expected: 'admin\tops\tdev' },
|
{ delimiter: '\t' as const, name: 'tab', expected: 'reading\tgaming\tcoding' },
|
||||||
{ delimiter: '|' as const, name: 'pipe', expected: 'admin|ops|dev' },
|
{ delimiter: '|' as const, name: 'pipe', expected: 'reading|gaming|coding' },
|
||||||
{ delimiter: ',' as const, name: 'comma', expected: 'admin,ops,dev' },
|
{ delimiter: ',' as const, name: 'comma', expected: 'reading,gaming,coding' },
|
||||||
])('encodes primitive arrays with $name', ({ delimiter, expected }) => {
|
])('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}`)
|
expect(encode(obj, { delimiter })).toBe(`tags[3${delimiter !== ',' ? delimiter : ''}]: ${expected}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -734,8 +734,8 @@ describe('delimiter options', () => {
|
|||||||
|
|
||||||
describe('length marker option', () => {
|
describe('length marker option', () => {
|
||||||
it('adds length marker to primitive arrays', () => {
|
it('adds length marker to primitive arrays', () => {
|
||||||
const obj = { tags: ['admin', 'ops', 'dev'] }
|
const obj = { tags: ['reading', 'gaming', 'coding'] }
|
||||||
expect(encode(obj, { lengthMarker: '#' })).toBe('tags[#3]: admin,ops,dev')
|
expect(encode(obj, { lengthMarker: '#' })).toBe('tags[#3]: reading,gaming,coding')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('handles empty arrays', () => {
|
it('handles empty arrays', () => {
|
||||||
@@ -758,12 +758,12 @@ describe('length marker option', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('works with delimiter option', () => {
|
it('works with delimiter option', () => {
|
||||||
const obj = { tags: ['admin', 'ops', 'dev'] }
|
const obj = { tags: ['reading', 'gaming', 'coding'] }
|
||||||
expect(encode(obj, { lengthMarker: '#', delimiter: '|' })).toBe('tags[#3|]: admin|ops|dev')
|
expect(encode(obj, { lengthMarker: '#', delimiter: '|' })).toBe('tags[#3|]: reading|gaming|coding')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('default is false (no length marker)', () => {
|
it('default is false (no length marker)', () => {
|
||||||
const obj = { tags: ['admin', 'ops', 'dev'] }
|
const obj = { tags: ['reading', 'gaming', 'coding'] }
|
||||||
expect(encode(obj)).toBe('tags[3]: admin,ops,dev')
|
expect(encode(obj)).toBe('tags[3]: reading,gaming,coding')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user