Skip to content

Instantly share code, notes, and snippets.

@brunosabot
Created February 27, 2022 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunosabot/0452d814c076b772dbb91ada500e999d to your computer and use it in GitHub Desktop.
Save brunosabot/0452d814c076b772dbb91ada500e999d to your computer and use it in GitHub Desktop.
import fetch from "node-fetch";
interface GistJsonResponse {
files: string[];
}
async function loadGist(id: string) {
const url = `https://gist.github.com/${id}`;
const jsonResponse = await fetch(`${url}.json`);
const jsonData = await (jsonResponse.json() as Promise<GistJsonResponse>);
const data = await Promise.all(
jsonData.files.map((file) =>
fetch(`${url}/raw/?file=${file}`).then((r) => r.text())
)
);
return [data, jsonData];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment