1 | 'use strict'
|
2 |
|
3 | const bent = require('bent')
|
4 | const path = require('path')
|
5 |
|
6 | const get = bent('string')
|
7 | const url = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv'
|
8 | const fs = require('fs')
|
9 |
|
10 | const parse = async function * () {
|
11 | const str = await get(url)
|
12 | const lines = str.split('\n')
|
13 | lines.shift()
|
14 | for (const line of lines) {
|
15 | if (!line.length) continue
|
16 | const [name, tag, code] = line.split(',')
|
17 | yield { name: name.trim(), tag: tag.trim(), code: parseInt(code.trim(), 16) }
|
18 | }
|
19 | }
|
20 |
|
21 | const run = async () => {
|
22 | const table = {}
|
23 |
|
24 | for await (const { name, code } of parse()) {
|
25 | table[name] = code
|
26 | }
|
27 |
|
28 | fs.writeFileSync(path.join(__dirname, '../src/base-table.json'), JSON.stringify(table, null, 2))
|
29 | }
|
30 | run()
|