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

smart-plurals

v1.1.0

Published

A collection of language-specific rules for determining the plurality of a number

Downloads

1,606

Readme

Smart.Plurals

A collection of language-specific rules for determining the plurality of a number. These rules are designed to help with the localization of your application.

The library is small and simple, minified and gzipped to under 500b.

Examples

For example, English has 2 plural forms - 1 is singular, all other values are plural:

var english = Smart.Plurals.getRule('en');
english(0, [ 'singular', 'plural'  ]); // returns 'plural'
english(1, [ 'singular', 'plural'  ]); // returns 'singular'
english(2, [ 'singular', 'plural'  ]); // returns 'plural'

However, many languages have different rules, and some even have 3 or 4 different plural forms. For example, Russian has 3 plural forms - numbers ending with 1 (such as 21, 31, 41) are singular; numbers ending in 2-4 (22, 23, 24) are "few", and all others are plural:

// (TODO: Improve this example with actual Russian words)
var russian = Smart.Plurals.getRule('ru');
russian(91, [ 'singular', 'few', 'plural' ]); // returns 'singular'
russian(94, [ 'singular', 'few', 'plural' ]); // returns 'few'
russian(99, [ 'singular', 'few', 'plural' ]); // returns 'plural'

Download

This library is designed to be tiny, has no dependencies, and should be very easy to integrate into any application. This library comes in 3 flavors; standalone, Angular, and Node.

Standalone

This standalone library exposes the API on the Smart.Plurals namespace. It has no additional dependencies.

Usage:

var pluralRule = Smart.Plurals.getRule('en');

Using with Node

This is the same as the standalone build, but exports the entire Smart object.

Usage:

var Smart = require('smart-plurals');
var pluralRule = Smart.Plurals.getRule('en');
...

Using with Angular

This build exposes a smart module with a SmartPlurals service. It also includes a plural filter.

Usage:

angular.module('example', [ 'smart' ]).run(function(SmartPlurals) {
    var pluralRule = SmartPlurals.getRule('en');
    ...
});
<span> There {{ value | plural:"is":"are" }} {{ value }} {{ value | plural:"item":"items" }} remaining... </span>

Supported languages:

  • Germanic family ** English, German, Dutch, Swedish, Danish, Norwegian, Faroese
  • Romanic family ** Spanish, Portuguese, Italian, Bulgarian
  • Latin/Greek family ** Greek
  • Finno-Ugric family ** Finnish, Estonian
  • Semitic family ** Hebrew
  • Artificial ** Esperanto
  • Finno-Ugric family ** Hungarian
  • Turkic/Altaic family ** Turkish
  • Slavic family ** Czech, Slovak
  • Romanic family ** French, Brazilian Portuguese
  • Celtic ** Gaeilge (Irish)
  • Baltic family ** Latvian
  • Baltic family ** Lithuanian
  • Slavic family ** Polish
  • Romanic family ** Romanian
  • Slavic family ** Russian, Ukrainian, Serbian, Croatian
  • Slavic family ** Slovenian