Toon.Types (toon v0.3.0)
View SourceType 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
@type decode_opt() :: {:keys, :strings | :atoms | :atoms!}
A single decoding option.
@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)
@type delimiter() :: binary()
Valid delimiters for array values.
Can be comma, tab, or pipe character.
@type depth() :: non_neg_integer()
Indentation depth level.
@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()]
@type encode_opt() :: {:indent, pos_integer()} | {:delimiter, delimiter()} | {:length_marker, String.t() | nil}
A single encoding option.
@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: "#")
@type iodata_result() :: iodata()
IO data that can be efficiently concatenated.
A JSON-compatible primitive value.