Back to packages list

Vals using json2csv

Description from the NPM package:
Convert JSON to CSV
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { Options, Parser as CsvParser } from "npm:json2csv";
export const handler = async () => {
const hashrateResp = await fetch("https://mempool.space/api/v1/mining/hashrate/3y");
const { difficulty } = await hashrateResp.json();
const dateAndDifficulties = difficulty.map(d => ({
dateTime: new Date(d.time * 1000).toUTCString(),
difficulty: d.difficulty,
}));
const csvParser = new CsvParser();
const csv = csvParser.parse(dateAndDifficulties);
return new Response(csv);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { Options, Parser as CsvParser } from "npm:json2csv";
export default async function(req: Request): Promise<Response> {
const blockFeesResp = await fetch("https://mempool.space/api/v1/mining/blocks/fees/3y");
const blockFees = await blockFeesResp.json();
const dateAndDifficulties = blockFees.map(b => ({
dateTime: new Date(b.timestamp * 1000).toUTCString(),
avgFees: b.avgFees,
avgBlockHeight: b.avgHeight,
usd: b.USD,
}));
const csvParser = new CsvParser();
const csv = csvParser.parse(dateAndDifficulties);
return new Response(csv);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { Options, Parser as CsvParser } from "npm:json2csv";
export const handler = async () => {
const resp = await fetch("https://mempool.space/api/v1/mining/hashrate/3y");
const { difficulty, hashrates } = await resp.json();
const dateAndHashrates = hashrates.map(h => ({
dateTime: new Date(h.timestamp * 1000).toUTCString(),
avgHashrate: h.avgHashrate,
}));
const csvParser = new CsvParser();
const csv = csvParser.parse(dateAndHashrates);
return new Response(csv);
};
1
Next