UNPKG

753 BJavaScriptView Raw
1'use strict'
2
3const bent = require('bent')
4const path = require('path')
5
6const get = bent('string')
7const url = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv'
8const fs = require('fs')
9
10const 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
21const 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}
30run()