plural-forms
TypeScript icon, indicating that this package has built-in type declarations

0.5.5 • Public • Published

plural-forms

Provides information about the plural forms from any language that you may know

Installation

yarn add plural-forms
# or
npm install --save plural-forms

Usage example

import { getNPlurals } from 'plural-forms'

const englishPluralsNumber = getNPlurals('en'); // 2 

Available methods

getNPlurals(language: string): number

  • language - language ISO code. Returns the number of plural forms for locale

Example:

import { getNPlurals } from 'plural-forms'

const englishPluralsNumber = getNPlurals('en'); // 2 

getFormula(language: string) : string

  • language - language ISO code. Returns plural form formula for locale

Example:

import { getFormula } from 'plural-forms'

const englishPluralsNumber = getFormula('en'); // "n!==1'"

getPluralFunc(language: string) : function

  • language - language ISO code. Returns function that can compute appropriate form for locale

Example:

import { getPluralFunc } from 'plural-forms'
const fn = getPluralFunc('en')

fn(1, ['banana', 'bananas']) // 'banana'
fn(2, ['banana', 'bananas']) // 'bananas'

hasLang(language: string): boolean

  • language - language ISO code Returns if language definition exists in catalog

Example:

import { hasLang } from 'plural-forms'
hasLang('en') // true
hasLang('zzz') // false

getAvailLangs(): [string]

Returns list with all existing ISO codes of languages from the catalog.

Example

import { getAvailLangs } from 'plural-forms';
getAvailLangs() // [en, uk, ...]

getExamples(language: string): [{ plural: number, sample: number}]

Returns list with examples for plurals.

Example

import { getExamples } from 'plural-forms';
getExamples('uk')
// [ { plural: 0, sample: 1 },
//   { plural: 1, sample: 2 },
//   { plural: 2, sample: 5 } ]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.5.543,938latest

Version History

VersionDownloads (Last 7 Days)Published
0.5.543,938
0.5.341,557
0.5.259
0.5.10
0.5.01
0.4.00
0.3.1029,298
0.3.90
0.3.80
0.3.70
0.3.60
0.3.50
0.3.40
0.3.31,376
0.3.20
0.3.10
0.4.10
0.3.0666
0.2.0194
0.1.20
0.1.00
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i plural-forms

Weekly Downloads

117,089

Version

0.5.5

License

MIT

Unpacked Size

63.9 kB

Total Files

10

Last publish

Collaborators

  • alexander