Support.String (Support v0.3.1)

Summary

Functions

Return the remainder of a string after the first occurrence of a given value.

Return the remainder of a string after the last occurrence of a given value.

Get the portion of a string before the first occurrence of a given value.

Get the portion of a string before the last occurrence of a given value.

Get the portion of a string between two given values.

Get the smallest possible portion of a string between two given values.

Convert a string to kebab case.

Convert the first character of the given string to lower-case.

Convert the given string to lower-case.

Get the plural form of an English word.

Reverse the given string.

Get the singular form of an English word.

Convert a string to snake case.

Take the first or last limit characters of a string.

Convert a string to the specified case.

Convert a string to the specified case with a custom delimiter.

Make a string's first character uppercase.

Convert the given string to upper-case.

Functions

after(value, search)

(since 0.2.0)
@spec after(String.t(), String.t() | integer()) :: String.t()

Return the remainder of a string after the first occurrence of a given value.

Usage

iex> alias Support.String
Support.String

iex> String.after("Elixir Package", "Elixir ")
"Package"

after_last(value, search)

(since 0.2.0)
@spec after_last(String.t(), String.t() | integer()) :: String.t()

Return the remainder of a string after the last occurrence of a given value.

Usage

iex> alias Support.String
Support.String

iex> String.after_last("Elixir Package Elixir", "Elixir ")
"Package Elixir"

before(value, search)

(since 0.2.0)
@spec before(String.t(), String.t() | integer()) :: String.t()

Get the portion of a string before the first occurrence of a given value.

Usage

iex> alias Support.String
Support.String

iex> String.before("Elixir Package", " Package")
"Elixir"

before_last(value, search)

(since 0.2.0)
@spec before_last(String.t(), String.t() | integer()) :: String.t()

Get the portion of a string before the last occurrence of a given value.

Usage

iex> alias Support.String
Support.String

iex> String.before_last("Elixir Package Elixir", " Elixir")
"Elixir Package"

between(value, from, to)

(since 0.3.0)
@spec between(String.t(), String.t() | integer(), String.t() | integer()) ::
  String.t()

Get the portion of a string between two given values.

Usage

iex> alias Support.String
Support.String

iex> String.between("Elixir Package", "E", "r")
"lixi"

between_first(value, from, to)

(since 0.3.0)
@spec between_first(String.t(), String.t() | integer(), String.t() | integer()) ::
  String.t()

Get the smallest possible portion of a string between two given values.

Usage

iex> alias Support.String
Support.String

iex> String.between_first("Elixir Package", "E", "i")
"l"

kebab(value)

(since 0.3.0)
@spec kebab(String.t()) :: String.t()

Convert a string to kebab case.

Usage

iex> alias Support.String
Support.String

iex> String.kebab("Elixir Package")
"elixir-package"

lcfirst(value)

(since 0.3.0)
@spec lcfirst(String.t()) :: String.t()

Convert the first character of the given string to lower-case.

Usage

iex> alias Support.String
Support.String

iex> String.lcfirst("Support")
"support"

lower(value)

(since 0.3.0)
@spec lower(String.t()) :: String.t()

Convert the given string to lower-case.

Usage

iex> alias Support.String
Support.String

iex> String.lower("Elixir Package")
"elixir package"

plural(word, count \\ 2)

(since 0.3.0)
@spec plural(String.t(), integer()) :: String.t()

Get the plural form of an English word.

Usage

iex> alias Support.String
Support.String

iex> String.plural("person")
"people"

iex> String.plural("User")
"Users"

reverse(value)

(since 0.1.0)
@spec reverse(String.t()) :: String.t()

Reverse the given string.

Usage

iex> alias Support.String
Support.String

iex> String.reverse("raBooF")
"FooBar"

iex> String.reverse("őtüzsineT")
"Teniszütő"

iex> String.reverse("☆etyBitluM❤")
"❤MultiByte☆"

singular(word)

(since 0.3.0)
@spec singular(String.t()) :: String.t()

Get the singular form of an English word.

Usage

iex> alias Support.String
Support.String

iex> String.singular("people")
"person"

iex> String.singular("Users")
"User"

snake(value, delimiter \\ "_")

(since 0.3.0)
@spec snake(String.t(), String.t()) :: String.t()

Convert a string to snake case.

Usage

iex> alias Support.String
Support.String

iex> String.snake("Elixir Package")
"elixir_package"

iex> String.snake("Elixir Package", "-")
"elixir-package"

take(value, limit)

(since 0.3.0)
@spec take(String.t(), integer()) :: String.t()

Take the first or last limit characters of a string.

Usage

iex> alias Support.String
Support.String

iex> String.take("Elixir Package", 7)
"Elixir "

iex> String.take("Elixir Package", -7)
"Package"

to_case(value, case)

(since 0.3.1)
@spec to_case(String.t(), atom()) :: String.t()

Convert a string to the specified case.

Usage

iex> alias Support.String
Support.String

iex> String.to_case("Elixir Package", :kebab)
"elixir-package"

iex> String.to_case("Elixir Package", :snake)
"elixir_package"

iex> String.to_case("Elixir Package", :upper)
"ELIXIR PACKAGE"

iex> String.to_case("Elixir Package", :lower)
"elixir package"

to_case(value, delimeter, case)

@spec to_case(String.t(), String.t(), atom()) :: String.t()

Convert a string to the specified case with a custom delimiter.

Usage

iex> alias Support.String
Support.String

iex> String.to_case("Elixir Package", "_", :snake)
"elixir_package"

iex> String.to_case("Elixir Package", " ?? ", :snake)
"elixir ?? package"

ucfirst(value)

(since 0.3.0)
@spec ucfirst(String.t()) :: String.t()

Make a string's first character uppercase.

Usage

iex> alias Support.String
Support.String

iex> String.ucfirst("support")
"Support"

upper(value)

(since 0.3.0)
@spec upper(String.t()) :: String.t()

Convert the given string to upper-case.

Usage

iex> alias Support.String
Support.String

iex> String.upper("Elixir Package")
"ELIXIR PACKAGE"