Fox.StringExt

Source

Summary

camelize(string)

Takes a string and makes it camel-cased. Note that “/“ become periods “.”

consume!(meal, bite)

Same as consume/2, except throws error instead of returning a tuple

consume(meal, bite)

Takes a string consume from the left a portion of the string and returns the remaining string

float?(string)

returns true if a string can be parsed as an float

integer?(string)

returns true if a string can be parsed as an integer

next_grapheme(string)

Just like String.next_grapheme/1, except if you give it the :reverse atom, it goes backwards

next_grapheme(string, arg2)
number?(string)

returns true if a string can be parsed as an integer or float

pluralize(noun)

Takes a singular word and returns the plural form

random()

Generates a random string of length n. Defaults to n = 10

random(n)
reverse_consume!(meal, bite)

Same as reverse_consume/2 except returns values/throws error instead of returning tuple

reverse_consume(meal, bite)

Consumes a string starting from the end and going to the begining

singularize(nouns)

Takes a word and returns its singular form

to_url(string)

Takes a string and builds it into an url-friendly string, good for permalinks and generally being passed around in the browser

Examples

“Breaking! Are 50% of Americans trying to kill you?” |> to_url # “breaking-bang-are-50-percent-of-americans-trying-to-kill-you-question”

transformations()
transformify(arg1)
underscore(string)

Takes a string and makes it underscored. This is the semi-inverse of camelize. Note that because this is Elixir and not ruby, periods become “/“, not “::”

Functions

camelize(string)

Takes a string and makes it camel-cased. Note that “/“ become periods “.”

Examples

“under_scored” |> camelize # UnderScored

# acronyms are not restored by camelize (lol obviously) “acronym_hiv” |> camelize # AcronymHiv

# spaces are ignored “sakidasu kasa no mure ni” |> camelize # Sakidasu kasa no mure ni

“my_app/module/sub_module” |> camelize # MyApp.Module.SubModule

Source
consume(meal, bite)

Takes a string consume from the left a portion of the string and returns the remaining string

Examples

“dog food” |> consume(“dog “) # {:ok, “food”}

“dog food” |> consume(“cat”) # {:error, “no cat in dog food”}

Source
consume!(meal, bite)

Same as consume/2, except throws error instead of returning a tuple

Source
float?(string)

returns true if a string can be parsed as an float

Source
integer?(string)

returns true if a string can be parsed as an integer

Source
next_grapheme(string)

Just like String.next_grapheme/1, except if you give it the :reverse atom, it goes backwards

Examples

“極彩色” |> next_grapheme(:reverse) # {“極彩”, “色”}

Source
next_grapheme(string, arg2)
Source
number?(string)

returns true if a string can be parsed as an integer or float

Source
pluralize(noun)

Takes a singular word and returns the plural form

Examples

“black” |> pluralize # blacks “white” |> pluralize # whites

“App.Something.DumbChild” |> pluralize # “App.Something.DumbChildren”

“App.Something.DumbChildRen” |> pluralize # “App.Something.DumbChildRens”

Note that in the last example, random capitalization will induce the inflector to treat ChildRen as 2 words. This is intentionally different from ActiveSupport’s version.

Source
random()

Generates a random string of length n. Defaults to n = 10

Examples

random(33) # dv9hUn7rfnKOtLkOebBkfaUEmWMND522V

Source
random(n)
Source
reverse_consume(meal, bite)

Consumes a string starting from the end and going to the begining.

Examples

“namae no nai kaibutsu” |> reverse_consume(“kaibutsu”) # {:ok, “namae no nai “}

“namae no nai kaibutsu” |> reverseconsume(“dumb show”) # {:error, }

Source
reverse_consume!(meal, bite)

Same as reverse_consume/2 except returns values/throws error instead of returning tuple

Source
singularize(nouns)

Takes a word and returns its singular form

Examples

“dogs” |> singularize # dog “oxen” |> singularize # ox

“App.Something.DumbChildren” |> singularize # “App.Something.DumbChild”

“App.Something.DumbChildRen” |> singularize # “App.Something.DumbChildRen”

Source
to_url(string)

Takes a string and builds it into an url-friendly string, good for permalinks and generally being passed around in the browser

Examples

“Breaking! Are 50% of Americans trying to kill you?” |> to_url # “breaking-bang-are-50-percent-of-americans-trying-to-kill-you-question”

Source
transformations()
Source
transformify(arg1)
Source
underscore(string)

Takes a string and makes it underscored. This is the semi-inverse of camelize. Note that because this is Elixir and not ruby, periods become “/“, not “::”

Examples

“CamelCase” |> underscore # camel_case

“AcronymHIV” |> underscore # acronym_hiv

“dasher-ized” |> underscore # dasher_ized

# Spaces are ignored (following rails convention) “regular words” |> underscore # regular words

“MyApp.Module.SubModule” |> underscore # my_app/module/sub_module

Source