tokengraph 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bundle/bin.js +16 -21
  2. package/package.json +2 -2
package/bundle/bin.js CHANGED
@@ -984,14 +984,20 @@ function escapeXml(value) {
984
984
  function n(value) {
985
985
  return String(Math.round(value * 100) / 100);
986
986
  }
987
+ function tokenParts(value) {
988
+ if (Math.round(value) < 1e3)
989
+ return { figure: String(Math.round(value)), unit: "" };
990
+ let scaled = value / 1e3;
991
+ let unit = 0;
992
+ while (unit < TOKEN_UNITS.length - 1 && Number(scaled.toFixed(1)) >= 1e3) {
993
+ scaled /= 1e3;
994
+ unit += 1;
995
+ }
996
+ return { figure: scaled.toFixed(1), unit: TOKEN_UNITS[unit] };
997
+ }
987
998
  function formatTokens(value) {
988
- if (value >= 1e9)
989
- return `${(value / 1e9).toFixed(1)}B`;
990
- if (value >= 1e6)
991
- return `${(value / 1e6).toFixed(1)}M`;
992
- if (value >= 1e3)
993
- return `${(value / 1e3).toFixed(1)}K`;
994
- return String(Math.round(value));
999
+ const { figure, unit } = tokenParts(value);
1000
+ return figure + unit;
995
1001
  }
996
1002
  function formatTokensExact(value) {
997
1003
  return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
@@ -1309,7 +1315,7 @@ function renderGraphSvg(days, options) {
1309
1315
  const label = `Token usage graph, ${formatTokens(grid.total)} weighted tokens over ${plural(grid.activeDays, "active day")}` + (grid.activeDays > 0 ? `, current streak ${plural(stats2.currentStreak, "day")}` : "");
1310
1316
  return graphFrame(layout2, height, theme, parts3.join(""), label, options.fontFaceCss);
1311
1317
  }
1312
- var FULL, COMPACT, WEEKS, DAYS, MONTHS, FONT, FALLBACK_ADVANCE, LEGEND_SWATCH, LEGEND_LOGO, LEGEND_ROW_GAP, LEGEND_ITEM_GAP, LEGEND_ROW, FOOTER_MARK_HEIGHT, FLAME_LEFT, FLAME_TOP, FLAME_HEIGHT, FLAME_CENTROID_Y, CHROME, ANIMATION_CSS, STRIP_HEIGHT, STRIP_COLUMNS, STRIP_INSET;
1318
+ var FULL, COMPACT, WEEKS, DAYS, MONTHS, FONT, FALLBACK_ADVANCE, TOKEN_UNITS, LEGEND_SWATCH, LEGEND_LOGO, LEGEND_ROW_GAP, LEGEND_ITEM_GAP, LEGEND_ROW, FOOTER_MARK_HEIGHT, FLAME_LEFT, FLAME_TOP, FLAME_HEIGHT, FLAME_CENTROID_Y, CHROME, ANIMATION_CSS, STRIP_HEIGHT, STRIP_COLUMNS, STRIP_INSET;
1313
1319
  var init_graph = __esm({
1314
1320
  "../core/dist/graph.js"() {
1315
1321
  "use strict";
@@ -1356,6 +1362,7 @@ var init_graph = __esm({
1356
1362
  MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
1357
1363
  FONT = "'IBM Plex Sans', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif";
1358
1364
  FALLBACK_ADVANCE = 0.56;
1365
+ TOKEN_UNITS = ["K", "M", "B", "T", "Q"];
1359
1366
  LEGEND_SWATCH = 11;
1360
1367
  LEGEND_LOGO = 14;
1361
1368
  LEGEND_ROW_GAP = 8;
@@ -2487,19 +2494,7 @@ function periodPhrase(range) {
2487
2494
  }
2488
2495
  }
2489
2496
  function heroNumber(value) {
2490
- const scales = [
2491
- [1e12, "T"],
2492
- [1e9, "B"],
2493
- [1e6, "M"],
2494
- [1e3, "K"]
2495
- ];
2496
- for (const [size, unit] of scales) {
2497
- if (value >= size) {
2498
- const scaled = value / size;
2499
- return { figure: scaled >= 100 ? String(Math.round(scaled)) : scaled.toFixed(1), unit };
2500
- }
2501
- }
2502
- return { figure: String(Math.round(value)), unit: "" };
2497
+ return tokenParts(value);
2503
2498
  }
2504
2499
  function compactDollars(value) {
2505
2500
  if (value < 1e3)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokengraph",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "A GitHub-style graph of the tokens your AI coding agents burn each day: Claude Code, Codex CLI, Cursor, Gemini CLI, Cline, OpenCode, Kilo CLI, Copilot CLI, pi, Qwen Code and Goose.",
5
5
  "keywords": [
6
6
  "ai",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@resvg/resvg-wasm": "^2.6.2",
49
- "@tokengraph/core": "0.2.1",
49
+ "@tokengraph/core": "0.2.2",
50
50
  "@types/react": "^19.3.0",
51
51
  "esbuild": "0.28.2",
52
52
  "qrcode-generator": "^2.0.4",