Class String

public

Defines string helper methods including string formatting and localization.

Show:

Module: @ember/string
str
String

The string to camelize.

returns
String

the camelized string.

Returns the lowerCamelCase form of a string.

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'
Module: @ember/string
str
String

The string to capitalize.

returns
String

The capitalized string.

Returns the Capitalized form of a string

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'
Module: @ember/string
str
String

the string to classify

returns
String

the classified string

Returns the UpperCamelCase form of a string.

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'
Module: @ember/string
str
String

The string to dasherize.

returns
String

the dasherized string.

Replaces underscores, spaces, or camelCase with dashes.

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'
Module: @ember/string
str
String

The string to decamelize.

returns
String

the decamelized string.

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

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'
Module: @ember/string
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.

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'
Module: @ember/string
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.

import { w } from '@ember/string';

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

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