import { Inject , Injectable , InjectionToken , Optional } from '@angular/core' ; export const PLURAL_NAMES_TOKEN = new InjectionToken < { [ name ] : string ; } > ( 'Plural Names' ) ; @ Injectable ( { providedIn : 'root' } ) export class Pluralizer { private pluralNames : { [ name ] : string ; } = { } ; constructor ( @ Optional ( ) @ Inject ( PLURAL_NAMES_TOKEN ) pluralNames ) { if ( pluralNames ) { pluralNames . forEach ( pn => Object . assign ( this . pluralNames , pn ) ) ; } } /**
     * Pluralize a singular name.
     * Examples: "hero" -> "heroes", "villain" -> "villains"
     */ pluralize ( name ) { return this . pluralNames [ name ] || name + 's' ; } }