Ember.Inflector Class node_modules/ember-inflector/addon/lib/system/inflector.js:32


Inflector.Ember provides a mechanism for supplying inflection rules for your application. Ember includes a default set of inflection rules, and provides an API for providing additional rules.

Examples:

Creating an inflector with no rules.

1
var inflector = new Ember.Inflector();

Creating an inflector with the default ember ruleset.

1
2
3
4
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);

inflector.pluralize('cow'); //=> 'kine'
inflector.singularize('kine'); //=> 'cow'

Creating an inflector and adding rules later.

1
2
3
4
5
6
7
8
9
10
11
12
13
var inflector = Ember.Inflector.inflector;

inflector.pluralize('advice'); // => 'advices'
inflector.uncountable('advice');
inflector.pluralize('advice'); // => 'advice'

inflector.pluralize('formula'); // => 'formulas'
inflector.irregular('formula', 'formulae');
inflector.pluralize('formula'); // => 'formulae'

// you would not need to add these as they are the default rules
inflector.plural(/$/, 's');
inflector.singular(/s$/i, '');

Creating an inflector with a nondefault ruleset.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var rules = {
  plurals:  [
    [ /$/, 's' ]
  ],
  singular: [
    [ /\s$/, '' ]
  ],
  irregularPairs: [
    [ 'cow', 'kine' ]
  ],
  uncountable: [ 'fish' ]
};

var inflector = new Ember.Inflector(rules);
Show:

Methods

Show:

disableCache;

public

enableCache

public

inflect

(word, typeRules, irregular) protected

Parameters:

word String
typeRules Object
irregular Object

irregular

(singular, plural)

Parameters:

singular String
plural String

plural

(regex, string)

Parameters:

regex RegExp
string String

pluralize

(word)

Parameters:

word String

purgedCache

public

singular

(regex, string)

Parameters:

regex RegExp
string String

singularize

(word)

Parameters:

word String

uncountable

(regex)

Parameters:

regex String