-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
character-orders.ts
68 lines (57 loc) · 1.59 KB
/
character-orders.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
import minimist from 'minimist'
import {outputFileSync} from 'fs-extra'
import stringify from 'json-stable-stringify'
import {getAllLocales} from './utils'
import type {Args} from './common-types'
type CharacterOrder = 'left-to-right' | 'right-to-left'
type CldrMiscLayout =
| {
main: {
[locale: string]: {
layout: {
orientation: {
characterOrder: CharacterOrder
}
}
}
}
}
| undefined
function getCharacterOrder(
layoutData: CldrMiscLayout,
locale: string
): CharacterOrder | undefined {
return layoutData?.main[locale].layout.orientation.characterOrder
}
async function main(args: Args) {
const {out} = args
const characterOrders: {[locale: string]: CharacterOrder} = {}
const locales = await getAllLocales()
for (const locale of locales) {
const layoutData = await import(`cldr-misc-full/main/${locale}/layout.json`)
const characterOrder = getCharacterOrder(layoutData, locale)
if (characterOrder) {
characterOrders[locale] = characterOrder
}
}
const possibleValues = Object.values(characterOrders).reduce((acc, val) => {
if (!acc.includes(val)) {
acc.push(val)
}
return acc
}, [] as string[])
outputFileSync(
out,
`/* @generated */
// prettier-ignore
export const characterOrders = ${stringify(characterOrders, {
space: 2,
})} as const
export type CharacterOrdersKey = keyof typeof characterOrders
export type CharacterOrder = '${possibleValues.join("' | '")}'
`
)
}
if (require.main === module) {
main(minimist<Args>(process.argv))
}