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.

Returns true is the word is singular, else false.

Functions

Link to this function

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

Link to this function

plural?(string)

@spec plural?(String.t()) :: boolean()

Returns true is the word is plural, else false.

Link to this function

pluralize(word, opts \\ [match_style: false, check: false])

@spec pluralize(
  String.t(),
  keyword()
) :: String.t()

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  "
Link to this function

singular?(string)

@spec singular?(String.t()) :: boolean()

Returns true is the word is singular, else false.

Link to this function

singularize(text, opts \\ [match_style: false, check: false])

@spec singularize(
  String.t(),
  keyword()
) :: String.t()

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  "