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

@looop/pluralize

v1.0.4

Published

Pluralize and singularize any word

Downloads

1,238

Readme

Pluralize

NPM version NPM downloads Build status Test coverage File Size CDNJS

Pluralize and singularize any word.

This was forked from https://github.com/plurals/pluralize. It was refactored into TS and there is now a build step added. Everything else remains the same.

Installation

npm install pluralize --save
yarn add pluralize

Node (ES2015 Module)

import pluralize from 'pluralize';

Node

const pluralize = require('pluralize');

AMD

define(function (require, exports, module) {
  const pluralize = require('pluralize');
});

<script> tag

<script src="pluralize.js"></script>

Why?

This module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input. For applications where the word(s) are known ahead of time, you can use a simple ternary (or function) which would be a much lighter alternative.

Usage

  • 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)

Examples:

pluralize('test'); //=> "tests"
pluralize('test', 0); //=> "tests"
pluralize('test', 1); //=> "test"
pluralize('test', 5); //=> "tests"
pluralize('test', 1, true); //=> "1 test"
pluralize('test', 5, true); //=> "5 tests"
pluralize('蘋果', 2, true); //=> "2 蘋果"

// Example of new plural rule:
pluralize.plural('regex'); //=> "regexes"
pluralize.addPluralRule(/gex$/i, 'gexii');
pluralize.plural('regex'); //=> "regexii"

// Example of new singular rule:
pluralize.singular('singles'); //=> "single"
pluralize.addSingularRule(/singles$/i, 'singular');
pluralize.singular('singles'); //=> "singular"

// Example of new irregular rule, e.g. "I" -> "we":
pluralize.plural('irregular'); //=> "irregulars"
pluralize.addIrregularRule('irregular', 'regular');
pluralize.plural('irregular'); //=> "regular"

// Example of uncountable rule (rules without singular/plural in context):
pluralize.plural('paper'); //=> "papers"
pluralize.addUncountableRule('paper');
pluralize.plural('paper'); //=> "paper"

// Example of asking whether a word looks singular or plural:
pluralize.isPlural('test'); //=> false
pluralize.isSingular('test'); //=> true

License

MIT