https://github.com/michalmuskala/format
A simple string formatter for Elixir
https://github.com/michalmuskala/format
elixir
Last synced: about 2 months ago
JSON representation
A simple string formatter for Elixir
- Host: GitHub
- URL: https://github.com/michalmuskala/format
- Owner: michalmuskala
- Created: 2016-02-18T19:38:04.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-19T16:03:19.000Z (over 6 years ago)
- Last Synced: 2025-02-25T17:09:58.688Z (2 months ago)
- Topics: elixir
- Language: Elixir
- Size: 19.5 KB
- Stars: 17
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.
```elixir
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
:okiex> 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](https://hex.pm/docs/publish), the package can be installed
by adding `format` to your list of dependencies in `mix.exs`:```elixir
def deps do
[{:format, "~> 0.1.0"}]
end
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/format](https://hexdocs.pm/format).