Casing & Capitalization

Wordsmith provides several methods for case modification:

Case Modification

apTitleize

Intelligently up-cases a string as a headline/title using AP capitalization rules.

{{ 'a tale of two cities' | camelize }}

# "A Tale of Two Cities"

camelize

Returns a camelCase version of the string.

Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores.

{{ 'Camel-Case' | camelize }}

# "camelCase"

dasherize

Returns a lowercase and trimmed string separated by dashes.

Dashes are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as underscores.

{{ 'fooBar' | dasherize }}

# "foo-bar"

entitle

Alias for apTitleize.

Provided so that Wordsmith can be a drop-in replacement for the Entitle plugin.

humanize

Capitalizes the first word of the string, replaces underscores with spaces, and strips away an ‘_id’ suffix if one is present.

{{ 'author_id' | humanize }}

# "Author"
{{ 'some_snake_case_words' | humanize }}

# "Some snake case words"

hyphenate

Alias for dasherize.

Provided so that Wordsmith can be a drop-in replacement for the Inflect and Typogrify plugins.

pascalize

Alias for upperCamelize.

Provided so that Wordsmith can be a drop-in replacement for the Inflect and Typogrify plugins.

slugify

Converts the string into an URL slug.

This includes replacing non-ASCII characters with their closest ASCII equivalents, removing remaining non-ASCII and non-alphanumeric characters, and replacing whitespace with $replacement. The replacement defaults to a single dash, and the string is also converted to lowercase. The language of the source string can also be supplied for language-specific transliteration.

{{ 'Using strings like fòô bàř' | slugify }}

# "using-strings-like-foo-bar"

titleize

Returns a trimmed string with the first letter of each word capitalized.

Also accepts an array, $ignore, allowing you to list words you want to leave un-capitalized.

{{ 'i like to watch television' | titleize }}

# "I Like to Watch Television"

If you’re working with titles in English, you may also be interested in apTitleize, which is a bit more intelligent and follows AP title capitalization rules.

underscore

Returns a lowercase and trimmed string separated by underscores.

Underscores are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as dashes.

{{ 'TestACase' | underscored }}

# "test_a_case"

underscored

Alias for underscore.

Provided for compatibility with Stringy, so that Wordsmith can be a drop-in replacement for the Typogrify plugin.

upperCamelize

Returns an UpperCamelCase version of the supplied string.

It trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, underscores.

{{ 'Upper Camel-Case' | upperCamelize }}

# "UpperCamelCase"