DarkMatter.Strings (DarkMatter v1.1.4) View Source

General utils for working with strings.

Link to this section Summary

Functions

Determine if a string is blank.

Determine if a string is blank.

Capitalizes all words in the given binary that are separated by the given separator

Concats a list of strings. Similar to CONCAT_WS in postgres.

Normalize a binary.

Strip non-alphanumeric chars from binary

Removes non word characters.

Link to this section Functions

Specs

blank?(nil | String.t()) :: boolean()

Determine if a string is blank.

Examples

iex> blank?(nil)
true

iex> blank?("")
true

iex> blank?("   ")
false

iex> blank?("a dog ran down the street")
false

Specs

blank?(nil | String.t(), list() | %{optional(:trim) => boolean()}) :: boolean()

Determine if a string is blank.

Examples

iex> blank?("   ", trim: true)
true

iex> blank?("   ", %{trim: true})
true
Link to this function

capitalize_words(binary, separator \\ " ")

View Source

Specs

capitalize_words(String.t(), String.t()) :: String.t()

Capitalizes all words in the given binary that are separated by the given separator

Examples

iex> capitalize_words("a dog ran down the street")
"A Dog Ran Down The Street"
Link to this function

concat_ws(list, joiner \\ " ")

View Source

Specs

concat_ws([String.t() | nil], String.t()) :: String.t()

Concats a list of strings. Similar to CONCAT_WS in postgres.

Examples

iex> concat_ws(["", nil, %{}, "first", "time"])
"first time"

Specs

normalize(String.t()) :: String.t()

Normalize a binary.

Examples

iex> normalize("a dog ran down the street")
"a dog ran down the street"

Specs

strip_non_digit(String.t()) :: String.t()

Strip non-alphanumeric chars from binary

Examples

iex> strip_non_digit("a dog ran down the street")
""

iex> strip_non_digit("123-456#1526")
"1234561526"
Link to this function

strip_non_words_characters(binary)

View Source

Specs

strip_non_words_characters(String.t()) :: String.t()

Removes non word characters.

Examples

iex> strip_non_words_characters("a dog ran down the street")
"adograndownthestreet"
Link to this function

strip_whitespace(binary, replacement \\ "")

View Source

Specs

strip_whitespace(String.t(), String.t()) :: String.t()

Removes whitespace chars.

Examples

iex> strip_whitespace("a dog ran down the street")
"adograndownthestreet"