{
  "version": 3,
  "sources": ["../src/unitformat.ts"],
  "sourcesContent": ["/**\n * @license Unit Formatter v1.2.0\n * https://github.com/rawify/UnitFormat.js\n *\n * Copyright (c) 2025, Robert Eisele (https://raw.org/)\n * Licensed under the MIT license.\n */\n\n/** A supported scaling base. */\nexport type UnitBase = 2 | 10;\n\nconst PREFIX_EXPONENTS: Readonly<Record<UnitBase, Readonly<Record<string, number>>>> = {\n  2: {\n    E: 60,\n    P: 50,\n    T: 40,\n    G: 30,\n    M: 20,\n    k: 10,\n  },\n  10: {\n    E: 18,\n    P: 15,\n    T: 12,\n    G: 9,\n    M: 6,\n    k: 3,\n    h: 2,\n    d: -1,\n    c: -2,\n    m: -3,\n    u: -6,\n    \u03BC: -6,\n    n: -9,\n    p: -12,\n    f: -15,\n    a: -18,\n  },\n};\n\nconst NUMBER_FORMATTER = createNumberFormatter();\n\nfunction createNumberFormatter(): Intl.NumberFormat | null {\n  if (typeof Intl !== 'object' || typeof Intl.NumberFormat !== 'function') {\n    return null;\n  }\n\n  try {\n    return new Intl.NumberFormat(undefined, {\n      maximumFractionDigits: 3,\n      useGrouping: false,\n    });\n  } catch {\n    return null;\n  }\n}\n\nfunction isUnitBase(base: number): base is UnitBase {\n  return base === 2 || base === 10;\n}\n\nfunction formatNumber(value: number): string {\n  return NUMBER_FORMATTER?.format(value) ?? String(Math.round(value * 1000) / 1000);\n}\n\n/**\n * Formats a number with configurable decimal or binary engineering prefixes.\n *\n * @param value The number to format.\n * @param baseUnit The unit appended after the selected prefix.\n * @param prefixes Allowed single-character prefixes in priority order.\n * @param base Scaling base. Only 2 and 10 are supported.\n */\nexport function UnitFormat(\n  value: number,\n  baseUnit: string | null = '',\n  prefixes: string | null = 'kMGTPE',\n  base: number | null = 10,\n): string {\n  const resolvedUnit = baseUnit ?? '';\n  const resolvedPrefixes = prefixes ?? 'kMGTPE';\n  const resolvedBase = base ?? 10;\n\n  if (!isUnitBase(resolvedBase)) {\n    throw new Error(`Not supported base ${resolvedBase}`);\n  }\n\n  if (value === 0) {\n    return `${formatNumber(0)}${resolvedUnit}`;\n  }\n\n  const magnitude = Math.abs(value);\n  const exponents = PREFIX_EXPONENTS[resolvedBase];\n  let bestPrefix = '';\n  let bestScore = magnitude;\n\n  for (const prefix of resolvedPrefixes) {\n    const exponent = exponents[prefix];\n\n    if (exponent === undefined) {\n      throw new Error(`Unknown unit ${prefix}`);\n    }\n\n    const score = magnitude / Math.pow(resolvedBase, exponent);\n\n    if (score >= 1 && (score < bestScore || bestScore < 1)) {\n      bestScore = score;\n      bestPrefix = prefix;\n    }\n  }\n\n  const scaledValue = value < 0 ? -bestScore : bestScore;\n  return `${formatNumber(scaledValue)}${bestPrefix}${resolvedUnit}`;\n}\n\nexport default UnitFormat;"],
  "mappings": ";AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,IAAM,mBAAiF;AAAA,EACrF,GAAG;AAAA,IACD,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAAA,EACA,IAAI;AAAA,IACF,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,QAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAEA,IAAM,mBAAmB,sBAAsB;AAE/C,SAAS,wBAAkD;AACzD,MAAI,OAAO,SAAS,YAAY,OAAO,KAAK,iBAAiB,YAAY;AACvE,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,IAAI,KAAK,aAAa,QAAW;AAAA,MACtC,uBAAuB;AAAA,MACvB,aAAa;AAAA,IACf,CAAC;AAAA,EACH,SAAQ;AACN,WAA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