Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@phensley/plurals

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@phensley/plurals - npm Package Compare versions

Comparing version 0.22.0 to 0.22.1

6

lib-es/types.d.ts

@@ -1,2 +0,2 @@

import { Decimal } from '@phensley/decimal';
import { Decimal, DecimalArg } from '@phensley/decimal';
import { NumberOperands } from './operands';

@@ -35,4 +35,4 @@ export declare type RuleMap = {

operands(d: Decimal): NumberOperands;
cardinal(language: string, n: Decimal): string;
ordinal(language: string, n: Decimal): string;
cardinal(language: string, n: DecimalArg): string;
ordinal(language: string, n: DecimalArg): string;
private evaluate;

@@ -39,0 +39,0 @@ private execute;

@@ -1,2 +0,2 @@

import { Decimal } from '@phensley/decimal';
import { coerceDecimal, Decimal } from '@phensley/decimal';
import { NumberOperands } from './operands';

@@ -47,6 +47,6 @@ // Notation for categories in compact plural rules

PluralRules.prototype.cardinal = function (language, n) {
return this.evaluate(language, new NumberOperands(n), this.cardinals);
return this.evaluate(language, new NumberOperands(coerceDecimal(n)), this.cardinals);
};
PluralRules.prototype.ordinal = function (language, n) {
return this.evaluate(language, new NumberOperands(n), this.ordinals);
return this.evaluate(language, new NumberOperands(coerceDecimal(n)), this.ordinals);
};

@@ -53,0 +53,0 @@ PluralRules.prototype.evaluate = function (language, operands, cache) {

@@ -1,2 +0,2 @@

import { Decimal } from '@phensley/decimal';
import { Decimal, DecimalArg } from '@phensley/decimal';
import { NumberOperands } from './operands';

@@ -35,4 +35,4 @@ export declare type RuleMap = {

operands(d: Decimal): NumberOperands;
cardinal(language: string, n: Decimal): string;
ordinal(language: string, n: Decimal): string;
cardinal(language: string, n: DecimalArg): string;
ordinal(language: string, n: DecimalArg): string;
private evaluate;

@@ -39,0 +39,0 @@ private execute;

@@ -49,6 +49,6 @@ "use strict";

PluralRules.prototype.cardinal = function (language, n) {
return this.evaluate(language, new operands_1.NumberOperands(n), this.cardinals);
return this.evaluate(language, new operands_1.NumberOperands(decimal_1.coerceDecimal(n)), this.cardinals);
};
PluralRules.prototype.ordinal = function (language, n) {
return this.evaluate(language, new operands_1.NumberOperands(n), this.ordinals);
return this.evaluate(language, new operands_1.NumberOperands(decimal_1.coerceDecimal(n)), this.ordinals);
};

@@ -55,0 +55,0 @@ PluralRules.prototype.evaluate = function (language, operands, cache) {

{
"name": "@phensley/plurals",
"version": "0.22.0",
"version": "0.22.1",
"description": "Plural rules engine",

@@ -37,7 +37,7 @@ "main": "lib/index.js",

"dependencies": {
"@phensley/decimal": "0.22.0",
"@phensley/decimal": "0.22.1",
"tslib": "1.10.x"
},
"devDependencies": {
"@types/jest": "^24.0.13",
"@types/jest": "24.0.22",
"@types/node": "^10.14.10",

@@ -47,3 +47,3 @@ "beautify-benchmark": "^0.2.4",

"chalk": "^2.3.2",
"jest": "^24.8.0",
"jest": "24.9.0",
"rimraf": "^3.0.0",

@@ -68,3 +68,3 @@ "ts-jest": "^24.0.2",

},
"gitHead": "84248f89037d075e80bc54c97f896767558ad1ca"
"gitHead": "066b0e34d064067d7353a387216befe4f5f17e14"
}
@phensley/plurals
Standalone CLDR plural rules engine.
## Example
The plural rules engine takes 2 parameters as input: an ISO 639 language code and a number. The number can be a `Decimal`, `number`, or a string containing a valid number.
The [Decimal](https://phensley.github.io/cldr-engine/docs/en/api-decimal) arbitrary precision type is used for evaluating the plural expressions internally.
```typescript
import { Decimal } from '@phensley/decimal';
import { pluralRules } from '@phensley/plurals';
const LANGUAGES = ['en', 'fr', 'lt', 'pl', 'mt'];
const NUMBERS = [
'1e-30',
'0.3333333333e-15',
0,
'0.00',
0.5,
1,
'1.0',
2,
'3.14159',
5,
6,
7,
9,
11,
15,
19,
23,
29,
'100',
'1000000000000',
'1000000000000.0',
'9999999999999999999999919',
'9999999999999999999999999',
'1e30',
];
let s = '';
for (const n of NUMBERS) {
s += `${new Decimal(n).toString().padStart(35)} `;
for (const lang of LANGUAGES) {
const cat = pluralRules.cardinal(lang, n);
s += `${lang} ${cat}`.padEnd(14);
}
s += '\n';
}
console.log(s);
```
```
0.000000000000000000000000000001 en other fr one lt many pl other mt other
0.0000000000000003333333333 en other fr one lt many pl other mt other
0 en other fr one lt other pl many mt few
0.00 en other fr one lt other pl other mt few
0.5 en other fr one lt many pl other mt other
1 en one fr one lt one pl one mt one
1.0 en other fr one lt one pl other mt one
2 en other fr other lt few pl few mt few
3.14159 en other fr other lt many pl other mt other
5 en other fr other lt few pl many mt few
6 en other fr other lt few pl many mt few
7 en other fr other lt few pl many mt few
9 en other fr other lt few pl many mt few
11 en other fr other lt other pl many mt many
15 en other fr other lt other pl many mt many
19 en other fr other lt other pl many mt many
23 en other fr other lt few pl few mt other
29 en other fr other lt few pl many mt other
100 en other fr other lt other pl many mt other
1000000000000 en other fr other lt other pl many mt other
1000000000000.0 en other fr other lt other pl other mt other
9999999999999999999999919 en other fr other lt other pl many mt many
9999999999999999999999999 en other fr other lt few pl many mt other
1000000000000000000000000000000 en other fr other lt other pl many mt other
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc