Skip to content

Commit

Permalink
simplify downloads-by-versions script
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 28, 2023
1 parent 3222dbc commit d67ed0f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions scripts/downloads-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ const downloadsByMajor = {};
let total = 0;

async function getStat(pkg) {
const res = await fetch(`https://www.npmjs.com/package/${ pkg }`);
const html = await res.text();
const { json } = html.match(/>window\.__context__ = (?<json>[^<]+)<\//).groups;
return JSON.parse(json).context.versionsDownloads;
const res = await fetch(`https://api.npmjs.org/versions/${ encodeURIComponent(pkg) }/last-week`);
const { downloads } = await res.json();
return downloads;
}

const [core, pure, bundle] = await Promise.all([
Expand Down

0 comments on commit d67ed0f

Please sign in to comment.