-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.js
41 lines (34 loc) · 837 Bytes
/
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
import {writeFile} from 'node:fs'
import {request} from 'node:https'
import concat from 'concat-stream'
import {bail} from 'bail'
const endpoint =
'https://raw.githubusercontent.com/cmusphinx/cmudict/master/cmudict.dict'
request(endpoint, onrequest).end()
/**
*
* @param {import("http").IncomingMessage} response
*/
function onrequest(response) {
response.pipe(concat(onconcat)).on('error', bail)
}
/**
*
* @param {Buffer} buffer
*/
function onconcat(buffer) {
const words = {}
for (const d of String(buffer).split('\n')) {
const space = d.indexOf(' ')
if (space !== -1) {
words[d.slice(0, space)] = d.slice(space + 1)
}
}
writeFile(
'index.js',
'/** @type {{ [word: string]: string }} */\nexport const dictionary = ' +
JSON.stringify(words, null, 2) +
'\n',
bail
)
}