# ng-pluralize

> Angular project to pluralize and singularize any word

Latest version **1.3.0** (published 2023-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng-pluralize
pnpm add ng-pluralize
yarn add ng-pluralize
bun add ng-pluralize
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2023-08-27 |
| First published | 2020-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Unpacked size | 105.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | jrquick |
| Keywords | angular, plural, plurals, pluralize, singular, singularize, inflection |

## Links

- npm: https://www.npmjs.com/package/ng-pluralize
- Repository: https://github.com/jrquick17/ng-pluralize
- Homepage: https://ng-pluralize.jrquick.com
- Issues: https://github.com/jrquick17/ng-pluralize/issues
- npm.io page: https://npm.io/package/ng-pluralize

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Recent versions

- 1.3.0 (latest) — 2023-08-27
- 1.2.0 — 2023-08-27
- 1.1.1 — 2023-08-25
- 1.1.0 — 2021-08-09
- 1.0.1 — 2021-08-09
- 1.0.0 — 2020-10-16
- 0.0.4 — 2020-10-16
- 0.0.3 — 2020-10-16
- 0.0.1 — 2020-10-16

## README

# ng-pluralize #

[![npm](https://img.shields.io/npm/l/ng-pluralize.svg)](https://www.npmjs.com/package/ng-pluralize/)
[![npm](https://img.shields.io/npm/dt/ng-pluralize.svg)](https://www.npmjs.com/package/ng-pluralize)
[![npm](https://img.shields.io/npm/dm/ng-pluralize.svg)](https://www.npmjs.com/package/ng-pluralize)

![](example.gif)

## Index ##

* [About](#about)
* [Setup](#setup)
* [Usage](#usage)
* [Documentation](#documentation)
* [Contributing](#contributing)
* [Issues](#issues)
* [Deploy](#deploy)

## About ## 

An Angular 2+ module to pluralize and singularize any word.

* Try out [the demo](https://ng-pluralize.jrquick.com) to see it in action!
* Visit [my website](https://jrquick.com) for other cool projects!

## Setup ##

### Install Node ###

```
npm install ng-pluralize --save
```

### Import module ###

* Import `NgPluralizeModule` by 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 ###

```typescript
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 pluralize
    * `count: number` - How many of the word exist
    * `inclusive: boolean` - Whether to prefix with the number (e.g. 3 ducks)

## Contributing ##

### Thanks ###

* [blakeembrey](https://github.com/blakeembrey)
* [jrquick17](https://github.com/jrquick17)

## Issues ##

If you find any issues feel free to open a request in [the Issues tab](https://github.com/jrquick17/ng-pluralize/issues). 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 install` to get packages required for the demo and then run `npm run demo` to run locally.

### Generate Docs ###

* Run `npm run docs:build`

#### Update Version ###
    
* Update version `package.json` files in both the root and `dist/` directory following [Semantic Versioning (2.0.0)](https://semver.org/).

### Build ###

* Run `npm run build` from root.

#### Test ####

* Run `npm run build:link` in root directory
* Run `npm link ng-pluralize` in `demo/` or any external project
* Run Demo [See: Demo](#demo)
* When done, run `npm unlink ng-pluralize` in `demo/` or any external project

#### NPM Release ####

* Run `npm publish` from `dist/` directory.

#### Update Changelog ####

* Add updates to `CHANGELOG.md` in root.

## License

MIT

---
_Source: https://npm.io/package/ng-pluralize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
