-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.js
43 lines (40 loc) · 1.36 KB
/
cron.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
// <https://www.iana.org/assignments/message-headers/perm-headers.csv>
// <https://www.iana.org/assignments/message-headers/message-headers.xhtml>
// <https://www.iana.org/assignments/message-headers/prov-headers.csv>
const fs = require('fs');
const superagent = require('superagent');
const csv = require('csvtojson');
const keys = ['perm', 'prov'];
(async () => {
const [perm, prov] = await Promise.all(keys.map(getParseAndWriteFile));
const permanent = JSON.stringify(perm, null, 2);
const provisional = JSON.stringify(prov, null, 2);
const all = perm.concat(prov);
fs.writeFileSync('./permanent.json', permanent);
fs.writeFileSync('./provisional.json', provisional);
fs.writeFileSync('./all.json', JSON.stringify(all, null, 2));
fs.writeFileSync(
'./deprecated.json',
JSON.stringify(all.filter(o => o.Status === 'deprecated'), null, 2)
);
fs.writeFileSync(
'./standard.json',
JSON.stringify(all.filter(o => o.Status === 'standard'), null, 2)
);
})();
async function getParseAndWriteFile(key) {
const res = await superagent
.get(`https://www.iana.org/assignments/message-headers/${key}-headers.csv`)
.set('accept', 'text/plain');
const json = await csv({
noheader: true,
headers: [
'Header Field Name',
'Template',
'Protocol',
'Status',
'Reference'
]
}).fromString(res.text);
return json;
}