https://github.com/emberjs/ember-inflector
ember-inflector goal is to be rails compatible.
https://github.com/emberjs/ember-inflector
Last synced: about 1 year ago
JSON representation
ember-inflector goal is to be rails compatible.
- Host: GitHub
- URL: https://github.com/emberjs/ember-inflector
- Owner: emberjs
- License: mit
- Created: 2012-08-06T13:59:39.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T08:58:42.000Z (over 1 year ago)
- Last Synced: 2024-10-29T15:44:46.428Z (over 1 year ago)
- Language: JavaScript
- Size: 1.88 MB
- Stars: 106
- Watchers: 18
- Forks: 80
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Ember Inflector [](https://github.com/emberjs/ember-inflector/actions/)
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.
## Compatibility
- Ember.js v3.16 or above
- Embroider or ember-auto-import v2
## Installation
```
ember install ember-inflector
```
## Usage
All methods are always available from the `ember-inflector` module:
```javascript
import Inflector 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
pluralize(2, "taco"); // 2 tacos
pluralize(2, "tacos", { withoutCount: true }); // tacos
```
### Custom Rules
If necessary you can setup special inflection rules for your application:
```javascript
import Inflector from 'ember-inflector';
Inflector.inflector.irregular('person', 'people');
Inflector.inflector.uncountable('sheep');
```
### Template Helpers
#### pluralize
Pluralize a word
```hbs
{{pluralize "taco"}} -> tacos
```
Specify a count with the word, with the pluralization being based on the number of items.
```hbs
{{pluralize 1 "taco"}} -> 1 taco
{{pluralize 2 "taco"}} -> 2 tacos
```
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.
```hbs
{{pluralize 1 "taco" without-count=true}} -> taco
{{pluralize 2 "taco" without-count=true}} -> tacos
```
#### singularize
```hbs
{{singularize 'octopi'}} -> octopus
```
## Contributing
See the [Contributing](CONTRIBUTING.md) guide for details.
## License
This project is licensed under the [MIT License](LICENSE.md).