« All deprecation guides

Deprecation Guide for String prototype extensions

until: 4.0.0
id: ember-string.prototype-extensions

Calling one of the Ember String methods (camelize, capitalize, classify, dasherize, decamelize, htmlSafe, underscore) directly on a string is deprecated.

While Ember addons (ember addon …) have prototype extensions disabled by default, they are enabled for applications (ember new …) making you able to call "Tomster".dasherize(), for example. Instead of calling the method on the string, you should instead import the function from @ember/string.

Before:

let mascot = "Empress Zoey";

mascot.camelize();   //=> "empressZoey"
mascot.capitalize(); //=> "Empress Zoey"
mascot.classify();   //=> "EmpressZoey"
mascot.decamelize(); //=> "empress zoey"
mascot.htmlSafe();   //=> { string: "Empress Zoey" }
mascot.underscore(); //=> "empress_zoey"
mascot.w();          //=> [ "Empress", "Zoey" ]

After:

import  {
  camelize,
  capitalize, 
  classify, 
  decamelize,
  underscore, 
  w, 
} from "@ember/string";
import { htmlSafe } from '@ember/template';

let mascot = "Empress Zoey";

camelize(mascot);   //=> "empressZoey"
capitalize(mascot); //=> "Empress Zoey"
classify(mascot);   //=> "EmpressZoey"
decamelize(mascot); //=> "empress zoey"
htmlSafe(mascot);   //=> { string: "Empress Zoey" }
underscore(mascot); //=> "empress_zoey"
w(mascot);          //=> [ "Empress", "Zoey" ]

You may also instead rely on methods from another library like lodash. Keep in mind that different libraries will behave in slightly different ways, so make sure any critical String transformations are thoroughly tested.

You can also disable String prototype extensions by editing your environment file:

config/environment.js
ENV = {
  EmberENV: {
    EXTEND_PROTOTYPES: {
      Date: false,
      String: false,
    }
  }
}