Import

js
import {
  generateStats,
  loadConfig,
  validateConfig,
  applyRuntimeOverrides,
  fetchStats,
  renderCards,
  listThemes
} from "profile-graphics";

Generate from a config

generateStats fetches the stats, renders every card in charts and writes the files to output.dir, just like the CLI.

js
const config = await loadConfig("profile-graphics.yml");
const { outputs } = await generateStats(config);
for (const output of outputs) console.log(output.chart, output.path);

Render without writing files

validateConfig fills in the defaults, applyRuntimeOverrides applies options by their camelCase names, as strings, the way CLI flags do. fetchStats returns the merged stats of every source, and renderCards turns them into SVG strings, or PNG and WebP bytes, without touching the disk.

js
const base = validateConfig({ provider: { user: "octocat" }, charts: ["streak"] });
const config = applyRuntimeOverrides(base, { theme: "dracula", calendarMode: "rolling" });
const stats = await fetchStats(config);
const [card] = await renderCards(config, stats);
console.log(card.content);

Browser and edge runtimes

profile-graphics/core holds the schema, themes, card translations and renderer without any Node.js API, so it runs in browsers, workers and edge functions. renderBrowserCards renders demo stats when you pass no stats, and also exports renderConfigCards, createDemoStats, resolveWindow and listThemes.

js
import { renderBrowserCards } from "profile-graphics/core";

const { cards } = renderBrowserCards({
  config: {
    provider: { user: "octocat" },
    charts: ["streak", "langs"],
    theme: { preset: "dracula" }
  }
});
document.body.innerHTML = cards.map((card) => card.svg).join("");

Card server

profile-graphics/server exports createCardHandler, the Fetch API handler behind profile-graphics serve, with allowedUsers, cacheSeconds, cacheEntries, rateLimit, clientKey and counter options, and the RateLimit type. By default a client is the first address in x-forwarded-for, and requests without one are not limited. listen runs a handler on the Node.js HTTP server.

createVercelHandler wraps the handler for Vercel functions: it strips the /api prefix, answers /api/stats?username=… with GitHub stats JSON and limits each client to 30 requests per 60 seconds. Set PG_RATE_LIMIT (such as 120/60) to change the limit and PG_ALLOWED_USERS (such as mona,octocat) to serve only those users; others get HTTP 403.

js
import { createCardHandler, createVercelHandler } from "profile-graphics/server";

export const handler = createCardHandler({
  allowedUsers: ["octocat"],
  cacheSeconds: 3600,
  rateLimit: { requests: 60, windowSeconds: 60 },
  clientKey: (request) => request.headers.get("cf-connecting-ip") ?? ""
});

export const GET = createVercelHandler();

View counter stores

The views counter keeps its counts in a CounterStore: an object with increment(key) and read(key) that both resolve to { total, days }, where days maps UTC dates to counts. MemoryCounterStore is the default, FileCounterStore writes a JSON file, and UpstashCounterStore talks to the Upstash Redis REST API with fetch and keeps one hash per user. Pass your own store to plug in any other database.

createVercelHandler picks UpstashCounterStore by itself when UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN (or KV_REST_API_URL and KV_REST_API_TOKEN) are set.

js
import { createCardHandler, UpstashCounterStore } from "profile-graphics/server";

const counter = new UpstashCounterStore({
  url: process.env.UPSTASH_REDIS_REST_URL,
  token: process.env.UPSTASH_REDIS_REST_TOKEN
});

export const handler = createCardHandler({ allowedUsers: ["octocat"], counter });

Web component

Use <profile-graphics> to render cards live on any page, such as a personal site or a blog. Load the single-file bundle from a CDN or import "profile-graphics/element" in a bundler. card takes one or more card names separated by commas (default streak), and the display options are attributes with dashes instead of underscores: theme, locale, frame, frame-title, layout, langs-style and the rest. config accepts a whole config as JSON. With the native theme the cards follow the viewer's color scheme, and they redraw when an attribute changes.

html
<script type="module" src="https://cdn.jsdelivr.net/npm/profile-graphics/dist/profile-graphics.element.js"></script>

<profile-graphics user="octocat" card="streak,langs" theme="tokyo-night" frame="window"
  frame-title="{user} · {total} contributions"></profile-graphics>

<profile-graphics provider="forgejo" user="forgejo" card="calendar"></profile-graphics>
<profile-graphics stats-src="https://cards.example.com/github/octocat.json" card="summary"></profile-graphics>
<profile-graphics views-src="https://cards.example.com/github/octocat/views.json" card="views"></profile-graphics>

Without data the element renders demo stats. provider="forgejo" loads a public Codeberg profile directly, and base-url points it at another server. stats-src loads stats JSON, for example from profile-graphics serve at /<provider>/<user>.json. views-src reads view counts from /<provider>/<user>/views.json for the views card without counting a view. The stats and token properties accept data or a token from a script. Never put a token in HTML.

Core types

Type Values
ProviderType github, gitlab, forgejo, wakatime, file
ChartType activity, langs, streak, summary, productive-time, punch-card, calendar, calendar-3d, profile-details, profile-card, trophy, repos, coding-time, coding-languages, coding-editors, coding-os, coding-projects, views
OutputFormat svg, png, webp
OutputLayout separate, dashboard
CalendarMode current-year, last-year, rolling
FrameStyle none, border, window
LangsStyle bar, donut, donut-compact
ThemeMode auto, light, dark, fixed