> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wevm/incur/llms.txt
> Use this file to discover all available pages before exploring further.

# Formatter

> Serialize data to multiple output formats including TOON, JSON, YAML, and Markdown

The `Formatter` module provides utilities for serializing data to various output formats. It supports TOON (the default format), JSON, YAML, Markdown tables, and JSONL.

## Types

### Format

Supported output formats for the `format()` function.

```typescript theme={null}
type Format = 'toon' | 'json' | 'yaml' | 'md' | 'jsonl'
```

<ResponseField name="toon" type="'toon'">
  TOON format (default) - a concise, human-readable format
</ResponseField>

<ResponseField name="json" type="'json'">
  Pretty-printed JSON with 2-space indentation
</ResponseField>

<ResponseField name="yaml" type="'yaml'">
  YAML format
</ResponseField>

<ResponseField name="md" type="'md'">
  Markdown format with tables for structured data
</ResponseField>

<ResponseField name="jsonl" type="'jsonl'">
  JSON Lines format (one JSON object per line)
</ResponseField>

## Functions

### format

Serializes a value to the specified format. Defaults to TOON.

<ParamField path="value" type="unknown" required>
  The value to serialize. Can be any JavaScript value including objects, arrays, primitives, or null/undefined.
</ParamField>

<ParamField path="fmt" type="Format" default="'toon'">
  The output format. Defaults to `'toon'`.
</ParamField>

<ResponseField name="return" type="string">
  The serialized string representation of the value
</ResponseField>

#### Usage: Basic Formatting

```typescript theme={null}
import { format } from 'incur'

const data = {
  name: 'Alice',
  age: 30,
  active: true
}

// TOON format (default)
const toon = format(data)
// name: Alice
// age: 30
// active: true

// JSON format
const json = format(data, 'json')
// {
//   "name": "Alice",
//   "age": 30,
//   "active": true
// }

// YAML format
const yaml = format(data, 'yaml')
// name: Alice
// age: 30
// active: true
```

#### Usage: Markdown Tables

```typescript theme={null}
import { format } from 'incur'

// Flat object becomes a key-value table
const config = { host: 'localhost', port: 3000 }
const md = format(config, 'md')
// | Key  | Value     |
// |------|-----------|  
// | host | localhost |
// | port | 3000      |

// Array of objects becomes a columnar table
const users = [
  { name: 'Alice', role: 'admin' },
  { name: 'Bob', role: 'user' }
]
const table = format(users, 'md')
// | name  | role  |
// |-------|-------|
// | Alice | admin |
// | Bob   | user  |
```

#### Usage: Scalar Values

```typescript theme={null}
import { format } from 'incur'

// Scalars return as strings
format('hello')  // 'hello'
format(42)       // '42'
format(true)     // 'true'
format(null)     // ''
format(undefined) // ''
```

#### Usage: CLI Output

```typescript theme={null}
import { format } from 'incur'

function output(data: unknown, fmt: Format = 'toon') {
  console.log(format(data, fmt))
}

// User can control output format
const result = { success: true, count: 42 }
output(result, 'json')  // Pretty JSON
output(result, 'yaml')  // YAML
output(result, 'md')    // Markdown table
```

#### Usage: Nested Objects

```typescript theme={null}
import { format } from 'incur'

const nested = {
  server: {
    host: 'localhost',
    port: 3000
  },
  database: {
    host: 'db.example.com',
    port: 5432
  }
}

const md = format(nested, 'md')
// ## server
//
// | Key  | Value     |
// |------|-----------|  
// | host | localhost |
// | port | 3000      |
//
// ## database
//
// | Key  | Value          |
// |------|----------------|
// | host | db.example.com |
// | port | 5432           |
```
