Skip to content

🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.

1.1 KB
Raw Blame
/** Formatting never changes the currency or the numeric value used in calculations. */
const currencyFormats = new Map<string, Intl.NumberFormat>();
export function formatUSD(value: number, locale = "en-US", minimumFractionDigits = 0, maximumFractionDigits = 6, useGrouping = false): string {
  const key = `${locale}:${minimumFractionDigits}:${maximumFractionDigits}:${useGrouping}`;
  let formatter = currencyFormats.get(key);
  if (!formatter) {
    formatter = new Intl.NumberFormat(locale, { style: "currency", currency: "USD", currencyDisplay: "narrowSymbol", minimumFractionDigits, maximumFractionDigits, useGrouping });
    currencyFormats.set(key, formatter);
  }
  return formatter.format(value);
}

/** Snapshots store an English display value; localize it without editing the snapshot. */
export function localizeSnapshotUSD(text: string, locale: string): string {
  const match = /^(< )?\$([\d,]+(?:\.\d+)?)$/.exec(text);
  if (!match) return text;
  const decimals = match[2].split(".")[1]?.length ?? 0;
  return `${match[1] || ""}${formatUSD(Number(match[2].replaceAll(",", "")), locale, decimals, decimals, true)}`;
}