Exflect (exflect v1.0.0)
Summary
Functions
Inflects the input word based on the the integer given.
Returns true is the word is plural, else false.
Pluralizes an English word.
Returns true is the word is singular, else false.
Singlarizes an English word.
Functions
inflect(word, n, opts \\ [match_style: false])
@spec inflect(String.t(), pos_integer(), keyword()) :: String.t()
Inflects the input word based on the the integer given.
iex> Exflect.inflect("leaf", 0)
"leaves"
iex> Exflect.inflect("leaf", 1)
"leaf"
iex> Exflect.inflect("leaf", 2)
"leaves"
Also accepts the match_style
option
plural?(string)
Returns true is the word is plural, else false.
pluralize(word, opts \\ [match_style: false, check: false])
Pluralizes an English word.
iex> Exflect.pluralize("leaf")
"leaves"
Takes two options:
check
: boolean
| default: false
match_style
: boolean
| default: false
Use the option check
, if you're not sure about the form of the word you're passing in.
For performance reasons, to avoid a bunch of expensive regex call, by default the input is not checked to see if it's already plural.
This incurs about a 30x performance hit. ~40k ips vs ~1.2m ips unchecked.
iex> Exflect.pluralize("men")
"mens"
iex> Exflect.pluralize("men", check: true)
"men"
Use the option match_style
if you want it to maintain the current whitespace/case.
iex> Exflect.pluralize(" LEAF ", match_style: true)
" LEAVES "
singular?(string)
Returns true is the word is singular, else false.
singularize(text, opts \\ [match_style: false, check: false])
Singlarizes an English word.
iex> Exflect.singularize("leaves")
"leaf"
Takes two options:
check
: boolean
| default: false
match_style
: boolean
| default: false
Use the option check
, if you're not sure about the form of the word you're passing in.
For performance reasons, to avoid a bunch of expensive regex call, by default the input is not checked to see if it's already singular.
This incurs about a 30x performance hit. ~40k ips vs ~1.2m ips unchecked.
iex> Exflect.singularize("bus")
"bu"
iex> Exflect.singularize("bus", check: true)
"bus"
Use the option match_style
if you want it to maintain the current whitespace/case.
iex> Exflect.singularize(" LEAVES ", match_style: true)
" LEAF "