Class: SC.String

Implements support methods useful when working with strings in SproutCore applications.

Defined in: string.js

Class Methods

Instance Methods

Class Method Detail

capitalizeEach(str)

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.
Parameters:
str String
String to capitalize each letter2
Returns:
String
capitalized string
classify(str)

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.
Parameters:
str String
String to classify
Returns:
String
escapeForRegExp(str)

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.
Parameters:
str String
String to escape for regex
Returns:
String
the string properly escaped for use in a regexp.
humanize(str)

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.
Parameters:
str String
String to humanize
Returns:
String
the humanized string.
pluralize(str)
Converts a word into its plural form.
Defined in: string.js.
Parameters:
str String
String to pluralize
Returns:
String
the plural form of the string
removeDiacritics(str)

Removes any standard diacritic characters from the string. So, for example, all instances of 'Á' will become 'A'.


Defined in: string.js.
Parameters:
str String
String to remove diacritics from
Returns:
String
the modified string
singularize(str)
Converts a word into its singular form.
Defined in: string.js.
Parameters:
str String
String to singularize
Returns:
String
the singular form of the string
titleize(str)

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.
Parameters:
str String
String to titleize
Returns:
String
titleized string.

Instance Method Detail

fmt(string, args)

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
w(str)

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
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:21 GMT-0600 (CST)