Toon.Types (toon v0.3.0)

View Source

Type definitions for TOON encoder and decoder.

This module defines all the types used throughout the TOON library, ensuring type safety and better documentation.

Summary

Types

A single decoding option.

Options for decoding TOON format.

Valid delimiters for array values.

Indentation depth level.

A JSON-compatible value that can be encoded to TOON format.

A single encoding option.

Options for encoding TOON format.

IO data that can be efficiently concatenated.

A JSON-compatible primitive value.

Types

decode_opt()

@type decode_opt() :: {:keys, :strings | :atoms | :atoms!}

A single decoding option.

decode_opts()

@type decode_opts() :: [decode_opt()]

Options for decoding TOON format.

Options

  • :keys - How to decode map keys (default: :strings)

Examples

Toon.decode!(toon, keys: :strings)
Toon.decode!(toon, keys: :atoms)

delimiter()

@type delimiter() :: binary()

Valid delimiters for array values.

Can be comma, tab, or pipe character.

depth()

@type depth() :: non_neg_integer()

Indentation depth level.

encodable()

@type encodable() ::
  nil
  | boolean()
  | number()
  | String.t()
  | %{optional(String.t()) => encodable()}
  | [encodable()]

A JSON-compatible value that can be encoded to TOON format.

This is a recursive type that includes:

  • Primitives: nil, boolean(), number(), String.t()
  • Maps: %{optional(String.t()) => encodable()}
  • Lists: [encodable()]

encode_opt()

@type encode_opt() ::
  {:indent, pos_integer()}
  | {:delimiter, delimiter()}
  | {:length_marker, String.t() | nil}

A single encoding option.

encode_opts()

@type encode_opts() :: [encode_opt()]

Options for encoding TOON format.

Options

  • :indent - Number of spaces for indentation (default: 2)
  • :delimiter - Delimiter for array values (default: ",")
  • :length_marker - Prefix for array length marker (default: nil)

Examples

Toon.encode!(data, indent: 4)
Toon.encode!(data, delimiter: "\t")
Toon.encode!(data, length_marker: "#")

iodata_result()

@type iodata_result() :: iodata()

IO data that can be efficiently concatenated.

primitive()

@type primitive() :: nil | boolean() | number() | String.t()

A JSON-compatible primitive value.