swiss v3.0.0 Swiss.String View Source

A few extra functions to deal with Strings. Heavily inspired by lodash.

Link to this section Summary

Link to this section Functions

Deburrs a string from unicode to its ascii equivalent.

Examples

iex> Swiss.String.deburr "hola señor!"
"hola senor!"
Link to this function

insert_at(string, pos, substr)

View Source
insert_at(String.t(), non_neg_integer(), String.t()) :: String.t()

Inserts a substring into another string at the given position.

Examples

iex> Swiss.String.insert_at "Banas", 2, "na"
"Bananas"
Link to this function

kebab_case(string)

View Source
kebab_case(String.t()) :: String.t()

Converts a string into kebab-case.

Examples

iex> Swiss.String.kebab_case "Foo Bar"
"foo-bar"
iex> Swiss.String.kebab_case "--foo-bar--"
"foo-bar"
iex> Swiss.String.kebab_case "__FOO_BAR__"
"foo-bar"
iex> Swiss.String.kebab_case "FooBar"
"foo-bar"
Link to this function

snake_case(string)

View Source
snake_case(String.t()) :: String.t()

Converts a string into snake_case.

Examples

iex> Swiss.String.snake_case "Foo Bar"
"foo_bar"
iex> Swiss.String.snake_case "--foo-bar--"
"foo_bar"
iex> Swiss.String.snake_case "__FOO_BAR__"
"foo_bar"
iex> Swiss.String.snake_case "FooBar"
"foo_bar"
Link to this function

words(string, pattern \\ %{__struct__: Regex, opts: "", re_pattern: {:re_pattern, 0, 0, 0, <<69, 82, 67, 80, 105, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, 0, 37, 111, 0, 0, 0, 0, 0, 0, 255, 3, 254, 255, 255, 7, 254, 255, 255, 7, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 107, 120, 0, 37, 0>>}, re_version: {"8.43 2019-02-23", :little}, source: "[^\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7f]+"})

View Source
words(String.t(), Regex.t()) :: [String.t()]

Decomposes a string into an array of its words.

Examples

iex> Swiss.String.words "FredBarney"
["Fred", "Barney"]
iex> Swiss.String.words "fred, barney, & pebbles"
["fred", "barney", "pebbles"]
iex> Swiss.String.words "fred, barney, & pebbles", ~r/[^, ]+/
["fred", "barney", "&", "pebbles"]