Algo.String (Algo v0.1.0)

Copy Markdown View Source

Utility functions for strings.

Summary

Functions

Convert an underscored, camelised, or dasherised string into one that can be read by humans. Also remove beginning and ending whitespace, and removes the postfix '_id'. The first character will be capitalised. For underscored strings, replaces underscores with spaces. For dasherised strings, replaces dashes with spaces. For camelised strings, inserts a space before any occurrence of an uppercase letter that is preceded by a lowercase letter. For identifier-like strings like 'author_id', removes the postfix '_id' and replaces underscores with spaces.

Functions

humanise(str)

@spec humanise(binary()) :: binary()

Convert an underscored, camelised, or dasherised string into one that can be read by humans. Also remove beginning and ending whitespace, and removes the postfix '_id'. The first character will be capitalised. For underscored strings, replaces underscores with spaces. For dasherised strings, replaces dashes with spaces. For camelised strings, inserts a space before any occurrence of an uppercase letter that is preceded by a lowercase letter. For identifier-like strings like 'author_id', removes the postfix '_id' and replaces underscores with spaces.

Examples

iex> Algo.String.humanise("author_id")
"Author"

iex> Algo.String.humanise(" thisIsDDOSAttack ")
"This is DDOS attack"

iex> Algo.String.humanise("")
""

iex> Algo.String.humanise("   ")
""

humanize(str)

Alias for humanise/1.