mirror of
https://github.com/voson-wang/toon.git
synced 2026-01-29 23:34:10 +08:00
chore: release v0.1.0
This commit is contained in:
51
README.md
51
README.md
@@ -211,19 +211,19 @@ users[2]{id,name,role}:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# npm
|
# npm
|
||||||
npm install toon
|
npm install @byjohann/toon
|
||||||
|
|
||||||
# pnpm
|
# pnpm
|
||||||
pnpm add toon
|
pnpm add @byjohann/toon
|
||||||
|
|
||||||
# yarn
|
# yarn
|
||||||
yarn add toon
|
yarn add @byjohann/toon
|
||||||
```
|
```
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { encode } from 'toon'
|
import { encode } from '@byjohann/toon'
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
user: {
|
user: {
|
||||||
@@ -420,28 +420,8 @@ String values are quoted when any of the following is true:
|
|||||||
| Starts with `"- "` (list-like) | `"- item"` |
|
| Starts with `"- "` (list-like) | `"- item"` |
|
||||||
| Looks like structural token | `"[5]"`, `"{key}"`, `"[3]: x,y"` |
|
| Looks like structural token | `"[5]"`, `"{key}"`, `"[3]: x,y"` |
|
||||||
|
|
||||||
**Delimiter-specific behavior:**
|
> [!NOTE]
|
||||||
|
> **Delimiter-aware quoting:** The quoting rules are context-sensitive. When using tab or pipe delimiters, commas don't need quoting. Only the active delimiter triggers quoting – this applies to both array values and object values.
|
||||||
The quoting rules are context-sensitive based on the active delimiter. A character only needs quoting if it's the active delimiter:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
// With comma delimiter (default): commas need quotes, tabs don't
|
|
||||||
encode({ items: ['a,b', 'c\td'] })
|
|
||||||
// → items[2]: "a,b",c d
|
|
||||||
|
|
||||||
// With tab delimiter: tabs need quotes, commas don't
|
|
||||||
encode({ items: ['a,b', 'c\td'] }, { delimiter: '\t' })
|
|
||||||
// → items[2]: a,b "c\td"
|
|
||||||
|
|
||||||
// With pipe delimiter: pipes need quotes, commas and tabs don't
|
|
||||||
encode({ items: ['a|b', 'c,d'] }, { delimiter: '|' })
|
|
||||||
// → items[2]: "a|b"|c,d
|
|
||||||
|
|
||||||
// Object values follow the same context-sensitive quoting
|
|
||||||
encode({ note: 'a,b' }) // → note: "a,b"
|
|
||||||
encode({ note: 'a,b' }, { delimiter: '|' }) // → note: a,b
|
|
||||||
encode({ note: 'a,b' }, { delimiter: '\t' }) // → note: a,b
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Examples
|
#### Examples
|
||||||
|
|
||||||
@@ -512,7 +492,7 @@ A TOON-formatted string with no trailing newline or spaces.
|
|||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { encode } from 'toon'
|
import { encode } from '@byjohann/toon'
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{ sku: 'A1', qty: 2, price: 9.99 },
|
{ sku: 'A1', qty: 2, price: 9.99 },
|
||||||
@@ -539,7 +519,7 @@ The `delimiter` option allows you to choose between comma (default), tab, or pip
|
|||||||
Using tab delimiters instead of commas can reduce token count further, especially for tabular data:
|
Using tab delimiters instead of commas can reduce token count further, especially for tabular data:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { encode } from 'toon'
|
import { encode } from '@byjohann/toon'
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
items: [
|
items: [
|
||||||
@@ -585,21 +565,6 @@ items[2]{sku,name,qty,price}:
|
|||||||
B2|Gadget|1|14.5
|
B2|Gadget|1|14.5
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Delimiter Selection Guide
|
|
||||||
|
|
||||||
| Delimiter | Token Efficiency | Human Readability | Quote Escaping | Best For |
|
|
||||||
|-----------|-----------------|-------------------|----------------|----------|
|
|
||||||
| `,` (comma) | ⭐⭐⭐ Baseline | ⭐⭐⭐⭐⭐ High | ⭐⭐⭐ Moderate | **Default choice**, general use |
|
|
||||||
| `\t` (tab) | ⭐⭐⭐⭐⭐ Highest | ⭐⭐ Lower | ⭐⭐⭐⭐⭐ Minimal | Large datasets, maximum efficiency |
|
|
||||||
| `\|` (pipe) | ⭐⭐⭐⭐ High | ⭐⭐⭐⭐ Good | ⭐⭐⭐⭐ Low | CSV-like data, CLI output |
|
|
||||||
|
|
||||||
> [!TIP]
|
|
||||||
> When using non-default delimiters, inform the LLM of the delimiter in your prompt:
|
|
||||||
> ```
|
|
||||||
> The following data uses tab-delimited TOON format:
|
|
||||||
> ```[tab-delimited content]```
|
|
||||||
> ```
|
|
||||||
|
|
||||||
## Using TOON in LLM Prompts
|
## Using TOON in LLM Prompts
|
||||||
|
|
||||||
When incorporating TOON into your LLM workflows:
|
When incorporating TOON into your LLM workflows:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@byjohann/toon",
|
"name": "@byjohann/toon",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.0.0",
|
"version": "0.1.0",
|
||||||
"packageManager": "pnpm@10.19.0",
|
"packageManager": "pnpm@10.19.0",
|
||||||
"description": "Token-Oriented Object Notation – a token-efficient data notation for LLM prompts",
|
"description": "Token-Oriented Object Notation – a token-efficient data notation for LLM prompts",
|
||||||
"author": "Johann Schopplich <hello@johannschopplich.com>",
|
"author": "Johann Schopplich <hello@johannschopplich.com>",
|
||||||
|
|||||||
Reference in New Issue
Block a user