Public
Edited
Jan 30, 2023
2 forks
Importers
45 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
url = moduleUrl(id || "@yurivish/quarantine-now")
Insert cell
imports = fetchAllImports(url)
Insert cell
async function* fetchAllImports(url) {
const urls = new Set([url]);
const importsByUrl = new Map();
const imports = [];
yield imports;
for (const url of urls) {
const urlImports = await fetchImports(url);
for (const importUrl of urlImports) {
urls.add(importUrl);
imports.push([url, importUrl]);
yield imports;
}
}
}
Insert cell
async function fetchImports(url) {
const response = await fetch(url);
if (!response.ok) throw new Error(`unable to fetch ${url}`);
const text = await response.text();
return parseImports(text);
}
Insert cell
function parseImports(text) {
const program = acorn.parse(text, {
ecmaVersion: 11,
sourceType: "module"
});
return program.body
.filter(node => node.type === "ImportDeclaration")
.map(node => new URL(node.source.value, url) + "");
}
Insert cell
function displayName(name) {
let v = name, m;
if (m = /^https:\/\/api\.observablehq\.com\/d\/([0-9a-f]{16}(?:@[0-9]+)?)\.js(?:\?|$)/i.exec(v)
|| /^https:\/\/api\.observablehq\.com\/(@[0-9a-z_-]+\/[0-9a-z_-]+(?:\/[0-9]+)?(?:@[0-9]+)?)\.js(?:\?|$)/i.exec(v)
) {
return m[1];
}
return name;
}
Insert cell
function notebookUrl(name) {
let v = name, m;
if (m = /^https:\/\/api\.observablehq\.com\/(d\/[0-9a-f]{16}(?:@[0-9]+)?)\.js(?:\?|$)/i.exec(v)
|| /^https:\/\/api\.observablehq\.com\/(@[0-9a-z_-]+\/[0-9a-z_-]+(?:\/[0-9]+)?(?:@[0-9]+)?)\.js(?:\?|$)/i.exec(v)
) {
return `https:\/\/observablehq\.com/${m[1]}`;
}
}
Insert cell
function moduleUrl(specifier) {
let v = specifier, m;
if (m = /^([0-9a-f]{16}(?:@[0-9]+)?)$/i.exec(v)) {
return `https://api.observablehq.com/d/${m[1]}.js?v=3`;
}
if (m = /^(@[0-9a-z_-]+\/[0-9a-z_-]+(?:\/[0-9]+)?(?:@[0-9]+)?)$/i.exec(v)
|| /^https:\/\/(?:beta\.)?observablehq\.com\/d\/([0-9a-f]{16}(?:@[0-9]+)?)(?:\?|$)/i.exec(v)
|| /^https:\/\/(?:beta\.)?observablehq\.com\/(@[0-9a-z_-]+\/[0-9a-z_-]+(?:\/[0-9]+)?(?:@[0-9]+)?)(?:\?|$)/i.exec(v)
|| /^https:\/\/api\.observablehq\.com\/d\/([0-9a-f]{16}(?:@[0-9]+)?)\.tgz\?v=3$/i.exec(v)
|| /^https:\/\/api\.observablehq\.com\/(@[0-9a-z_-]+\/[0-9a-z_-]+(?:\/[0-9]+)?(?:@[0-9]+)?)\.tgz\?v=3$/i.exec(v)
) {
return `https://api.observablehq.com/${m[1]}.js?v=3`;
}
return specifier;
}
Insert cell
acorn = require("acorn@8")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more