npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pluralise

v1.0.1

Published

Plurals for the masses.

Downloads

3,239

Readme

pluralise

This package does one thing simply. It does not try to be clever.

This package is considered STABLE therefore may not be updated frequently. It works really well, is small, and there are no open issues. It is used in a number of projects (hence the download count). Please use with all your might but let me know if you find any bugs. Bugs will be fixed and published quickly. :) Thanks, @andychilton.

Install

npm install --save pluralise

Synopsis

Firstly, require the library:

const pluralise = require('pluralise')

There are two functions for two general cases. The first case is when you just want the plural of a word:

pluralise(0, 'book') // -> 'books'
pluralise(1, 'book') // -> 'book'
pluralise(2, 'book') // -> 'books'

Just passing the count and the singular version of the word will result in just the word (if count is 1) or the word plus an s when count is !== 1. ie. for zero or 2 and above.

Other times you want to be specific about what the plural actually is. Since this package contains no logic related to sheep, wolves or lorries then you need to pass it yourself:

pluralise(0, 'wolf', 'wolves') // -> 'wolves'
pluralise(1, 'wolf', 'wolves') // -> 'wolf'
pluralise(2, 'wolf', 'wolves') // -> 'wolves'

The second case is when you want to include the number with the singular/plural. This also has the case where you might want to say something different when you have no things. For example you might say 'no wolves', '1 wolf' or '2 wolves'. Just use the % symbol for where you would like the number to appear:

pluralise.withCount(0, '% wolf', '% wolves', 'no wolves') // -> 'no wolves'
pluralise.withCount(1, '% wolf', '% wolves', 'no wolves') // -> '1 wolf'
pluralise.withCount(2, '% wolf', '% wolves', 'no wolves') // -> '2 wolves'

If you have a regular plural such as 'item' and 'items', then you just miss the plural out. It will take on the singular form with an added 's' (or just pass the singular form twice):

pluralise.withCount(0, '% horse', null, 'no horses') // -> 'no horses'
pluralise.withCount(1, '% horse', null, 'no horses') // -> '1 horse'
pluralise.withCount(2, '% horse', null, 'no horses') // -> '2 horses'

pluralise.withCount(0, '% horse', '% horse', 'no horses') // -> 'no horses'
pluralise.withCount(1, '% horse', '% horse', 'no horses') // -> '1 horse'
pluralise.withCount(2, '% horse', '% horse', 'no horses') // -> '2 horses'

That's all pluralise(Infinity, 'folk').

Lodash

With lodash, you can .partialRight() so that you could create a module such as this:

const lodash = require('lodash')
const pluralise = require('pluralise')

module.exports = {
  cow   : lodash.partialRight(pluralise, 'cow'),
  sheep : lodash.partialRight(pluralise, 'sheep', 'sheep'),
  wolf  : lodash.partialRight(pluralise, 'wolf', 'wolves'),
}

Which you can then use as follows:

const plurals = require('path/to/above-file.js')

const cows = 3

console.log('Farmer Brown has %d %s', cows, plurals.cow(cows))
// -> 'Farmer Brown has 3 cows'

The same can be done withCount:

module.exports = {
  cow   : lodash.partialRight(pluralise.withCount, '% cow', null, 'no cows'),
  sheep : lodash.partialRight(pluralise.withCount, '% sheep', '% sheep', 'no sheep'),
  wolf  : lodash.partialRight(pluralise.withCount, '% wolf', '% wolves', 'no wolves'),
}

Author

$ npx chilts

   ╒════════════════════════════════════════════════════╕
   │                                                    │
   │   Andrew Chilton (Personal)                        │
   │   -------------------------                        │
   │                                                    │
   │          Email : [email protected]             │
   │            Web : https://chilts.org                │
   │        Twitter : https://twitter.com/andychilton   │
   │         GitHub : https://github.com/chilts         │
   │         GitLab : https://gitlab.org/chilts         │
   │                                                    │
   │   Apps Attic Ltd (My Company)                      │
   │   ---------------------------                      │
   │                                                    │
   │          Email : [email protected]              │
   │            Web : https://appsattic.com             │
   │        Twitter : https://twitter.com/AppsAttic     │
   │         GitLab : https://gitlab.com/appsattic      │
   │                                                    │
   │   Node.js / npm                                    │
   │   -------------                                    │
   │                                                    │
   │        Profile : https://www.npmjs.com/~chilts     │
   │           Card : $ npx chilts                      │
   │                                                    │
   ╘════════════════════════════════════════════════════╛

License

MIT - http://chilts.mit-license.org/2015/

(Ends)