ember-inflector
v7.0.0
Published
String inflections for Ember applications.
Keywords
Readme
Ember Inflector 
Ember Inflector is a library for inflecting words between plural and singular forms. Ember Inflector aims to be compatible with ActiveSupport::Inflector from Ruby on Rails, including the ability to add your own inflections in your app.
Compatibility
- Ember.js v4.8 or above
- Embroider or ember-auto-import v2
Installation
ember install ember-inflectorUsage
All methods are always available from the ember-inflector module:
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 }); // tacosCustom Rules
If necessary you can setup special inflection rules for your application:
import Inflector from 'ember-inflector';
Inflector.inflector.irregular('person', 'people');
Inflector.inflector.uncountable('sheep');
Template Helpers
pluralize
Pluralize a word
{{pluralize "taco"}} -> tacosSpecify a count with the word, with the pluralization being based on the number of items.
{{pluralize 1 "taco"}} -> 1 taco
{{pluralize 2 "taco"}} -> 2 tacosSpecify 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.
{{pluralize 1 "taco" without-count=true}} -> taco
{{pluralize 2 "taco" without-count=true}} -> tacossingularize
{{singularize 'octopi'}} -> octopusTypeScript
Types are published with the addon, so no @types/* package is needed.
If your app is not yet using strict mode templates, register the template helpers with Glint by extending the addon's registry:
import type EmberInflectorRegistry from 'ember-inflector/template-registry';
declare module '@glint/environment-ember-loose/registry' {
export default interface Registry extends EmberInflectorRegistry {}
}Contributing
See the Contributing guide for details.
License
This project is licensed under the MIT License.
