String

Ember.String Namespace

PUBLIC

Defined in: packages/ember-runtime/lib/system/string.js:121

Module: ember-runtime

Defines string helper methods including string formatting and localization. Unless EmberENV.EXTEND_PROTOTYPES.String is false these methods will also be added to the String.prototype as well.

camelize (str) Stringpublic

Defined in packages/ember-runtime/lib/system/string.js:240

Returns the lowerCamelCase form of a string.

'innerHTML'.camelize();          // 'innerHTML'
'action_name'.camelize();        // 'actionName'
'css-class-name'.camelize();     // 'cssClassName'
'my favorite items'.camelize();  // 'myFavoriteItems'
'My Favorite Items'.camelize();  // 'myFavoriteItems'
'private-docs/owner-invoice'.camelize(); // 'privateDocs/ownerInvoice'

Parameters:

str String
The string to camelize.

Returns:

String
the camelized string.

capitalize (str) Stringpublic

Defined in packages/ember-runtime/lib/system/string.js:296

Returns the Capitalized form of a string

'innerHTML'.capitalize()         // 'InnerHTML'
'action_name'.capitalize()       // 'Action_name'
'css-class-name'.capitalize()    // 'Css-class-name'
'my favorite items'.capitalize() // 'My favorite items'
'privateDocs/ownerInvoice'.capitalize(); // 'PrivateDocs/ownerInvoice'

Parameters:

str String
The string to capitalize.

Returns:

String
The capitalized string.

classify (str) Stringpublic

Defined in packages/ember-runtime/lib/system/string.js:259

Returns the UpperCamelCase form of a string.

'innerHTML'.classify();          // 'InnerHTML'
'action_name'.classify();        // 'ActionName'
'css-class-name'.classify();     // 'CssClassName'
'my favorite items'.classify();  // 'MyFavoriteItems'
'private-docs/owner-invoice'.classify(); // 'PrivateDocs/OwnerInvoice'

Parameters:

str String
the string to classify

Returns:

String
the classified string

dasherize (str) Stringpublic

Defined in packages/ember-runtime/lib/system/string.js:222

Replaces underscores, spaces, or camelCase with dashes.

'innerHTML'.dasherize();          // 'inner-html'
'action_name'.dasherize();        // 'action-name'
'css-class-name'.dasherize();     // 'css-class-name'
'my favorite items'.dasherize();  // 'my-favorite-items'
'privateDocs/ownerInvoice'.dasherize(); // 'private-docs/owner-invoice'

Parameters:

str String
The string to dasherize.

Returns:

String
the dasherized string.

decamelize (str) Stringpublic

Defined in packages/ember-runtime/lib/system/string.js:205

Converts a camelized string into all lower case separated by underscores.

'innerHTML'.decamelize();           // 'inner_html'
'action_name'.decamelize();        // 'action_name'
'css-class-name'.decamelize();     // 'css-class-name'
'my favorite items'.decamelize();  // 'my favorite items'

Parameters:

str String
The string to decamelize.

Returns:

String
the decamelized string.

fmt (str, formats) Stringdeprecatedpublic

Defined in packages/ember-runtime/lib/system/string.js:132

Use ES6 template strings instead: http://babeljs.io/docs/learn-es2015/#template-strings

Apply formatting options to the string. This will look for occurrences of "%@" in your string and substitute them with the arguments you pass into this method. If you want to control the specific order of replacement, you can add a number after the key as well to indicate which argument you want to insert.

Ordered insertions are most useful when building loc strings where values you need to insert may appear in different orders.

"Hello %@ %@".fmt('John', 'Doe');     // "Hello John Doe"
"Hello %@2, %@1".fmt('John', 'Doe');  // "Hello Doe, John"

Parameters:

str String
The string to format
formats Array
An array of parameters to interpolate into string.

Returns:

String
formatted string

htmlSafeHandlebars.SafeStringpublicstatic

Defined in packages/ember-glimmer/lib/utils/string.js:76

Mark a string as safe for unescaped output with Ember templates. If you return HTML from a helper, use this function to ensure Ember's rendering layer does not escape the HTML.

Ember.String.htmlSafe('<div>someString</div>')

Returns:

Handlebars.SafeString
A string that will not be HTML escaped by Handlebars.

isHTMLSafeBooleanpublicstatic

Defined in packages/ember-glimmer/lib/utils/string.js:100

Detects if a string was decorated using Ember.String.htmlSafe.

var plainString = 'plain string',
    safeString = Ember.String.htmlSafe('<div>someValue</div>');

Ember.String.isHTMLSafe(plainString); // false
Ember.String.isHTMLSafe(safeString);  // true

Returns:

Boolean
`true` if the string was decorated with `htmlSafe`, `false` otherwise.

loc (str, formats) Stringpublic

Defined in packages/ember-runtime/lib/system/string.js:156

Formats the passed string, but first looks up the string in the localized strings hash. This is a convenient way to localize text. See Ember.String.fmt() for more information on formatting.

Note that it is traditional but not required to prefix localized string keys with an underscore or other character so you can easily identify localized strings.

Ember.STRINGS = {
  '_Hello World': 'Bonjour le monde',
  '_Hello %@ %@': 'Bonjour %@ %@'
};

Ember.String.loc("_Hello World");  // 'Bonjour le monde';
Ember.String.loc("_Hello %@ %@", ["John", "Smith"]);  // "Bonjour John Smith";

Parameters:

str String
The string to format
formats Array
Optional array of parameters to interpolate into string.

Returns:

String
formatted string

underscore (str) Stringpublic

Defined in packages/ember-runtime/lib/system/string.js:277

More general than decamelize. Returns the lower_case_and_underscored form of a string.

'innerHTML'.underscore();          // 'inner_html'
'action_name'.underscore();        // 'action_name'
'css-class-name'.underscore();     // 'css_class_name'
'my favorite items'.underscore();  // 'my_favorite_items'
'privateDocs/ownerInvoice'.underscore(); // 'private_docs/owner_invoice'

Parameters:

str String
The string to underscore.

Returns:

String
the underscored string.

w (str) Arraypublic

Defined in packages/ember-runtime/lib/system/string.js:183

Splits a string into separate units separated by spaces, eliminating any empty strings in the process. This is a convenience method for split that is mostly useful when applied to the String.prototype.

Ember.String.w("alpha beta gamma").forEach(function(key) {
  console.log(key);
});

// > alpha
// > beta
// > gamma

Parameters:

str String
The string to split

Returns:

Array
array containing the split strings

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/classes/Ember.String.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部