UNPKG

1.62 kBMarkdownView Raw
1# Ember Inflector [![Build Status](https://travis-ci.org/emberjs/ember-inflector.png?branch=master)](https://travis-ci.org/emberjs/ember-inflector)
2
3Ember 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
7Ember CLI/NPM:
8
9```
10npm install --save ember-inflector
11```
12
13## Usage
14
15All methods are always available from `Ember.Inflector`, but in Ember CLI, you can always `import` instead:
16
17```javascript
18import Inflector from 'ember-inflector';
19import {singularize, pluralize} from 'ember-inflector';
20
21Inflector.inflector.singularize("tacos"); // taco
22Inflector.inflector.pluralize("taco"); // tacos
23
24singularize("tacos"); // taco
25pluralize("taco"); // tacos
26
27// or if not using Ember CLI/ES6
28Ember.Inflector.inflector.pluralize("taco"); // tacos
29```
30
31###Template Helpers
32####pluralize
33
34Pluralize a word
35```helpers
36{{pluralize "taco"}} //tacos
37```
38
39Specify a count with the word, with the pluralization being based on the number of items.
40```helpers
41{{pluralize 1 "taco"}} //1 taco
42{{pluralize 2 "taco"}} //2 tacos
43```
44
45Specify 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.
46```helpers
47{{pluralize 1 "taco" without-count=true}} //taco
48{{pluralize 2 "taco" without-count=true}} //tacos
49```
50
51####singularize
52```helpers
53{{singularize 'octopi'}} //octopus
54```