{"version":3,"file":"numberFormattingFunction-Bez6GYgm.cjs","names":[],"sources":["../src/Utils/numberFormattingFunction.ts"],"sourcesContent":["import type { PadZerosTypes } from '@/Types';\r\nimport { checkIfNullOrUndefined } from './checkIfNullOrUndefined';\r\n\r\n/**\r\n * Formats a number into a human-readable string, optionally with prefix/suffix\r\n * and locale-aware formatting.\r\n *\r\n * Supports:\r\n * - Compact notation (K, M, B, T)\r\n * - Locale formatting via Intl.NumberFormat\r\n * - Prefix and suffix\r\n * - NA fallback\r\n */\r\n\r\nconst formatWithLocale = (\r\n  num: number,\r\n  precisionValue: number,\r\n  locale?: string,\r\n  padZeros?: boolean,\r\n) => {\r\n  return new Intl.NumberFormat(locale || 'en', {\r\n    minimumFractionDigits: padZeros && num !== 0 ? precisionValue : 0,\r\n    maximumFractionDigits: precisionValue,\r\n    useGrouping: false,\r\n  }).format(num);\r\n};\r\nconst formatCompact = (n: number, precisionValue: number, locale?: string, padZeros?: boolean) => {\r\n  const suffixes = ['', 'K', 'M', 'B', 'T'];\r\n  const tier = Math.floor(Math.log10(Math.abs(n)) / 3);\r\n\r\n  if (tier === 0) {\r\n    return formatWithLocale(n, precisionValue, locale, padZeros);\r\n  }\r\n\r\n  const scaled = n / 10 ** (tier * 3);\r\n  const formatted = formatWithLocale(scaled, precisionValue, locale, padZeros);\r\n\r\n  return formatted + suffixes[tier];\r\n};\r\nexport function numberFormattingFunction(\r\n  value: number | string | undefined | null,\r\n  naLabel?: string,\r\n  precision?: number,\r\n  prefix?: string,\r\n  suffix?: string,\r\n  locale?: string,\r\n  padZeros?: PadZerosTypes,\r\n) {\r\n  if (checkIfNullOrUndefined(value)) return naLabel || 'NA';\r\n\r\n  if (typeof value === 'string') {\r\n    return `${prefix || ''}${value}${suffix || ''}`;\r\n  }\r\n\r\n  if (checkIfNullOrUndefined(value)) {\r\n    return naLabel || 'NA';\r\n  }\r\n  const num = value as number;\r\n  // Small numbers (no compacting)\r\n  if (Math.abs(num) < 1000 && Number.isInteger(num)) {\r\n    return `${prefix || ''}${formatWithLocale(num, precision ?? 0, locale, padZeros === 'all')}${suffix || ''}`;\r\n  }\r\n  const formattedNumber =\r\n    Math.abs(num) < 1000\r\n      ? formatWithLocale(num, precision ?? 2, locale, padZeros === 'all' || padZeros === 'decimal')\r\n      : formatCompact(num, precision ?? 2, locale, padZeros === 'all' || padZeros === 'decimal');\r\n\r\n  return `${prefix || ''}${formattedNumber}${suffix || ''}`;\r\n}\r\n"],"mappings":"yDAcA,IAAM,GACJ,EACA,EACA,EACA,IAEO,IAAI,KAAK,aAAa,GAAU,KAAM,CAC3C,sBAAuB,GAAY,IAAQ,EAAI,EAAiB,EAChE,sBAAuB,EACvB,YAAa,EACf,CAAC,EAAE,OAAO,CAAG,EAET,GAAiB,EAAW,EAAwB,EAAiB,IAAuB,CAChG,IAAM,EAAW,CAAC,GAAI,IAAK,IAAK,IAAK,GAAG,EAClC,EAAO,KAAK,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,EAAI,CAAC,EASnD,OAPI,IAAS,EACJ,EAAiB,EAAG,EAAgB,EAAQ,CAAQ,EAI3C,EADH,EAAI,KAAO,EAAO,GACU,EAAgB,EAAQ,CAE5D,EAAY,EAAS,EAC9B,EACA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACA,EACA,EACA,CACA,GAAI,EAAA,EAAuB,CAAK,EAAG,OAAO,GAAW,KAErD,GAAI,OAAO,GAAU,SACnB,MAAO,GAAG,GAAU,KAAK,IAAQ,GAAU,KAG7C,GAAI,EAAA,EAAuB,CAAK,EAC9B,OAAO,GAAW,KAEpB,IAAM,EAAM,EAEZ,GAAI,KAAK,IAAI,CAAG,EAAI,KAAQ,OAAO,UAAU,CAAG,EAC9C,MAAO,GAAG,GAAU,KAAK,EAAiB,EAAK,GAAa,EAAG,EAAQ,IAAa,KAAK,IAAI,GAAU,KAEzG,IAAM,EACJ,KAAK,IAAI,CAAG,EAAI,IACZ,EAAiB,EAAK,GAAa,EAAG,EAAQ,IAAa,OAAS,IAAa,SAAS,EAC1F,EAAc,EAAK,GAAa,EAAG,EAAQ,IAAa,OAAS,IAAa,SAAS,EAE7F,MAAO,GAAG,GAAU,KAAK,IAAkB,GAAU,IACvD"}