ymlr - A YAML encoder for Elixir.
The package can be installed by adding ymlr
to your list of dependencies in mix.exs
:
def deps do
[
{:ymlr, "~> 4.0"}
]
end
See The usage livebook usage.livemd
for more detailed examples.
iex> Ymlr.document!(%{a: 1})
"""
---
a: 1
"""
iex> Ymlr.document!({"comment", %{a: 1}})
"""
---
# comment
a: 1
"""
iex> Ymlr.document!({["comment 1", "comment 2"], %{"a" => "a", "b" => :b, "c" => "true", "d" => "100"}})
"""
---
# comment 1
# comment 2
a: a
b: b
c: 'true'
d: '100'
"""
iex> Ymlr.documents!([%{a: 1}, %{b: 2}])
"""
---
a: 1
---
b: 2
"""
By default, atoms as map keys are encoded as strings (without the leading
colon). If you want atoms to be encoded with a leading colon in order to be able
to parse it later using YamlElixir
's atoms
option, you can
pass atoms: true
as second argument to any of the Ymlr
module's functions:
iex> Ymlr.document!(%{a: 1}, atoms: true)
"""
---
:a: 1
"""