Focused TOML 1.0.0 encoder.
gsmlg_toml 1.0.0 only decodes, so Formata ships this encoder.
Domain
| Elixir value | TOML |
|---|---|
| map with string keys (root) | the document (root table) |
| nested map | [table] section (inline {} inside arrays) |
| non-empty list of maps | array of tables [[name]] |
other list (incl. []) | inline array |
| UTF-8 binary | basic string with escapes |
| integer in signed 64-bit range | integer |
float / :infinity / :negative_infinity / :nan | float / inf / -inf / nan |
true / false | boolean |
DateTime | offset date-time |
NaiveDateTime | local date-time |
Date | local date |
Time | local time |
Everything else is rejected: a non-map root, nil, atoms, tuples, other
structs, non-string or non-UTF-8 keys, integers outside the 64-bit range,
years outside 0000..9999, and DateTime offsets that are not whole minutes.
Keys are emitted in sorted order; plain keys are bare when they match
[A-Za-z0-9_-]+ and quoted otherwise.
Summary
Functions
Encodes a map as a TOML document.
Functions
@spec encode(term()) :: {:ok, binary()} | {:error, [Formata.Error.t(), ...]}
Encodes a map as a TOML document.
iex> Formata.Codec.TOML.Encoder.encode(%{"title" => "x", "owner" => %{"name" => "Tom"}})
{:ok, ~s(title = "x"\n\n[owner]\nname = "Tom"\n)}