format icon indicating copy to clipboard operation
format copied to clipboard

A simple string formatter for Elixir

Format


WARNING: This library is of alpha quality. There's a lot of missing features and bugs should be expected.


Alternative string formatter for Elixir inspired by Python and Rust.

iex> use Format
iex> Format.fmt(~F"{} {}", [1, "foo"])
[[[[]] | "1"], " ", "foo"]]
iex> Format.string(~F"{} {}", [1, "foo"])
"1 foo"
iex> Format.puts(~F"{} {}", [1, "foo"])
1 foo
:ok

iex> Format.string(~F"{foo} {bar}", bar: 1, foo: 3)
"3 1"
iex> Format.string(~F"{foo:.3f} {foo:.5f}", foo: 3.2)
"3.200 3.20000"
iex> Format.string(~F"{0:^10d}|{0:<10x}|{0:>10b}", [100])
"   100    |        64|1100100   "

Installation

If available in Hex, the package can be installed by adding format to your list of dependencies in mix.exs:

def deps do
  [{:format, "~> 0.1.0"}]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/format.