Public
Edited
May 15
2 forks
Importers
16 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function numbish(value) {
return +value;
}
Insert cell
function majorVersion({version}) {
const [major, minor] = version.split(".");
return major === "0" ? `${major}.${minor}` : major;
}
Insert cell
function isPrerelease(version) {
return /-/.test(version);
}
Insert cell
function isMajor(version) {
return /^\d+\.0\.0$/.test(version);
}
Insert cell
versiondata = Object.entries((await d3.json(`https://api.npmjs.org/versions/${encodeURIComponent(name)}/last-week`)).downloads).map(([version, downloads]) => ({version, downloads}))
Insert cell
Insert cell
daydata.slice(0, -115)
Insert cell
daydata.slice(0, 10)
Insert cell
daydata = {
const data = [];
const min = new Date("2015-01-01");
const max = d3.utcDay();
let start = max;
let end;
while (start > min) {
end = start;
start = d3.utcDay.offset(start, -365);
if (start < min) start = min;
try {
const batch = await d3.json(`https://api.npmjs.org/downloads/range/${formatDate(start)}:${formatDate(d3.utcDay.offset(end, -1))}${name ? `/${encodeURIComponent(name)}`: ``}`);
for (const {downloads: value, day: date} of batch.downloads.reverse()) {
data.push({date: new Date(date), value});
}
for (let i = data.length - 1; i >= 0; --i) {
if (data[i].value > 0) {
yield data.slice(data[0].value > 0 ? 0 : 1, i + 1).reverse(); // ignore npm reporting zero for today
break;
}
}
} catch {
return;
}
}
}
Insert cell
versions = {
const info = await d3.json(`https://registry.npmjs.org/${encodeURIComponent(name)}`);
return Object.values(info.versions).map(({version}) => ({version, date: new Date(info.time[version])}));
}
Insert cell
formatDate = d3.utcFormat("%Y-%m-%d")
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