Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A YAML encoder for Elixir.

License

NotificationsYou must be signed in to change notification settings

ufirstgroup/ymlr

Repository files navigation

ymlr - A YAML encoder for Elixir.

Module VersionCoverage StatusLast Updated

Build Status Code QualitsBuild Status Elixir

Hex DocsTotal DownloadLicense

Installation

The package can be installed by addingymlr to your list of dependencies inmix.exs:

defdepsdo[{:ymlr,"~> 5.0"}]end

Examples

See The usage livebookusage.livemd for more detailed examples.

Encode a single document - optionally with comments:

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'  """

Encode a multiple documents

iex>Ymlr.documents!([%{a:1},%{b:2}])"""---a: 1---b: 2"""

Support for atoms

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'satomsoption, you canpassatoms: true as second argument to any of theYmlr module's functions:

iex>Ymlr.document!(%{a:1},atoms:true)"""---:a: 1"""

Encode maps with keys sorted

Maps in elixir, implemented by erlang:maps, internally areflatmaps orhashmaps 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...

Benchmark

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

Running the script

cd benchmark/elixir run.exs

[8]ページ先頭

©2009-2025 Movatter.jp