Last active
February 23, 2025 04:50
Revisions
-
mjackson revised this gist
Oct 21, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ async function getDownloads(startYear, endYear = startYear) { let totalDownloads = downloadCounts.reduce((memo, n) => memo + n); return totalDownloads.toLocaleString(); } getDownloads(2015, 2022).then(downloads => console.log(downloads)); -
mjackson revised this gist
Oct 21, 2022 . 1 changed file with 30 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,30 @@ const npmApiUrl = "https://api.npmjs.org/downloads/point"; async function fetchDownloadCounts(packageName, year) { let range = `${year}-01-01:${year}-12-31`; let response = await fetch(`${npmApiUrl}/${range}/${packageName}`); return (await response.json()).downloads; } async function getDownloads(startYear, endYear = startYear) { if (endYear < startYear) { throw new Error( `End year (${endYear}) must be before start year (${startYear})` ); } let years = []; for (let year = startYear; year <= endYear; year += 1) { years.push(year); } let downloadCounts = await Promise.all( years.map(year => fetchDownloadCounts("react-router", year)) ); let totalDownloads = downloadCounts.reduce((memo, n) => memo + n); return totalDownloads; } getDownloads(2015, 2022).then(downloads => console.log(downloads)); -
mjackson created this gist
Oct 21, 2022 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@