Unity

An Elixir unit conversion calculator inspired by the Unix units utility. Powered by Localize for unit conversion, arithmetic, and locale-aware output in 500+ locales.

Quick taste

> 3 meters to feet
9.84252 feet

> 100 kg * 9.8 m/s^2
980 kilogram-meter-per-square-second

> 1|3 cup to mL
78.862746 milliliters

> 3.756 hours to h;min;s
3 hours, 45 minutes, 21.6 seconds

> sqrt(9 m^2)
3 meters

> locale de
Locale set to :de

> 1234,5 meter to kilometer
1,2345 Kilometer

Installation

Add unity to your list of dependencies in mix.exs:

def deps do
  [
    {:unity, "~> 0.5"}
  ]
end

Three ways to use it

As a library — embed unit evaluation in any Elixir application:

iex> {:ok, result, _env} = Unity.eval("3 meters to feet")
iex> result.value
9.84251968503937

As a REPL — interactive calculator with tab completion and history:

$ iex -S mix
iex> Unity.Repl.start()

As a CLI — single-expression evaluation and scripting:

$ mix escript.build
$ ./unity "3 meters to feet"
$ ./unity -v "1 gallon" "liters"
$ echo "100 celsius to fahrenheit" | ./unity

What's included

See the Exploring Unity guide for a detailed walkthrough with examples, or the GNU Units Conformance guide for a feature-by-feature comparison.

A fun example from history

See https://www.ibiblio.org/harris/500milemail.html.

> 3 millilightsecond to mile
558.847191 miles

References

License

Apache 2.0 (See LICENSE.md)