-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data): add jsDelivr hits (#263)
* Add jsDelivr hits * Removed interval for re-fetching data * Removed catch when loading jsDelivr hits * Record schema in README.md updated
- Loading branch information
Showing
7 changed files
with
38 additions
and
7 deletions.
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 characters
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 characters
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 characters
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 characters
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import got from 'got'; | ||
import c from './config.js'; | ||
|
||
const hits = new Map(); | ||
|
||
function formatHits(pkg) { | ||
if (pkg.type !== 'npm') { | ||
return; | ||
} | ||
|
||
hits.set(pkg.name, pkg.hits); | ||
} | ||
|
||
export async function loadHits() { | ||
const hitsJSONpromise = got(c.jsDelivrHitsEndpoint, { json: true }); | ||
const hitsJSON = (await hitsJSONpromise).body; | ||
hits.clear(); | ||
hitsJSON.forEach(formatHits); | ||
} | ||
|
||
export function getHits(pkgs) { | ||
return pkgs.map(({ name }) => ({ jsDelivrHits: hits.get(name) || 0 })); | ||
} |
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 characters
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 characters