Skip to main content
This page documents all exported TypeScript types, interfaces, and type aliases used throughout the TOON library.

JSON Value Types

Types representing valid JSON values that can be encoded/decoded.

JsonPrimitive

Represents JSON primitive values.
Valid primitive types that can appear in JSON:
  • string - Text values
  • number - Numeric values (integers and floats)
  • boolean - true or false
  • null - Null value

JsonObject

Represents a JSON object with string keys and JsonValue values.
An object where:
  • Keys are always strings
  • Values can be any JsonValue (including nested objects and arrays)
  • Properties can be optional or undefined

JsonArray

Represents a JSON array of JsonValue elements.
An array containing any valid JSON values. Supports both mutable and readonly arrays.

JsonValue

Union type representing any valid JSON value.
This is the top-level type for any JSON-compatible value. Used as the input/output type for encode/decode functions.

Delimiter Types

Types for controlling how values are separated in arrays.

DelimiterKey

String literal type for delimiter names.
Available delimiter types:
  • 'comma' - Comma-separated values (default)
  • 'tab' - Tab-separated values
  • 'pipe' - Pipe-separated values

Delimiter

The actual delimiter character type.
The character used to separate values:
  • ',' - Comma (comma key)
  • '\t' - Tab character (tab key)
  • '|' - Pipe (pipe key)

Encoder Types

Types related to the encoding process.

EncodeReplacer

Function type for transforming or filtering values during encoding.
Parameters:
  • key - The property key or array index (as string). Empty string ('') for root value.
  • value - The normalized JsonValue at this location.
  • path - Array representing the path from root to this value.
Returns:
  • The replacement value (will be normalized again), or undefined to omit.
  • For root value, returning undefined means “no change” (don’t omit root).

EncodeOptions

Configuration interface for encoding operations.
See EncodeOptions for detailed documentation of each field.

ResolvedEncodeOptions

Internal type representing fully resolved encoding options.
All required fields are present with their default values, except replacer which remains optional. This type is used internally and typically not needed in application code.

Decoder Types

Types related to the decoding process.

DecodeOptions

Configuration interface for decoding operations.
See DecodeOptions for detailed documentation of each field.

DecodeStreamOptions

Specialized options interface for streaming decode that explicitly omits expandPaths.
Path expansion is not supported in streaming mode because it requires buffering the entire input.

ResolvedDecodeOptions

Internal type representing fully resolved decoding options.
All fields are present with their default values. This type is used internally and typically not needed in application code.

Streaming Types

Types for streaming decode operations.

JsonStreamEvent

Union type representing events emitted by streaming decoders.
Event Types:
{ type: 'startObject' }
Signals the beginning of an object. All following key events until the matching endObject are properties of this object.
{ type: 'endObject' }
Signals the end of an object. Matches the most recent unmatched startObject.
{ type: 'startArray', length: number }
Signals the beginning of an array. The length property indicates the declared array length from the TOON header.
{ type: 'endArray' }
Signals the end of an array. Matches the most recent unmatched startArray.
{ type: 'key', key: string, wasQuoted?: boolean }
Signals an object property key. The next event (which may be another event like startObject) is the value for this key.The optional wasQuoted field is true if the key was quoted in the TOON source.
{ type: 'primitive', value: JsonPrimitive }
Signals a primitive value (string, number, boolean, or null). The value field contains the parsed primitive.

Internal Types

These types are used internally by the library and are typically not needed in application code.

ArrayHeaderInfo

Information parsed from a TOON array header line.
string | undefined
The optional key name before the array header (e.g., users in users[3]:).
number
The declared length of the array (e.g., 3 in users[3]:).
Delimiter
The delimiter used for array values.
string[] | undefined
For tabular arrays, the field names (e.g., ['id', 'name', 'email'] in users[2]{id,name,email}:).

ParsedLine

Represents a parsed line from TOON input during decoding.
string
The original line text including indentation.
Depth
The computed nesting depth based on indentation.
number
The number of spaces of indentation.
string
The line content with indentation removed.
number
The 1-based line number in the input.

BlankLineInfo

Information about a blank line encountered during parsing.
Used internally for strict mode validation to detect blank lines within array data.

Depth

Type alias for representing nesting depth.
A numeric value representing how deeply nested a structure is. Root level is depth 0.

Constants

DELIMITERS

Object containing all available delimiter values.

DEFAULT_DELIMITER

The default delimiter used when none is specified.

Type Imports

All types are exported from the main package entry point:

See Also