UNPKG

query-registry

Version:

Query the npm registry for packuments, manifests, packages and download counts

12 lines (11 loc) 410 B
import { cache } from "./cache.js"; export async function fetchData(schema, url, headers) { const cacheKey = JSON.stringify({ url, headers }); const cachedJson = cache.get(cacheKey); if (cachedJson) return schema.parse(cachedJson); const response = await fetch(url, { headers }); const json = (await response.json()); cache.set(cacheKey, json); return schema.parse(json); }