Fox.StringExt
SourceSummary
camelize(string) | Takes a string and makes it camel-cased. Note that “/“ become periods “.” |
consume!(meal, bite) | Same as |
consume(meal, bite) | Takes a string consume from the left a portion of the string and returns the remaining string |
dasherize(string) | Takes a string and makes it dashed, very similar to underscore, except instead of “_” we use “-“ |
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 |
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(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(arg) | |
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
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
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”}
Same as consume/2
, except throws error instead of returning a tuple
Takes a string and makes it dashed, very similar to underscore, except instead of “_” we use “-“
Examples
“CamelCase” |> dasherize # camel-case
“AcronymHIV” |> dasherize # acronym-hiv
“dasher-ized” |> dasherize # dasher-ized
# Spaces are ignored (following rails convention) “regular words” |> dasherize # regular words
“MyApp.Module.SubModule” |> dasherize # my-app/module/sub-module
returns true if a string can be parsed as an float
returns true if a string can be parsed as an integer
Just like String.next_grapheme/1
, except if you give it the :reverse
atom, it goes backwards
Examples
“極彩色” |> next_grapheme(:reverse) # {“極彩”, “色”}
returns true if a string can be parsed as an integer or float
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.
Generates a random string of length n. Defaults to n = 10
Examples
random(33) # dv9hUn7rfnKOtLkOebBkfaUEmWMND522V
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, }
Same as reverse_consume/2
except returns values/throws error instead of returning tuple
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”
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”
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