1 | # Ember Inflector [![Build Status](https://travis-ci.org/emberjs/ember-inflector.png?branch=master)](https://travis-ci.org/emberjs/ember-inflector)
|
2 |
|
3 | Ember Inflector is a library for inflecting words between plural and singular forms. Ember Inflector aims to be compatible with [ActiveSupport::Inflector](http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html) from Ruby on Rails, including the ability to add your own inflections in your app.
|
4 |
|
5 | ## Installation
|
6 |
|
7 | Ember CLI/NPM:
|
8 |
|
9 | ```
|
10 | npm install --save ember-inflector
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | All methods are always available from `Ember.Inflector`, but in Ember CLI, you can always `import` instead:
|
16 |
|
17 | ```javascript
|
18 | import Inflector from 'ember-inflector';
|
19 | import {singularize, pluralize} from 'ember-inflector';
|
20 |
|
21 | Inflector.inflector.singularize("tacos"); // taco
|
22 | Inflector.inflector.pluralize("taco"); // tacos
|
23 |
|
24 | singularize("tacos"); // taco
|
25 | pluralize("taco"); // tacos
|
26 |
|
27 | // or if not using Ember CLI/ES6
|
28 | Ember.Inflector.inflector.pluralize("taco"); // tacos
|
29 | ```
|
30 |
|
31 | ### Template Helpers
|
32 |
|
33 | #### pluralize
|
34 |
|
35 | Pluralize a word
|
36 | ```helpers
|
37 | {{pluralize "taco"}} //tacos
|
38 | ```
|
39 |
|
40 | Specify a count with the word, with the pluralization being based on the number of items.
|
41 | ```helpers
|
42 | {{pluralize 1 "taco"}} //1 taco
|
43 | {{pluralize 2 "taco"}} //2 tacos
|
44 | ```
|
45 |
|
46 | Specify a count with the word, with the pluralization being based on the number of items. Specify `without-count=true` to return on the word without the number.
|
47 | ```helpers
|
48 | {{pluralize 1 "taco" without-count=true}} //taco
|
49 | {{pluralize 2 "taco" without-count=true}} //tacos
|
50 | ```
|
51 |
|
52 | #### singularize
|
53 | ```helpers
|
54 | {{singularize 'octopi'}} //octopus
|
55 | ```
|