- Notifications
You must be signed in to change notification settings - Fork11
ufirstgroup/ymlr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ymlr - A YAML encoder for Elixir.
The package can be installed by addingymlr
to your list of dependencies inmix.exs
:
defdepsdo[{:ymlr,"~> 5.0"}]end
See The usage livebookusage.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 leadingcolon). If you want atoms to be encoded with a leading colon in order to be ableto parse it later usingYamlElixir
'satoms
option, you canpassatoms: true
as second argument to any of theYmlr
module's functions:
iex>Ymlr.document!(%{a:1},atoms:true)"""---:a: 1"""
Maps in elixir, implemented by erlang:maps
, internally areflatmap
s orhashmap
s by size.Large maps will be encoded in strange order.
iex>1..33|>Map.new(&{&1,&1})|>Ymlr.document!()|>IO.puts---4:425:258:8...
By using:sort_maps
option, ymlr will encode all entries sorted.
iex>1..33|>Map.new(&{&1,&1})|>Ymlr.document!(sort_maps:true)|>IO.puts---1:12:23:3...
This library does not claim to be particularly performant. We do have a scriptto benchmark encoding so we know if performance gets better or worse withchanges.
You can find the last Benchmark inBENCHMARK.md
cd benchmark/elixir run.exs
About
A YAML encoder for Elixir.