Skip to content

Commit ba55f6c

Browse files
committed
feat: Also update .d.ts files for compact notation
1 parent d5c283b commit ba55f6c

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

packages/cli/src/print-types.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ function stringifyCategories({ cardinals, ordinals }, categories) {
2020

2121
export default function printPluralTypes(args) {
2222
const MakePlural = getCompiler(args)
23-
const { cardinals, locale, ordinals } = args
24-
let fnArgs = 'n: number | string'
25-
if (cardinals && ordinals) fnArgs += ', ord?: boolean'
23+
const { cardinals, locale } = args
2624
const locales =
2725
locale.length === 0
2826
? Object.keys(MakePlural.rules[cardinals ? 'cardinal' : 'ordinal'])
@@ -35,8 +33,22 @@ export default function printPluralTypes(args) {
3533
mpc.compile()
3634
mpc.test()
3735
const id = identifier(lc)
36+
const fnArgs = mpc.functionArgs().map(arg => {
37+
switch (arg) {
38+
case 'n':
39+
return 'n: number | string'
40+
case 'ord':
41+
return 'ord?: boolean'
42+
case 'c':
43+
return 'c?: number'
44+
default:
45+
throw new Error(
46+
`Unsupported selector argument for locale ${lc}: ${arg}`
47+
)
48+
}
49+
})
3850
const cat = stringifyCategories(args, mpc.categories)
39-
str += `export const ${id}: (${fnArgs}) => ${cat};\n`
51+
str += `export const ${id}: (${fnArgs.join(', ')}) => ${cat};\n`
4052
}
4153
return str
4254
}

packages/compiler/src/compiler.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,15 @@ export class Compiler {
112112
body = ` return ${this.buildBody(pt, true)};`
113113
}
114114

115-
const args = this.parser.args(ordinals && cardinals)
115+
const args = this.functionArgs().join(', ')
116116
const vars = this.parser.vars()
117117
if (vars) body = ` ${vars};\n${body}`
118118

119119
return new Function(args, body) // eslint-disable-line no-new-func
120120
}
121+
122+
functionArgs() {
123+
const { cardinals, ordinals } = this.types
124+
return this.parser.args(ordinals && cardinals)
125+
}
121126
}

packages/compiler/src/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class Parser {
5555
let args = ['n']
5656
if (ord) args.push('ord')
5757
if (this.c) args.push('c')
58-
return args.join(', ')
58+
return args
5959
}
6060

