Rivet.Utils.English (rivet_utils v2.8.0)

Copy Markdown View Source

Various english-centric human wording helper functions.

Summary

Functions

iex> a_or_an("explosion") "an explosion" iex> a_or_an("cart") "a cart"

chicago_number as in the Chicago Style Guide's rule for numbers which is to spell out numbers lower than 100.

Similarly, just trying to avoid heavy dependencies, do this here.

iex> pluralize(1, "cave") "cave" iex> pluralize(3, "cave") "caves"

iex> titleize("mote in god's eye") "Mote in God's Eye"

Functions

a_or_an(str)

iex> a_or_an("explosion") "an explosion" iex> a_or_an("cart") "a cart"

capitalize(x)

See String.capitalize/1.

chicago_number(n)

chicago_number as in the Chicago Style Guide's rule for numbers which is to spell out numbers lower than 100.

We could use Number.to_word() except that library has heavy dependencies which are not necessary here.

iex> chicago_number(1) "one" iex> chicago_number(42) "forty-two" iex> chicago_number(120) "120"

comma_number(n)

Similarly, just trying to avoid heavy dependencies, do this here.

iex> comma_number(-1_234_567) "-1,234,567" iex> comma_number(1_234.50000000000353) "1,234.5" iex> comma_number(-1_234.5000) "-1,234.5" iex> comma_number(134.0) "134"

is_or_are(count)

number_to_string(n)

pluralize(count, word)

iex> pluralize(1, "cave") "cave" iex> pluralize(3, "cave") "caves"

titleize(str)

iex> titleize("mote in god's eye") "Mote in God's Eye"