@phensley/plurals
Advanced tools
Comparing version 1.2.13 to 1.2.14
@@ -5,3 +5,3 @@ import { cardinalRules, expressions, ordinalRules } from './autogen.rules'; | ||
var resolve = function (r, language, region) { | ||
return (region ? r[language + "-" + region] : undefined) || r[language] || r.root; | ||
return (region ? r["".concat(language, "-").concat(region)] : undefined) || r[language] || r.root; | ||
}; | ||
@@ -8,0 +8,0 @@ /** |
@@ -6,3 +6,3 @@ import { Decimal } from '@phensley/decimal'; | ||
export declare const digitCount: (w: number) => number; | ||
export declare type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
export type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
/** | ||
@@ -9,0 +9,0 @@ * Operands for use in evaluating localized plural rules: |
@@ -5,23 +5,23 @@ /** | ||
export var digitCount = function (w) { | ||
if (w < 10000 /* P4 */) { | ||
if (w < 100 /* P2 */) { | ||
return w < 10 /* P1 */ ? 1 : 2; | ||
if (w < 10000 /* Constants.P4 */) { | ||
if (w < 100 /* Constants.P2 */) { | ||
return w < 10 /* Constants.P1 */ ? 1 : 2; | ||
} | ||
return w < 1000 /* P3 */ ? 3 : 4; | ||
return w < 1000 /* Constants.P3 */ ? 3 : 4; | ||
} | ||
if (w < 1000000 /* P6 */) { | ||
return w < 100000 /* P5 */ ? 5 : 6; | ||
if (w < 1000000 /* Constants.P6 */) { | ||
return w < 100000 /* Constants.P5 */ ? 5 : 6; | ||
} | ||
return w < 10000000 /* P7 */ ? 7 : 8; | ||
return w < 10000000 /* Constants.P7 */ ? 7 : 8; | ||
}; | ||
var POWERS10 = [ | ||
1 /* P0 */, | ||
10 /* P1 */, | ||
100 /* P2 */, | ||
1000 /* P3 */, | ||
10000 /* P4 */, | ||
100000 /* P5 */, | ||
1000000 /* P6 */, | ||
10000000 /* P7 */, | ||
100000000 /* P8 */, | ||
1 /* Constants.P0 */, | ||
10 /* Constants.P1 */, | ||
100 /* Constants.P2 */, | ||
1000 /* Constants.P3 */, | ||
10000 /* Constants.P4 */, | ||
100000 /* Constants.P5 */, | ||
1000000 /* Constants.P6 */, | ||
10000000 /* Constants.P7 */, | ||
100000000 /* Constants.P8 */, | ||
]; | ||
@@ -67,3 +67,3 @@ // When a number crosses this limit we reduce it to avoid overflow. | ||
// const dec = exp < 0; | ||
var precision = last * 7 /* RDIGITS */ + digitCount(data[last]); | ||
var precision = last * 7 /* Constants.RDIGITS */ + digitCount(data[last]); | ||
// Local operands | ||
@@ -89,3 +89,3 @@ var n = 0; | ||
var r = data[x]; | ||
var c = x !== last ? 7 /* RDIGITS */ : digitCount(r); | ||
var c = x !== last ? 7 /* Constants.RDIGITS */ : digitCount(r); | ||
y = c - 1; | ||
@@ -158,3 +158,3 @@ // Scan each decimal digit of the radix number from | ||
var _this = this; | ||
return FIELDS.map(function (f) { return f + ": " + _this[f]; }).join(', '); | ||
return FIELDS.map(function (f) { return "".concat(f, ": ").concat(_this[f]); }).join(', '); | ||
}; | ||
@@ -161,0 +161,0 @@ return NumberOperands; |
import { Decimal, DecimalArg } from '@phensley/decimal'; | ||
import { NumberOperands } from './operands'; | ||
import { Expr, Rule } from './types'; | ||
export declare type RuleMap = { | ||
export type RuleMap = { | ||
[x: string]: Rule[]; | ||
}; | ||
export declare type RangeMap = number | { | ||
export type RangeMap = number | { | ||
[x: number]: number; | ||
}; | ||
export declare type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
export type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
/** | ||
@@ -12,0 +12,0 @@ * Set of all cardinal and ordinal plural rules, and the array of expression |
@@ -1,2 +0,2 @@ | ||
export declare type RangeList = Array<number | Range>; | ||
export type RangeList = Array<number | Range>; | ||
export interface Range { | ||
@@ -12,4 +12,4 @@ [0]: number; | ||
} | ||
export declare type AndCond = Array<Expr>; | ||
export declare type OrCond = Array<AndCond>; | ||
export type AndCond = Array<Expr>; | ||
export type OrCond = Array<AndCond>; | ||
export interface Rule { | ||
@@ -19,4 +19,4 @@ [0]: number; | ||
} | ||
export declare type RuleMap = { | ||
export type RuleMap = { | ||
[x: string]: Rule[]; | ||
}; |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pluralRules = exports.Plurals = void 0; | ||
var autogen_rules_1 = require("./autogen.rules"); | ||
@@ -7,3 +8,3 @@ var autogen_ranges_1 = require("./autogen.ranges"); | ||
var resolve = function (r, language, region) { | ||
return (region ? r[language + "-" + region] : undefined) || r[language] || r.root; | ||
return (region ? r["".concat(language, "-").concat(region)] : undefined) || r[language] || r.root; | ||
}; | ||
@@ -10,0 +11,0 @@ /** |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pluralRanges = void 0; | ||
exports.pluralRanges = { | ||
@@ -8,0 +9,0 @@ af: 5, |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.expressions = exports.ordinalRules = exports.cardinalRules = void 0; | ||
exports.cardinalRules = { | ||
@@ -8,0 +9,0 @@ af: [[1, [[0]]]], |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PluralRules = exports.NumberOperands = exports.Plurals = exports.pluralRules = void 0; | ||
var api_1 = require("./api"); | ||
exports.pluralRules = api_1.pluralRules; | ||
exports.Plurals = api_1.Plurals; | ||
Object.defineProperty(exports, "pluralRules", { enumerable: true, get: function () { return api_1.pluralRules; } }); | ||
Object.defineProperty(exports, "Plurals", { enumerable: true, get: function () { return api_1.Plurals; } }); | ||
var operands_1 = require("./operands"); | ||
exports.NumberOperands = operands_1.NumberOperands; | ||
Object.defineProperty(exports, "NumberOperands", { enumerable: true, get: function () { return operands_1.NumberOperands; } }); | ||
var rules_1 = require("./rules"); | ||
exports.PluralRules = rules_1.PluralRules; | ||
Object.defineProperty(exports, "PluralRules", { enumerable: true, get: function () { return rules_1.PluralRules; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ import { Decimal } from '@phensley/decimal'; | ||
export declare const digitCount: (w: number) => number; | ||
export declare type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
export type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
/** | ||
@@ -9,0 +9,0 @@ * Operands for use in evaluating localized plural rules: |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NumberOperands = exports.digitCount = void 0; | ||
/** | ||
* Returns the number of digits in w, where w < RADIX. | ||
*/ | ||
exports.digitCount = function (w) { | ||
if (w < 10000 /* P4 */) { | ||
if (w < 100 /* P2 */) { | ||
return w < 10 /* P1 */ ? 1 : 2; | ||
var digitCount = function (w) { | ||
if (w < 10000 /* Constants.P4 */) { | ||
if (w < 100 /* Constants.P2 */) { | ||
return w < 10 /* Constants.P1 */ ? 1 : 2; | ||
} | ||
return w < 1000 /* P3 */ ? 3 : 4; | ||
return w < 1000 /* Constants.P3 */ ? 3 : 4; | ||
} | ||
if (w < 1000000 /* P6 */) { | ||
return w < 100000 /* P5 */ ? 5 : 6; | ||
if (w < 1000000 /* Constants.P6 */) { | ||
return w < 100000 /* Constants.P5 */ ? 5 : 6; | ||
} | ||
return w < 10000000 /* P7 */ ? 7 : 8; | ||
return w < 10000000 /* Constants.P7 */ ? 7 : 8; | ||
}; | ||
exports.digitCount = digitCount; | ||
var POWERS10 = [ | ||
1 /* P0 */, | ||
10 /* P1 */, | ||
100 /* P2 */, | ||
1000 /* P3 */, | ||
10000 /* P4 */, | ||
100000 /* P5 */, | ||
1000000 /* P6 */, | ||
10000000 /* P7 */, | ||
100000000 /* P8 */, | ||
1 /* Constants.P0 */, | ||
10 /* Constants.P1 */, | ||
100 /* Constants.P2 */, | ||
1000 /* Constants.P3 */, | ||
10000 /* Constants.P4 */, | ||
100000 /* Constants.P5 */, | ||
1000000 /* Constants.P6 */, | ||
10000000 /* Constants.P7 */, | ||
100000000 /* Constants.P8 */, | ||
]; | ||
@@ -68,3 +70,3 @@ // When a number crosses this limit we reduce it to avoid overflow. | ||
// const dec = exp < 0; | ||
var precision = last * 7 /* RDIGITS */ + exports.digitCount(data[last]); | ||
var precision = last * 7 /* Constants.RDIGITS */ + (0, exports.digitCount)(data[last]); | ||
// Local operands | ||
@@ -90,3 +92,3 @@ var n = 0; | ||
var r = data[x]; | ||
var c = x !== last ? 7 /* RDIGITS */ : exports.digitCount(r); | ||
var c = x !== last ? 7 /* Constants.RDIGITS */ : (0, exports.digitCount)(r); | ||
y = c - 1; | ||
@@ -159,3 +161,3 @@ // Scan each decimal digit of the radix number from | ||
var _this = this; | ||
return FIELDS.map(function (f) { return f + ": " + _this[f]; }).join(', '); | ||
return FIELDS.map(function (f) { return "".concat(f, ": ").concat(_this[f]); }).join(', '); | ||
}; | ||
@@ -162,0 +164,0 @@ return NumberOperands; |
import { Decimal, DecimalArg } from '@phensley/decimal'; | ||
import { NumberOperands } from './operands'; | ||
import { Expr, Rule } from './types'; | ||
export declare type RuleMap = { | ||
export type RuleMap = { | ||
[x: string]: Rule[]; | ||
}; | ||
export declare type RangeMap = number | { | ||
export type RangeMap = number | { | ||
[x: number]: number; | ||
}; | ||
export declare type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
export type Operand = 'n' | 'i' | 'v' | 'w' | 'f' | 't'; | ||
/** | ||
@@ -12,0 +12,0 @@ * Set of all cardinal and ordinal plural rules, and the array of expression |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.evaluateExpr = exports.PluralRules = void 0; | ||
var decimal_1 = require("@phensley/decimal"); | ||
@@ -7,3 +8,3 @@ var operands_1 = require("./operands"); | ||
var CATEGORIES = ['zero', 'one', 'two', 'few', 'many', 'other']; | ||
var arg = function (n) { return new operands_1.NumberOperands(decimal_1.coerceDecimal(n)); }; | ||
var arg = function (n) { return new operands_1.NumberOperands((0, decimal_1.coerceDecimal)(n)); }; | ||
/** | ||
@@ -58,3 +59,3 @@ * Set of all cardinal and ordinal plural rules, and the array of expression | ||
var expr = this.expressions[cond[j]]; | ||
res = res && exports.evaluateExpr(operands, expr); | ||
res = res && (0, exports.evaluateExpr)(operands, expr); | ||
if (!res) { | ||
@@ -73,3 +74,3 @@ break; | ||
exports.PluralRules = PluralRules; | ||
exports.evaluateExpr = function (operands, expr) { | ||
var evaluateExpr = function (operands, expr) { | ||
var operand = expr[0]; | ||
@@ -98,2 +99,3 @@ var n = operands[operand]; | ||
}; | ||
exports.evaluateExpr = evaluateExpr; | ||
//# sourceMappingURL=rules.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type RangeList = Array<number | Range>; | ||
export type RangeList = Array<number | Range>; | ||
export interface Range { | ||
@@ -12,4 +12,4 @@ [0]: number; | ||
} | ||
export declare type AndCond = Array<Expr>; | ||
export declare type OrCond = Array<AndCond>; | ||
export type AndCond = Array<Expr>; | ||
export type OrCond = Array<AndCond>; | ||
export interface Rule { | ||
@@ -19,4 +19,4 @@ [0]: number; | ||
} | ||
export declare type RuleMap = { | ||
export type RuleMap = { | ||
[x: string]: Rule[]; | ||
}; |
{ | ||
"name": "@phensley/plurals", | ||
"version": "1.2.13", | ||
"version": "1.2.14", | ||
"description": "Plural rules engine", | ||
@@ -39,4 +39,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@phensley/decimal": "~1.2.13", | ||
"tslib": "^1.13.0" | ||
"@phensley/decimal": "~1.2.14", | ||
"tslib": "^2.3.1" | ||
}, | ||
@@ -47,15 +47,15 @@ "devDependencies": { | ||
"@types/node": "^14.0.1", | ||
"@typescript-eslint/eslint-plugin": "^2.33.0", | ||
"@typescript-eslint/parser": "^2.33.0", | ||
"@typescript-eslint/eslint-plugin": "5.55.0", | ||
"@typescript-eslint/parser": "5.55.0", | ||
"beautify-benchmark": "^0.2.4", | ||
"benchmark": "^2.1.4", | ||
"chalk": "^4.0.0", | ||
"eslint": "^7.0.0", | ||
"eslint": "^8.32.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"jest": "^26.0.1", | ||
"jest": "25.5.4", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^25.5.1", | ||
"typescript": "~3.8.3" | ||
"ts-jest": "25.5.1", | ||
"typescript": "4.9.4" | ||
}, | ||
@@ -75,3 +75,3 @@ "jest": { | ||
}, | ||
"gitHead": "1649a9047668bc4519d33526f50174ba3f2e2d32" | ||
"gitHead": "bea64f8ab05fb48af97cfa88b1293e0b17d2ed0d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
249607
3007
- Removedtslib@1.14.1(transitive)
Updated@phensley/decimal@~1.2.14
Updatedtslib@^2.3.1