Skip to content
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

Deprecate Ember.Inflector, Ember.String.singularize() and Ember.String.pluralize() #131

Merged
merged 3 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ ember install ember-inflector

## Usage

All methods are always available from `Ember.Inflector`, but in Ember CLI, you can always `import` instead:
All methods are always available from the `ember-inflector` module:

```javascript
import Inflector from 'ember-inflector';
import {singularize, pluralize} from 'ember-inflector';
import { singularize, pluralize } from 'ember-inflector';

Inflector.inflector.singularize("tacos"); // taco
Inflector.inflector.pluralize("taco"); // tacos

singularize("tacos"); // taco
pluralize("taco"); // tacos

// or if not using Ember CLI/ES6
Ember.Inflector.inflector.pluralize("taco"); // tacos
```

### Template Helpers
Expand Down
35 changes: 32 additions & 3 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,39 @@ import {
} from "./lib/system";

Inflector.defaultRules = defaultRules;
Ember.Inflector = Inflector;

Ember.String.pluralize = pluralize;
Ember.String.singularize = singularize;
Object.defineProperty(Ember, 'Inflector', {
get() {
Ember.deprecate(`Ember.Inflector is deprecated. Please explicitly: import Inflector from 'ember-inflector';`, false, {
id: 'ember-inflector.globals',
until: '3.0.0',
});

return Inflector;
},
});

Object.defineProperty(Ember.String, 'singularize', {
get() {
Ember.deprecate(`Ember.String.singularize() is deprecated. Please explicitly: import { singularize } from 'ember-inflector';`, false, {
id: 'ember-inflector.globals',
until: '3.0.0',
});

return singularize;
},
});

Object.defineProperty(Ember.String, 'pluralize', {
get() {
Ember.deprecate(`Ember.String.pluralize() is deprecated. Please explicitly: import { pluralize } from 'ember-inflector';`, false, {
id: 'ember-inflector.globals',
until: '3.0.0',
});

return pluralize;
},
});

import "./lib/ext/string";

Expand Down
30 changes: 24 additions & 6 deletions addon/lib/ext/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,35 @@ if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.String) {
@method pluralize
@for String
*/
String.prototype.pluralize = function() {
return pluralize(this);
};
Object.defineProperty(String.prototype, 'pluralize', {
get() {
Ember.deprecate(`String.prototype.pluralize() is deprecated. Please explicitly: import { pluralize } from 'ember-inflector';`, false, {
id: 'ember-inflector.globals',
until: '3.0.0',
});

return function() {
return pluralize(this);
};
},
});

/**
See {{#crossLink "Ember.String/singularize"}}{{/crossLink}}

@method singularize
@for String
*/
String.prototype.singularize = function() {
return singularize(this);
};
Object.defineProperty(String.prototype, 'singularize', {
get() {
Ember.deprecate(`String.prototype.singularize() is deprecated. Please explicitly: import { singularize } from 'ember-inflector';`, false, {
id: 'ember-inflector.globals',
until: '3.0.0',
});

return function() {
return singularize(this);
};
},
});
}