Package Exports
- ng-pluralize
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ng-pluralize) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ng-pluralize

Index
About
An Angular 2+ module to pluralize and singularize any word.
- Try out the demo to see it in action!
- Visit my website for other cool projects!
Setup
Install Node
npm install ng-pluralize --saveImport module
Import
NgPluralizeModuleby adding the following to your parent module (i.e.app.module.ts):import { NgPluralizeModule } from 'ng-pluralize'; @NgModule({ ... imports: [ NgPluralizeModule, ... ], ... }) export class AppModule {}
Usage
Use Service
import {NgPluralizeService} from 'ng-pluralize';
@Injectable()
export class TechCheckService {
constructor(
private service:NgPluralizeService
) {
// Example: Singularize word
this.service.singularize('dogs'); // dog
// Example: Pluralize word
this.service.pluralize('cat'); // cats
// Example: Singluralize or pluralize based on count
this.service.fromCount('test', 0) //=> "tests"
this.service.fromCount('test', 1) //=> "test"
this.service.fromCount('test', 5) //=> "tests"
this.service.fromCount('test', 1, true) //=> "1 test"
this.service.fromCount('test', 5, true) //=> "5 tests"
this.service.fromCount('蘋果', 2, true) //=> "2 蘋果"
// Example of new plural rule:
this.service.pluralize('regex') //=> "regexes"
this.service.addPluralRule(/gex$/i, 'gexii')
this.service.pluralize('regex') //=> "regexii"
// Example of new singular rule:
this.service.singularize('singles') //=> "single"
this.service.addSingularRule(/singles$/i, 'singular')
this.service.singularize('singles') //=> "singular"
// Example of new irregular rule, e.g. "I" -> "we":
this.service.pluralize('irregular') //=> "irregulars"
this.service.addIrregularRule('irregular', 'regular')
this.service.pluralize('irregular') //=> "regular"
// Example of uncountable rule (rules without singular/plural in context):
this.service.pluralize('paper') //=> "papers"
this.service.addUncountableRule('paper')
this.service.pluralize('paper') //=> "paper"
// Example of asking whether a word looks singular or plural:
this.service.isPlural('test') //=> false
this.service.isSingular('test') //=> true
// Example of adding a token exception whose case should not be restored:
this.service.pluralize('promo ID') //=> 'promo IDS'
this.service.addRestoreCaseException('IDs')
this.service.pluralize('promo ID') //=> 'promo IDs'
}
}Documentation
singularize()- Convert a word into it's singular form (ie dogs to dog)pluralize()- Convert a word into it's plural form (ie cat to cats)fromCount(word, count, inclusive)- Get the current internet speed in KBPS (kilobytes per second).word: string- The word to pluralizecount: number- How many of the word existinclusive: boolean- Whether to prefix with the number (e.g. 3 ducks)
Contributing
Thanks
Issues
If you find any issues feel free to open a request in the Issues tab. If I have the time I will try to solve any issues but cannot make any guarantees. Feel free to contribute yourself.
Deploy
Demo
- Run
npm installto get packages required for the demo and then runnpm run demoto run locally.
Generate Docs
- Run
npm run docs:build
Update Version
- Update version
package.jsonfiles in both the root anddist/directory following Semantic Versioning (2.0.0).
Build
- Run
npm run buildfrom root.
Test
- Copy
dist/contents intodemo/node_modules/ng-pluralize/- Run from root:
cp -fr dist/* demo/node_modules/ng-pluralize/
- Run from root:
- Run
ng servefromdemo/ - Run
ng build --prodfromdemo/
NPM Release
- Run
npm publishfromdist/directory.
Update Changelog
- Add updates to
CHANGELOG.mdin root.
License
MIT