string_extensions.coffee | |
---|---|
inflect = require('../inflect')
enableStringExtensions = -> | |
Returns the plural form of the word in the string. Examples | String::pluralize = ->
inflect.pluralize(this) |
The reverse of pluralize, returns the singular form of a word in a string. Examples | String::singularize = ->
inflect.singularize(this) |
By default, camelize converts strings to UpperCamelCase. If the argument to camelize is set to false then camelize produces lowerCamelCase. Examples
As a rule of thumb you can think of camelize as the inverse of underscore, though there are cases where that does not hold: | String::camelize = (first_letter_in_uppercase = true) ->
inflect.camelize(this, first_letter_in_uppercase) |
Converts the first character to uppercase and the remainder to lowercase. Examples | String::capitalize = ->
inflect.capitalize(this) |
Capitalizes all the words and replaces some characters in the string to create a nicer looking title. titleize is meant for creating pretty output. Examples | String::titleize = ->
inflect.titleize(this) |
Makes an underscored, lowercase form from the expression in the string. Examples
As a rule of thumb you can think of underscore as the inverse of camelize, though there are cases where that does not hold: | String::underscore = ->
inflect.underscore(this) |
Replaces underscores with dashes in the string. Examples | String::dasherize = ->
inflect.dasherize(this) |
Replaces special characters in a string so that it may be used as part of a 'pretty' URL. Examples | String::parameterize = (sep = '-') ->
inflect.parameterize(this, sep) |
Capitalizes the first word and turns underscores into spaces and strips a trailing "_id", if any. Like titleize, this is meant for creating pretty output. Examples | String::humanize = ->
inflect.humanize(this)
exports.enableStringExtensions = enableStringExtensions
|