Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
fast-plural-rules
Advanced tools
Evaluates locale-specific plural rules to identify the right plural form for a cardinal number, which represents an item count.
Evaluates locale-specific plural rules to identify the right plural form for a cardinal number, which represents an item count. Internationalization libraries can utilize it to choose the right localized string.
const { getPluralFormForCardinalByLocale } = require('fast-plural-rules')
// Returns index of the plural form for the specified locale and cardinal.
getPluralFormForCardinalByLocale('en', 1) // Returns 0; "1 file"
getPluralFormForCardinalByLocale('en', 2) // Returns 1; "2 files"
getPluralFormForCardinalByLocale('en', 5) // Returns 1; "5 files"
getPluralFormForCardinalByLocale('cs', 1) // Returns 0; "1 soubor"
getPluralFormForCardinalByLocale('cs', 2) // Returns 1; "2 soubory"
getPluralFormForCardinalByLocale('cs', 5) // Returns 2; "5 souborů"
// English: 0 - singular
// 1 - plural
// Czech: 0 - singular
// 1 - plural for 2-4 items
// 2 - plural for 5+ items
This module can be installed in your project using NPM or Yarn. Make sure, that you use Node.js version 6 or newer.
$ npm i fast-plural-rules --save
$ yarn add fast-plural-rules
Functions are exposed as named exports, for example:
const { getPluralFormForCardinalByLocale } = require('fast-plural-rules')
You can read more about the module loading in other environments, like with ES6 or in web browsers. Usage scenarios demonstrate applications of this library in typical real-world situations. Design concepts explain the approach to the correct internationalization of messages with cardinals taken by this library. Translators will read about plural rules for supported languages to be able to write the right plural forms to language packs. Finally, the API reference lists all functions with a description of their functionality.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Copyright (c) 2018-2019 Ferdinand Prantl
Licensed under the MIT license.
FAQs
Evaluates locale-specific plural rules to identify the right plural form for a cardinal number, which represents an item count.
We found that fast-plural-rules demonstrated a not healthy version release cadence and project activity because the last version was released 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
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.