6161
vars() {

packages/plurals/cardinals.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const bo: (n: number | string) => "other";
2323
export const br: (n: number | string) => "one" | "two" | "few" | "many" | "other";
2424
export const brx: (n: number | string) => "one" | "other";
2525
export const bs: (n: number | string) => "one" | "few" | "other";
26-
export const ca: (n: number | string) => "one" | "many" | "other";
26+
export const ca: (n: number | string, c?: number) => "one" | "many" | "other";
2727
export const ce: (n: number | string) => "one" | "other";
2828
export const ceb: (n: number | string) => "one" | "other";
2929
export const cgg: (n: number | string) => "one" | "other";
@@ -43,15 +43,15 @@ export const ee: (n: number | string) => "one" | "other";
4343
export const el: (n: number | string) => "one" | "other";
4444
export const en: (n: number | string) => "one" | "other";
4545
export const eo: (n: number | string) => "one" | "other";
46-
export const es: (n: number | string) => "one" | "many" | "other";
46+
export const es: (n: number | string, c?: number) => "one" | "many" | "other";
4747
export const et: (n: number | string) => "one" | "other";
4848
export const eu: (n: number | string) => "one" | "other";
4949
export const fa: (n: number | string) => "one" | "other";
5050
export const ff: (n: number | string) => "one" | "other";
5151
export const fi: (n: number | string) => "one" | "other";
5252
export const fil: (n: number | string) => "one" | "other";
5353
export const fo: (n: number | string) => "one" | "other";
54-
export const fr: (n: number | string) => "one" | "many" | "other";
54+
export const fr: (n: number | string, c?: number) => "one" | "many" | "other";
5555
export const fur: (n: number | string) => "one" | "other";
5656
export const fy: (n: number | string) => "one" | "other";
5757
export const ga: (n: number | string) => "one" | "two" | "few" | "many" | "other";
@@ -77,7 +77,7 @@ export const ig: (n: number | string) => "other";
7777
export const ii: (n: number | string) => "other";
7878
export const io: (n: number | string) => "one" | "other";
7979
export const is: (n: number | string) => "one" | "other";
80-
export const it: (n: number | string) => "one" | "many" | "other";
80+
export const it: (n: number | string, c?: number) => "one" | "many" | "other";
8181
export const iu: (n: number | string) => "one" | "two" | "other";
8282
export const ja: (n: number | string) => "other";
8383
export const jbo: (n: number | string) => "other";
@@ -110,7 +110,7 @@ export const lb: (n: number | string) => "one" | "other";
110110
export const lg: (n: number | string) => "one" | "other";
111111
export const lij: (n: number | string) => "one" | "other";
112112
export const lkt: (n: number | string) => "other";
113-
export const lld: (n: number | string) => "one" | "many" | "other";
113+
export const lld: (n: number | string, c?: number) => "one" | "many" | "other";
114114
export const ln: (n: number | string) => "one" | "other";
115115
export const lo: (n: number | string) => "other";
116116
export const lt: (n: number | string) => "one" | "few" | "many" | "other";
@@ -150,8 +150,8 @@ export const pcm: (n: number | string) => "one" | "other";
150150
export const pl: (n: number | string) => "one" | "few" | "many" | "other";
151151
export const prg: (n: number | string) => "zero" | "one" | "other";
152152
export const ps: (n: number | string) => "one" | "other";
153-
export const pt: (n: number | string) => "one" | "many" | "other";
154-
export const pt_PT: (n: number | string) => "one" | "many" | "other";
153+
export const pt: (n: number | string, c?: number) => "one" | "many" | "other";
154+
export const pt_PT: (n: number | string, c?: number) => "one" | "many" | "other";
155155
export const rm: (n: number | string) => "one" | "other";
156156
export const ro: (n: number | string) => "one" | "few" | "other";
157157
export const rof: (n: number | string) => "one" | "other";
@@ -161,7 +161,7 @@ export const sah: (n: number | string) => "other";
161161
export const saq: (n: number | string) => "one" | "other";
162162
export const sat: (n: number | string) => "one" | "two" | "other";
163163
export const sc: (n: number | string) => "one" | "other";
164-
export const scn: (n: number | string) => "one" | "many" | "other";
164+
export const scn: (n: number | string, c?: number) => "one" | "many" | "other";
165165
export const sd: (n: number | string) => "one" | "other";
166166
export const sdh: (n: number | string) => "one" | "other";
167167
export const se: (n: number | string) => "one" | "two" | "other";
@@ -210,7 +210,7 @@ export const und: (n: number | string) => "other";
210210
export const ur: (n: number | string) => "one" | "other";
211211
export const uz: (n: number | string) => "one" | "other";
212212
export const ve: (n: number | string) => "one" | "other";
213-
export const vec: (n: number | string) => "one" | "many" | "other";
213+
export const vec: (n: number | string, c?: number) => "one" | "many" | "other";
214214
export const vi: (n: number | string) => "other";
215215
export const vo: (n: number | string) => "one" | "other";
216216
export const vun: (n: number | string) => "one" | "other";

packages/plurals/plurals.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const bo: (n: number | string, ord?: boolean) => "other";
2323
export const br: (n: number | string, ord?: boolean) => "one" | "two" | "few" | "many" | "other";
2424
export const brx: (n: number | string, ord?: boolean) => "one" | "other";
2525
export const bs: (n: number | string, ord?: boolean) => "one" | "few" | "other";
26-
export const ca: (n: number | string, ord?: boolean) => "one" | "two" | "few" | "many" | "other";
26+
export const ca: (n: number | string, ord?: boolean, c?: number) => "one" | "two" | "few" | "many" | "other";
2727
export const ce: (n: number | string, ord?: boolean) => "one" | "other";
2828
export const ceb: (n: number | string, ord?: boolean) => "one" | "other";
2929
export const cgg: (n: number | string, ord?: boolean) => "one" | "other";
@@ -43,15 +43,15 @@ export const ee: (n: number | string, ord?: boolean) => "one" | "other";
4343
export const el: (n: number | string, ord?: boolean) => "one" | "other";
4444
export const en: (n: number | string, ord?: boolean) => "one" | "two" | "few" | "other";
4545
export const eo: (n: number | string, ord?: boolean) => "one" | "other";
46-
export const es: (n: number | string, ord?: boolean) => "one" | "many" | "other";
46+
export const es: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
4747
export const et: (n: number | string, ord?: boolean) => "one" | "other";
4848
export const eu: (n: number | string, ord?: boolean) => "one" | "other";
4949
export const fa: (n: number | string, ord?: boolean) => "one" | "other";
5050
export const ff: (n: number | string, ord?: boolean) => "one" | "other";
5151
export const fi: (n: number | string, ord?: boolean) => "one" | "other";
5252
export const fil: (n: number | string, ord?: boolean) => "one" | "other";
5353
export const fo: (n: number | string, ord?: boolean) => "one" | "other";
54-
export const fr: (n: number | string, ord?: boolean) => "one" | "many" | "other";
54+
export const fr: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
5555
export const fur: (n: number | string, ord?: boolean) => "one" | "other";
5656
export const fy: (n: number | string, ord?: boolean) => "one" | "other";
5757
export const ga: (n: number | string, ord?: boolean) => "one" | "two" | "few" | "many" | "other";
@@ -77,7 +77,7 @@ export const ig: (n: number | string, ord?: boolean) => "other";
7777
export const ii: (n: number | string, ord?: boolean) => "other";
7878
export const io: (n: number | string, ord?: boolean) => "one" | "other";
7979
export const is: (n: number | string, ord?: boolean) => "one" | "other";
80-
export const it: (n: number | string, ord?: boolean) => "one" | "many" | "other";
80+
export const it: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
8181
export const iu: (n: number | string, ord?: boolean) => "one" | "two" | "other";
8282
export const ja: (n: number | string, ord?: boolean) => "other";
8383
export const jbo: (n: number | string, ord?: boolean) => "other";
@@ -110,7 +110,7 @@ export const lb: (n: number | string, ord?: boolean) => "one" | "other";
110110
export const lg: (n: number | string, ord?: boolean) => "one" | "other";
111111
export const lij: (n: number | string, ord?: boolean) => "one" | "many" | "other";
112112
export const lkt: (n: number | string, ord?: boolean) => "other";
113-
export const lld: (n: number | string, ord?: boolean) => "one" | "many" | "other";
113+
export const lld: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
114114
export const ln: (n: number | string, ord?: boolean) => "one" | "other";
115115
export const lo: (n: number | string, ord?: boolean) => "one" | "other";
116116
export const lt: (n: number | string, ord?: boolean) => "one" | "few" | "many" | "other";
@@ -150,8 +150,8 @@ export const pcm: (n: number | string, ord?: boolean) => "one" | "other";
150150
export const pl: (n: number | string, ord?: boolean) => "one" | "few" | "many" | "other";
151151
export const prg: (n: number | string, ord?: boolean) => "zero" | "one" | "other";
152152
export const ps: (n: number | string, ord?: boolean) => "one" | "other";
153-
export const pt: (n: number | string, ord?: boolean) => "one" | "many" | "other";
154-
export const pt_PT: (n: number | string, ord?: boolean) => "one" | "many" | "other";
153+
export const pt: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
154+
export const pt_PT: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
155155
export const rm: (n: number | string, ord?: boolean) => "one" | "other";
156156
export const ro: (n: number | string, ord?: boolean) => "one" | "few" | "other";
157157
export const rof: (n: number | string, ord?: boolean) => "one" | "other";
@@ -161,7 +161,7 @@ export const sah: (n: number | string, ord?: boolean) => "other";
161161
export const saq: (n: number | string, ord?: boolean) => "one" | "other";
162162
export const sat: (n: number | string, ord?: boolean) => "one" | "two" | "other";
163163
export const sc: (n: number | string, ord?: boolean) => "one" | "many" | "other";
164-
export const scn: (n: number | string, ord?: boolean) => "one" | "many" | "other";
164+
export const scn: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
165165
export const sd: (n: number | string, ord?: boolean) => "one" | "other";
166166
export const sdh: (n: number | string, ord?: boolean) => "one" | "other";
167167
export const se: (n: number | string, ord?: boolean) => "one" | "two" | "other";
@@ -210,7 +210,7 @@ export const und: (n: number | string, ord?: boolean) => "other";
210210
export const ur: (n: number | string, ord?: boolean) => "one" | "other";
211211
export const uz: (n: number | string, ord?: boolean) => "one" | "other";
212212
export const ve: (n: number | string, ord?: boolean) => "one" | "other";
213-
export const vec: (n: number | string, ord?: boolean) => "one" | "many" | "other";
213+
export const vec: (n: number | string, ord?: boolean, c?: number) => "one" | "many" | "other";
214214
export const vi: (n: number | string, ord?: boolean) => "one" | "other";
215215
export const vo: (n: number | string, ord?: boolean) => "one" | "other";
216216
export const vun: (n: number | string, ord?: boolean) => "one" | "other";

0 commit comments

Comments
 (0)