Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Hand-drawn, sketchy React charts and flowcharts.

![npm v0.2.0](assets/badges/npm.svg) ![license MIT](assets/badges/license.svg) ![drawn with rough.js](assets/badges/drawn-with.svg) ![default vibe chaotic_notebook](assets/badges/vibe.svg)
![npm v0.2.0](assets/badges/npm.svg) ![downloads/mo](assets/badges/downloads.svg) ![license MIT](assets/badges/license.svg) ![drawn with rough.js](assets/badges/drawn-with.svg) ![default vibe chaotic_notebook](assets/badges/vibe.svg)

> These badges? We ship them. See [`Badge`](src/components/Badge.tsx) and the `render-badge` / `render-github-badge` MCP tools.

Expand Down
1 change: 1 addition & 0 deletions assets/badges/downloads.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions scripts/render-readme-badges.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,28 @@ const BRAND = {
font: 'sans-serif',
};

function formatCount(n) {
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
if (n >= 1_000) return `${(n / 1_000).toFixed(1).replace(/\.0$/, '')}k`;
return String(n);
}

async function fetchNpmDownloads(pkg, period = 'last-month') {
const url = `https://api.npmjs.org/downloads/point/${period}/${pkg}`;
const r = await fetch(url);
if (!r.ok) throw new Error(`npm downloads fetch failed: ${r.status}`);
const j = await r.json();
return j.downloads;
}

const monthlyDownloads = await fetchNpmDownloads('goldenchart', 'last-month');
console.log(` fetched npm last-month downloads: ${monthlyDownloads}`);

const badges = [
{ file: 'npm.svg', label: 'npm', value: 'v0.2.0', tone: 'info', icon: 'tag' },
// No icon: the v1 BADGE_ICONS set has no download glyph and "downloads/mo"
// as a label is clear enough on its own.
{ file: 'downloads.svg', label: 'downloads/mo', value: formatCount(monthlyDownloads), tone: 'info' },
{ file: 'license.svg', label: 'license', value: 'MIT', tone: 'neutral', icon: 'license' },
{ file: 'drawn-with.svg', label: 'drawn with', value: 'rough.js', tone: 'neutral' },
{ file: 'vibe.svg', label: 'default vibe', value: 'chaotic_notebook', tone: 'info', icon: 'star' },
Expand Down
Loading