Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
make-plural
Advanced tools
The make-plural npm package is a utility for handling pluralization rules in various languages. It allows developers to determine the correct plural form of a word based on a given number, which is particularly useful for internationalization (i18n) and localization (l10n) tasks.
Determine Plural Form
This feature allows you to determine the plural form of a word in a specified language based on a given number. In this example, the plural form for English ('en') is determined for the numbers 1 and 2.
const makePlural = require('make-plural');
const plural = makePlural('en');
console.log(plural(1)); // 'one'
console.log(plural(2)); // 'other'
Support for Multiple Languages
This feature demonstrates the package's support for multiple languages. It shows how to determine the plural form for both English and French.
const makePlural = require('make-plural');
const pluralEn = makePlural('en');
const pluralFr = makePlural('fr');
console.log(pluralEn(1)); // 'one'
console.log(pluralEn(2)); // 'other'
console.log(pluralFr(1)); // 'one'
console.log(pluralFr(2)); // 'other'
Custom Plural Rules
This feature allows you to define custom pluralization rules. In this example, custom rules are provided to determine the plural form.
const makePlural = require('make-plural');
const customRules = {
one: 'n == 1',
other: 'true'
};
const pluralCustom = makePlural(customRules);
console.log(pluralCustom(1)); // 'one'
console.log(pluralCustom(2)); // 'other'
The pluralize package provides simple pluralization and singularization of English words. It is less comprehensive than make-plural as it primarily focuses on English and does not support custom rules or multiple languages.
i18next is a powerful internationalization framework that supports pluralization among many other features. It is more comprehensive than make-plural, offering a full suite of i18n tools, but it may be overkill if you only need pluralization.
The messageformat package provides support for handling complex message formatting, including pluralization, gender, and other language-specific rules. It is more feature-rich compared to make-plural, but also more complex to use.
A JavaScript module that translates Unicode CLDR pluralization rules to executable JavaScript.
npm install make-plural
> plurals = require('make-plural')
{ set_rules: [Function], build: [Function] }
> console.log( plurals.build('fr') )
function(n) {
if (n >= 0 && n < 2) return 'one';
return 'other';
}
> console.log( plurals.build('sk') )
function(n) {
var s = String(n).split('.'), i = s[0], v0 = !s[1];
if (n == 1 && v0) return 'one';
if ((i >= 2 && i <= 4) && v0) return 'few';
if (!v0) return 'many';
return 'other';
}
> sk = plurals.build('sk', {'return_function':1})
[Function]
> sk(1)
'one'
> sk(3.0)
'few'
> sk('1.0')
'many'
> sk('0')
'other'
By default, returns a string representation of a function that takes a single
argument n
and returns its plural category for the given locale lc
. The
optional opt
object may contain the following members, each of which is
assumed as false by default:
minify
— if true, the string output of build
is minifiedno_tests
— if true, the generated function is not verified by testing it
with each of the example values included in the CLDR rulesquiet
— if true, no output is reported to console.error
on errorreturn_function
— if true, build
returns an executable function of n
rather than a stringSets the used CLDR rules to cldr
, which may be an object or the path to a JSON
file formatted like this.
By default, the included rules in data/unicode-cldr-plural-rules.json
are
used.
None. CLDR plural rule data is included in JSON format; make-plural supports the LDML Language Plural Rules as used in CLDR release 24 and later.
FAQs
Unicode CLDR pluralization rules as JavaScript functions
The npm package make-plural receives a total of 1,120,743 weekly downloads. As such, make-plural popularity was classified as popular.
We found that make-plural demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.