An open API service indexing awesome lists of open source software.

https://github.com/kalpeshsingh/pluraljs

A micro library to produce any singular noun into plural
https://github.com/kalpeshsingh/pluraljs

inflections noun plural singular words

Last synced: 3 months ago
JSON representation

A micro library to produce any singular noun into plural

Awesome Lists containing this project

README

          





PluralJS



npm version

File size

npm downloads

A micro library to produce any singular noun into plural

### πŸ’‘ Motive
---
I was curious to learn about how to build a library, what are the thought-processes behind it, what are the technical stuff you need to know etc. This was the primary reason PluralJS came into conception.

### πŸ“₯ Installation

---

**via npm**

```shell
npm install pluraljs --save
```

**via yarn**

```shell
yarn add pluraljs
```

**via CDN direct link**

```html

```

**direct download**

```shell
curl -o https://unpkg.com/pluraljs/dist/pluraljs.umd.min.js
```

### πŸ“‘ Usage

---

The PluralJS is single responsibility library.
It takes only a noun (with optional count parameter) and produce plural noun out of it.

#### API

| parameter | description | type | required | example |
| --------- | --------------------------------- | ------ | -------- | ---------------------------------------------------------- |
| word | a word to pluralize | string | yes | pluralJs('cat') // cats |
| count | pluralize the word based on count | number | no | pluralJs('cat', 3) // cats
pluralJs('cat', 1) // cat |

#### Node

```node
const pluralJs = require('pluraljs');
console.log(pluralJs('cat')); // cats

console.log(pluralJs('cat', 1)); // cat
console.log(pluralJs('cat', 3)); // cats
```

#### ES6

```js
import pluraJs from 'pluraljs';
console.log(pluralJs('cat')); // cats

console.log(pluralJs('cat', -4)); // cat
```

#### Browser

```html

console.log(pluralJs('cat')); // cats
console.log(pluralJs('cat', '4')); // cats

```

### 🧑 Show little more care in your product

---

| Product without words pluralization | Product using PluralJS |
| -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Screenshot - Product not using PluralJS | Screenshot - Product using PluralJS |

### πŸ“‹ Changelog

---

**1.1.0**

- `ENHANCEMENT` Added ability to pass count parameter

**1.0.0**

- `FEATURE` Released first stable version

### πŸ’‚β€β™‚οΈMaintainer

---

Kalpesh Singh ([@knowkalpesh](https://twitter.com/knowkalpesh))

### πŸ™‡ Credits

---

- The core logic and testing file are borrowed from [Blake Embrey](https://github.com/blakeembrey)'s [Pluralize](https://github.com/blakeembrey/pluralize)
- Card screenshot used from [Chakra UI](https://chakra-ui.com/)
- Those lovely cats artwork used for branding is from [Undraw](https://undraw.co/)

### βš–οΈ License

---

kalpeshsingh/PluralJS is licensed under the [MIT license](https://opensource.org/licenses/MIT).