You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

7 years ago
const fs = require('fs');
const fetch = require('isomorphic-fetch');
const sortby = require('lodash.sortby');
const endpoint = 'https://www.cryptocompare.com/api/data/coinlist/';
/**
* Build the JSON file based on the cryptocompare coinlist.
*/
fetch(endpoint)
.then(response => response.json())
.then(json => {
const sorted = sortby(json.Data, o => o.CoinName);
const symbols = {};
sorted.forEach(currency => {
const {Name, CoinName} = currency;
symbols[Name] = CoinName;
});
fs.writeFileSync('cryptocurrencies.json', JSON.stringify(symbols, null, 2));
console.log('JSON File written');
7 years ago
// --------------------------------------------- //
// Now build the Readme
const template = fs.readFileSync('readme.md').toString();
const data = JSON.parse(fs.readFileSync('cryptocurrencies.json').toString());
const newSymbols = Object.keys(data);
let table = `There are currently **${newSymbols.length} cryptocurrencies** represented*:\n`;
table += '\n\n';
table += '| Symbol | Name |\n';
table += '| :------ | :------ |\n';
newSymbols.forEach(symbol => {
table += `| \`${symbol}\` | ${data[symbol]} |\n`;
});
table += `\n<small><em>* Last updated: ${new Date().toUTCString()}</em></small>`;
const target = /<!-- BEGIN TABLE INJECT -->(\w|\W)*<!-- END TABLE INJECT -->/gim;
const updated = template.replace(target, `<!-- BEGIN TABLE INJECT -->\n${table}\n<!-- END TABLE INJECT -->`);
7 years ago
fs.writeFileSync('readme.md', updated);
console.log('Readme Markdown Table updated');
})
.catch(err => console.error(err));