Class String
publicDefines 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) String public
Defined in packages/@ember/string/index.ts:191
- str
- String
- The string to camelize.
- returns
- String
- the camelized string.
Returns the lowerCamelCase form of a string.
1 2 3 4 5 6 7 8 |
import { camelize } from '@ember/string'; camelize('innerHTML'); // 'innerHTML' camelize('action_name'); // 'actionName' camelize('css-class-name'); // 'cssClassName' camelize('my favorite items'); // 'myFavoriteItems' camelize('My Favorite Items'); // 'myFavoriteItems' camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice' |
capitalize (str) String public
Defined in packages/@ember/string/index.ts:259
- str
- String
- The string to capitalize.
- returns
- String
- The capitalized string.
Returns the Capitalized form of a string
1 2 3 4 5 6 7 |
import { capitalize } from '@ember/string'; capitalize('innerHTML') // 'InnerHTML' capitalize('action_name') // 'Action_name' capitalize('css-class-name') // 'Css-class-name' capitalize('my favorite items') // 'My favorite items' capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice' |
classify (str) String public
Defined in packages/@ember/string/index.ts:214
- str
- String
- the string to classify
- returns
- String
- the classified string
Returns the UpperCamelCase form of a string.
1 2 3 4 5 6 7 |
import { classify } from '@ember/string'; classify('innerHTML'); // 'InnerHTML' classify('action_name'); // 'ActionName' classify('css-class-name'); // 'CssClassName' classify('my favorite items'); // 'MyFavoriteItems' classify('private-docs/owner-invoice'); // 'PrivateDocs/OwnerInvoice' |
dasherize (str) String public
Defined in packages/@ember/string/index.ts:169
- str
- String
- The string to dasherize.
- returns
- String
- the dasherized string.
Replaces underscores, spaces, or camelCase with dashes.
1 2 3 4 5 6 7 |
import { dasherize } from '@ember/string'; dasherize('innerHTML'); // 'inner-html' dasherize('action_name'); // 'action-name' dasherize('css-class-name'); // 'css-class-name' dasherize('my favorite items'); // 'my-favorite-items' dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice' |
decamelize (str) String public
Defined in packages/@ember/string/index.ts:148
- str
- String
- The string to decamelize.
- returns
- String
- the decamelized string.
Converts a camelized string into all lower case separated by underscores.
1 2 3 4 5 6 |
import { decamelize } from '@ember/string'; decamelize('innerHTML'); // 'inner_html' decamelize('action_name'); // 'action_name' decamelize('css-class-name'); // 'css-class-name' decamelize('my favorite items'); // 'my favorite items' |
loc (str, formats) String public
Defined in packages/@ember/string/index.ts:87
- str
- String
- The string to format
- formats
- Array
- Optional array of parameters to interpolate into string.
- returns
- String
- formatted string
Formats the passed string, but first looks up the string in the localized strings hash. This is a convenient way to localize text.
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.
1 2 3 4 5 6 7 8 9 |
import { loc } from '@ember/string'; Ember.STRINGS = { '_Hello World': 'Bonjour le monde', '_Hello %@ %@': 'Bonjour %@ %@' }; loc("_Hello World"); // 'Bonjour le monde'; loc("_Hello %@ %@", ["John", "Smith"]); // "Bonjour John Smith"; |
underscore (str) String public
Defined in packages/@ember/string/index.ts:236
- str
- String
- The string to underscore.
- returns
- String
- the underscored string.
More general than decamelize. Returns the lower_case_and_underscored form of a string.
1 2 3 4 5 6 7 |
import { underscore } from '@ember/string'; underscore('innerHTML'); // 'inner_html' underscore('action_name'); // 'action_name' underscore('css-class-name'); // 'css_class_name' underscore('my favorite items'); // 'my_favorite_items' underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice' |
w (str) Array public
Defined in packages/@ember/string/index.ts:122
- str
- String
- The string to split
- returns
- Array
- array containing the split strings
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
.
1 2 3 4 5 6 7 8 9 |
import { w } from '@ember/string'; w("alpha beta gamma").forEach(function(key) { console.log(key); }); // > alpha // > beta // > gamma |