https://github.com/totaltechgeek/plural-squirrel
https://github.com/totaltechgeek/plural-squirrel
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/totaltechgeek/plural-squirrel
- Owner: TotalTechGeek
- License: mit
- Created: 2022-10-07T14:22:27.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-29T19:00:51.000Z (about 3 years ago)
- Last Synced: 2025-02-01T17:13:46.799Z (over 1 year ago)
- Language: JavaScript
- Size: 42 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Plural Squirrel
[](https://coveralls.io/github/TotalTechGeek/plural-squirrel?branch=master)
Looking for a simple library to handle your pluralization?
Plural Squirrel allows you to write simple templates to handle plural text.
By using `[single|plural|zero]` syntax, you are able to easily simply distinguish how you'd like your string to be formatted for different inputs.
```js
const dogs = plural`The dog[|s] [is|are] hungry.`
console.log(dogs(1)) // The dog is hungry.
console.log(dogs(5)) // The dogs are hungry.
```
You may wish to use additional arguments with your function, or output the number of items. `[#]` will insert the number of items, and `[0]` will refer to the first additional argument passed in.
```js
const bananas = plural`[0] has eaten [#] banana[|s].`
console.log(bananas(1, 'Josh')) // Josh has eaten 1 banana.
console.log(bananas(2, 'Steve')) // Steve has eaten 2 bananas.
```
You may use the `#` symbol the `[single|plural]` syntax as well.
```js
const bananas = plural`[0] has eaten [a|#] banana[|s].`
console.log(bananas(1, 'Josh')) // Josh has eaten a banana.
console.log(bananas(2, 'Steve')) // Steve has eaten 2 bananas.
```