diff --git a/src/cardinals.js b/src/cardinals.js index eb7e215..131cbf1 100644 --- a/src/cardinals.js +++ b/src/cardinals.js @@ -120,7 +120,8 @@ const cardinals = { // everything else: 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29, // 32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 44, 45, 46, 47, 48, 49, 52, 53, // 54, 55, 56, 57, 58, 59, 62, 63, 64, 65, 66, 67, 68, 69, 72, 73, ... - n => n % 10 === 1 && n % 100 !== 11 ? 0 + n => n % 10 === 1 && n % 100 !== 11 + ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 2 : 1, // Plural rule #7 (3 forms) @@ -139,7 +140,8 @@ const cardinals = { // 20, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 45, 46, 47, 48, 49, // 50, 55, 56, 57, 58, 59, 60, 65, 66, 67, 68, 69, 70, 75, 76, 77, ..., 112, // 113, ..., 212, 213, ... - n => n % 10 === 1 && n % 100 !== 11 ? 0 + n => n % 10 === 1 && n % 100 !== 11 + ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, // Plural rule #8 (3 forms) @@ -165,7 +167,8 @@ const cardinals = { // everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, // 20, 21, 25, 26, 27, 28, 29, 30, 31, 35, 36, 37, 38, 39, 40, 41, 45, 46, // 47, 48, 49, 50, 51, 55, 56, 57, 58, 59, 60, 61, 65, 66, 67, 68, ... - n => n === 1 ? 0 + n => n === 1 + ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, // Plural rule #10 (4 forms) @@ -207,8 +210,13 @@ const cardinals = { // 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, ... // ends in 00-02, excluding 0-2: 100, 101, 102, 200, 201, 202, ... // is 0: 0 - n => n === 1 ? 0 : n === 2 ? 1 : n % 100 >= 3 && n % 100 <= 10 ? 2 - : n % 100 >= 11 ? 3 : n !== 0 ? 4 : 5, + n => n === 1 + ? 0 + : n === 2 + ? 1 + : n % 100 >= 3 && n % 100 <= 10 + ? 2 + : n % 100 >= 11 ? 3 : n !== 0 ? 4 : 5, // Plural rule #13 (4 forms) // Families: Semitic (Maltese) @@ -223,8 +231,11 @@ const cardinals = { // everything else: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, // 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, ... - n => n === 1 ? 0 : n === 0 || (n % 100 > 0 && n % 100 < 11) ? 1 - : n % 100 > 10 && n % 100 < 20 ? 2 : 3, + n => n === 1 + ? 0 + : n === 0 || (n % 100 > 0 && n % 100 < 11) + ? 1 + : n % 100 > 10 && n % 100 < 20 ? 2 : 3, // Plural rule #14 (3 forms) // Families: Unused @@ -265,14 +276,18 @@ const cardinals = { // 6000000, 7000000, 8000000, 9000000, 10000000, ... // everything else: 0, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, // 20, 25, 26, 27, 28, 30, 35, 36, 37, 38, 40, ... - n => n % 10 === 1 && n % 100 !== 11 && n % 100 !== 71 && n % 100 !== 91 ? 0 - : n % 10 === 2 && n % 100 !== 12 && n % 100 !== 72 && n % 100 !== 92 ? 1 + n => n % 10 === 1 && n % 100 !== 11 && n % 100 !== 71 && n % 100 !== 91 + ? 0 + : n % 10 === 2 && n % 100 !== 12 && n % 100 !== 72 && n % 100 !== 92 + ? 1 : (n % 10 === 3 || n % 10 === 4 || n % 10 === 9) && n % 100 !== 13 && n % 100 !== 73 && n % 100 !== 93 && n % 100 !== 14 && n % 100 !== 74 && n % 100 !== 94 && - n % 100 !== 19 && n % 100 !== 79 && n % 100 !== 99 ? 2 - : n !== 0 && n % 1000000 === 0 ? 3 - : 4, + n % 100 !== 19 && n % 100 !== 79 && n % 100 !== 99 + ? 2 + : n !== 0 && n % 1000000 === 0 + ? 3 + : 4, // Plural rule #17 (2 forms) // Families: Ecuador indigenous languages (Shuar) @@ -310,7 +325,8 @@ const cardinals = { // 20, 21, 25, 26, 27, 28, 29, 30, 31, 35, 36, 37, 38, 39, 40, 41, 45, 46, // 47, 48, 49, 50, 51, 55, 56, 57, 58, 59, 60, 61, 65, 66, 67, 68, 69, 70, // 71, 75, 76, 77, ..., 111, 115, ..., 211, 215, ... - n => n === 1 ? 0 + n => n === 1 + ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, // Plural rule #20 (4 forms) @@ -338,7 +354,8 @@ const cardinals = { // 20, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 45, 46, 47, 48, 49, // 50, 55, 56, 57, 58, 59, 60, 65, 66, 67, 68, 69, 70, 75, 76, 77, ..., 112, // 113, ..., 212, 213, ... - n => n % 10 === 1 && n % 100 !== 11 ? 0 + n => n % 10 === 1 && n % 100 !== 11 + ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, // Plural rule #22 (3 forms) diff --git a/src/index.d.ts b/src/index.d.ts index e97c15f..98f63e8 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,20 +1,23 @@ +declare type getPluralFormForCardinal = (count: number) => number + declare function getPluralFormForCardinalByLocale (locale: string, count: number): number declare function getPluralFormNameForCardinalByLocale (locale: string, count: number): string declare function getPluralFormForCardinalByIndex (index: number, count: number): number declare function getPluralFormNameForCardinalByIndex (index: number, count: number): string -declare function getPluralRuleForCardinalsByLocale (locale: string): Function -declare function getPluralRuleForNamedFormsForCardinalsByLocale (locale: string): Function +declare function getPluralRuleForCardinalsByLocale (locale: string): getPluralFormForCardinal +declare function getPluralRuleForNamedFormsForCardinalsByLocale (locale: string): getPluralFormForCardinal -declare function getPluralRuleForCardinalsByIndex (index: number): Function -declare function getPluralRuleForNamedFormsForCardinalsByIndex (index: number): Function +declare function getPluralRuleForCardinalsByIndex (index: number): getPluralFormForCardinal +declare function getPluralRuleForNamedFormsForCardinalsByIndex (index: number): getPluralFormForCardinal export { getPluralFormForCardinalByLocale, getPluralRuleForCardinalsByLocale, getPluralFormNameForCardinalByLocale, getPluralRuleForNamedFormsForCardinalsByLocale, getPluralFormForCardinalByIndex, getPluralRuleForCardinalsByIndex, - getPluralFormNameForCardinalByIndex, getPluralRuleForNamedFormsForCardinalsByIndex + getPluralFormNameForCardinalByIndex, getPluralRuleForNamedFormsForCardinalsByIndex, + getPluralFormForCardinal } export as namespace fastPluralRules diff --git a/test/browser.html b/test/browser.html index 1245900..44ec3d2 100644 --- a/test/browser.html +++ b/test/browser.html @@ -10,6 +10,7 @@ - + + diff --git a/test/browser.test.js b/test/browser.test.js index f0cd1be..cb317d2 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -1,4 +1,4 @@ -/* global jasmine, beforeAll, afterAll, it, expect */ +/* global beforeAll, afterAll, it, expect */ const { join } = require('path') const { readdirSync } = require('fs') @@ -13,20 +13,13 @@ let browser let page const customMatchers = { - toPass: function () { - return { - compare: function (result, message) { - return { - pass: result, - message: () => message - } - } - } + toPass: function (pass, message) { + return { pass, message } } } beforeAll(done => { - jasmine.addMatchers(customMatchers) + expect.extend(customMatchers) server = connect() .use(serve(join(__dirname, '..'), { etag: false })) .listen(port, () => { diff --git a/test/documentation.test.js b/test/documentation.test.js index 4128d30..15348e4 100644 --- a/test/documentation.test.js +++ b/test/documentation.test.js @@ -27,7 +27,7 @@ it('form count matches the note in the rule title', () => { }) it('locales are assigned to distinct rules', () => { - var referredLocales = {} + const referredLocales = {} descriptions .filter(description => description.locales) .forEach(description => { diff --git a/test/typings.test.ts b/test/typings.test.ts index 66b8372..8535da5 100644 --- a/test/typings.test.ts +++ b/test/typings.test.ts @@ -1,14 +1,18 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ + import { getPluralFormForCardinalByLocale, getPluralRuleForCardinalsByLocale, getPluralFormNameForCardinalByLocale, getPluralRuleForNamedFormsForCardinalsByLocale, getPluralFormForCardinalByIndex, getPluralRuleForCardinalsByIndex, - getPluralFormNameForCardinalByIndex, getPluralRuleForNamedFormsForCardinalsByIndex + getPluralFormNameForCardinalByIndex, getPluralRuleForNamedFormsForCardinalsByIndex, + getPluralFormForCardinal } from '..' -declare function test (label: string, callback: Function) +declare type testCallback = () => void +declare function test (label: string, callback: testCallback): void test('Type declarations for TypeScript', () => { - let rule: Function + let rule: getPluralFormForCardinal let formIndex: number let formName: string rule = getPluralRuleForCardinalsByIndex(0) diff --git a/util/generate-browser-tests.js b/util/generate-browser-tests.js index 3f6f725..ca275ff 100644 --- a/util/generate-browser-tests.js +++ b/util/generate-browser-tests.js @@ -43,7 +43,8 @@ function formatModuleImport (input) { if (match[1] === 'cardinals') { scriptName = '../cardinals.umd.js' } else { - scriptName = counter++ % 2 === 0 ? '../../dist/index.umd.min.js' + scriptName = counter++ % 2 === 0 + ? '../../dist/index.umd.min.js' : '../../dist/index.umd.js' } const functionScriptElement = [ diff --git a/util/parse-plural-rule.js b/util/parse-plural-rule.js index 54aa187..1b13721 100644 --- a/util/parse-plural-rule.js +++ b/util/parse-plural-rule.js @@ -14,20 +14,21 @@ function parseNamedList (ruleLines, listName, startIndex = 0) { let insideNamedList let nextIndex = ruleLines.findIndex((line, index) => { if (index < startIndex) { - return + return false } const match = /^([^:]+):\s*(.+)$/.exec(line) if (match) { if (!insideNamedList && match[1] === listName) { items.push(match[2]) insideNamedList = true - return + return false } return true } if (insideNamedList) { items.push(line) } + return false }) if (nextIndex < 0) { nextIndex = startIndex