-
-
Notifications
You must be signed in to change notification settings - Fork 69
[RFC#236] Add guide for String prototype extensions deprecation #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1b0e8df
add deprecation guide for String prototype extensions
locks 9b21462
tweak message
locks 7356de3
rename file to remove deprecate prefix
locks 11f5a4b
Update content/ember/v3/ember-string-prototype-extensions.md
locks 78b44e6
Update content/ember/v3/ember-string-prototype-extensions.md
locks 8ff2da9
Update content/ember/v3/ember-string-prototype-extensions.md
locks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
id: ember-string.prototype-extensions | ||
title: Deprecate String prototype extensions | ||
until: '4.0.0' | ||
since: 'Upcoming Features' | ||
--- | ||
|
||
Calling one of the [Ember `String` methods](https://api.emberjs.com/ember/3.22/classes/String) (camelize, capitalize, classify, dasherize, decamelize, 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: | ||
|
||
```js | ||
let mascot = "Empress Zoey"; | ||
|
||
mascot.camelize(); //=> "empressZoey" | ||
mascot.capitalize(); //=> "Empress Zoey" | ||
mascot.classify(); //=> "EmpressZoey" | ||
mascot.decamelize(); //=> "empress zoey" | ||
mascot.underscore(); //=> "empress_zoey" | ||
mascot.w(); //=> [ "Empress", "Zoey" ] | ||
``` | ||
|
||
After: | ||
|
||
```js | ||
import { | ||
camelize, | ||
capitalize, | ||
classify, | ||
decamelize, | ||
underscore, | ||
w, | ||
} from "@ember/string"; | ||
|
||
let mascot = "Empress Zoey"; | ||
|
||
camelize(mascot); //=> "empressZoey" | ||
capitalize(mascot); //=> "Empress Zoey" | ||
classify(mascot); //=> "EmpressZoey" | ||
decamelize(mascot); //=> "empress zoey" | ||
underscore(mascot); //=> "empress_zoey" | ||
w(mascot); //=> [ "Empress", "Zoey" ] | ||
``` | ||
|
||
You may also instead rely on methods from another library like [lodash](https://lodash.com/). | ||
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](https://guides.emberjs.com/release/configuring-ember/disabling-prototype-extensions/) by editing your environment file: | ||
|
||
```js | ||
// config/environment.js | ||
ENV = { | ||
EmberENV: { | ||
EXTEND_PROTOTYPES: { | ||
Date: false, | ||
ijlee2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String: false, | ||
} | ||
} | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.