Skip to content

Commit

Permalink
fix: Adapt sources after upgrading the build environment
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Jan 28, 2022
1 parent 35335d3 commit d185af3
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 38 deletions.
45 changes: 31 additions & 14 deletions src/cardinals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion test/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/boot0.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/boot1.js"></script>
</head>
</html>
15 changes: 4 additions & 11 deletions test/browser.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jasmine, beforeAll, afterAll, it, expect */
/* global beforeAll, afterAll, it, expect */

const { join } = require('path')
const { readdirSync } = require('fs')
Expand All @@ -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, () => {
Expand Down
2 changes: 1 addition & 1 deletion test/documentation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
10 changes: 7 additions & 3 deletions test/typings.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion util/generate-browser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
5 changes: 3 additions & 2 deletions util/parse-plural-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d185af3

Please sign in to comment.