-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
55 lines (51 loc) · 1.31 KB
/
build.js
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
import fs from 'node:fs/promises'
import fetch from 'node-fetch'
import * as dsv from 'd3-dsv'
const headers = ['code', 'numeric', 'english', 'french', 'pva', 'age', 'date']
const response = await fetch('https://www.unicode.org/iso15924/iso15924.txt')
const text = await response.text()
const data = dsv
.dsvFormat(';')
.parse(
headers.join(';') +
String(text)
.split('\n')
.filter((d) => d.charAt(0) !== '#')
.join('\n')
)
.map(function (script) {
return {
code: script.code,
name: script.english,
numeric: script.numeric,
pva: script.pva || undefined,
date: script.date
}
})
await fs.writeFile(
'index.js',
[
'/**',
' * @typedef Script',
' * ISO 15924 script info.',
' * @property {string} name',
' Script name.',
' * @property {string} code',
' * Four character ISO 15924 code.',
' * @property {string} numeric',
' * Three character ISO 15924 code.',
' * @property {string} [pva]',
' * Property value alias.',
' * @property {string} date',
" * Date of addition (e.g., `'2016-12-05'`).",
' */',
'',
'/**',
' * List of scripts.',
' *',
' * @type {Array<Script>}',
' */',
'export const iso15924 = ' + JSON.stringify(data, null, 2),
''
].join('\n')
)