codex-cost 0.1.0

Local web dashboard for inspecting Codex token usage from session logs.
Documentation
(function attachNumberFormat(global) {
  const fullFormatter = new Intl.NumberFormat("en-US");
  const compactFormatter = new Intl.NumberFormat("en-US", {
    notation: "compact",
    maximumFractionDigits: 1,
  });

  function numericValue(value) {
    const number = Number(value ?? 0);
    return Number.isFinite(number) ? number : 0;
  }

  function formatCompactNumber(value) {
    const number = numericValue(value);
    if (Math.abs(number) < 1000) {
      return fullFormatter.format(number);
    }
    return compactFormatter.format(number);
  }

  function formatFullNumber(value) {
    return fullFormatter.format(numericValue(value));
  }

  function formatTokenTooltip(label, totalTokens, eventCount) {
    const lines = [
      String(label || "Unknown"),
      `${formatFullNumber(totalTokens)} tokens`,
    ];

    if (eventCount !== undefined && eventCount !== null) {
      const count = numericValue(eventCount);
      lines.push(`${formatFullNumber(count)} ${count === 1 ? "event" : "events"}`);
    }

    return lines.join("\n");
  }

  const api = {
    formatCompactNumber,
    formatFullNumber,
    formatTokenTooltip,
  };

  global.CodexUsageNumberFormat = api;

  if (typeof module !== "undefined" && module.exports) {
    module.exports = api;
  }
})(typeof globalThis !== "undefined" ? globalThis : window);