Class: SC.String
Implements support methods useful when working with strings in SproutCore applications.
Defined in: string.js
Class Methods
- capitalizeEach(str)
- classify(str)
- escapeForRegExp(str)
- humanize(str)
- pluralize(str)
- removeDiacritics(str)
- singularize(str)
- titleize(str)
Instance Methods
Class Method Detail
Capitalizes every word in a string. Unlike titleize, spaces or dashes will remain in-tact.
Examples
- Input String -> Output String
- my favorite items -> My Favorite Items
- css-class-name -> Css-Class-Name
- action_name ->
Action_Name
innerHTML
-> InnerHTML
Defined in: string.js.
Converts the string into a class name. This method will camelize your string and then capitalize the first letter.
Examples
- Input String -> Output String
- my favorite items -> MyFavoriteItems
- css-class-name -> CssClassName
- action_name -> ActionName
innerHTML
-> InnerHtml
Defined in: string.js.
Will escape a string so it can be securely used in a regular expression.
Useful when you need to use user input in a regular expression without having to worry about it breaking code if any reserved regular expression characters are used.
Defined in: string.js.
Converts a camelized string or a string with dashes or underscores into a string with components separated by spaces.
Examples
- Input String -> Output String
- my favorite items -> my favorite items
- css-class-name -> css class name
- action_name -> action name
innerHTML
-> inner html
Defined in: string.js.
Defined in: string.js.
Removes any standard diacritic characters from the string. So, for example, all instances of 'Á' will become 'A'.
Defined in: string.js.
Defined in: string.js.
Converts a string to a title. This will decamelize the string, convert separators to spaces and capitalize every word.
Examples
- Input String -> Output String
- my favorite items -> My Favorite Items
- css-class-name -> Css Class Name
- action_name -> Action Name
innerHTML
-> Inner HTML
Defined in: string.js.
Instance Method Detail
Formats a string. You can format either with named parameters or indexed, but not both.
Indexed Parameters
Indexed parameters are just arguments you pass into format. For example:
"%@1 %@3 %@2".fmt(1, 2, 3)
// -> "1 3 2"
If you don't supply a number, it will use them in the order you supplied. For example:
"%@, %@".fmt("Iskander", "Alex")
// -> "Iskander, Alex"
Named Paramters
You can use named parameters like this:
"Value: %{key_name}".fmt({ key_name: "A Value" })
// -> "Value: A Value"
You can supply formatters for each field. A formatter is a method to get applied to the parameter:
Currency = function(v) { return "$" + v; };
"Value: %{val}".fmt({ val: 12.00, valFormatter: Currency })
// -> $12.00
Formatters can also use arguments:
Currency = function(v, sign) { return sign + v; };
"Value: %{val:£}".fmt({ val: 12.00, valFormatter: Currency })
// -> £12.00
You can supply a different formatter for each named parameter. Formatters can ONLY be used with named parameters (not indexed parameters).
- Parameters:
- string
- args
Splits the string into words, separated by spaces. Empty strings are removed from the results.
- Parameters:
- str
- Returns:
- Array
- An array of non-empty strings