{"version":3,"file":"get-notification-data.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAMzC,MAAM,oBAAoB,GAAG;IAC3B,aAAa,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,wBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC;AAHD,0CAGC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,mBAAmB,GAAG,CAAC,YAA6B,EAAU,EAAE;IAC3E,MAAM,WAAW,GAAG,IAAI,wBAAS,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjE,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AACxD,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B;AAEF;;;;;;;;;;;GAWG;AACI,MAAM,YAAY,GAAG,CAC1B,aAAqB,EACrB,IAAoB,EACZ,EAAE;IACV,+BAA+B;IAC/B,MAAM,OAAO,GAAG,EAAE,GAAG,oBAAoB,EAAE,GAAG,IAAI,EAAE,CAAC;IAErD,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAAC,aAAa,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,YAAY,GAAG,CAA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AAa,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB","sourcesContent":["import { BigNumber } from 'bignumber.js';\n\ntype FormatOptions = {\n  decimalPlaces?: number;\n  shouldEllipse?: boolean;\n};\nconst defaultFormatOptions = {\n  decimalPlaces: 4,\n};\n\n/**\n * Calculates the token amount based on the given value and decimals.\n *\n * @param value - The value to calculate the token amount from.\n * @param decimals - The number of decimals to use for the calculation.\n * @returns The calculated token amount.\n */\nexport function calcTokenAmount(value: string, decimals: number): BigNumber {\n  const multiplier = Math.pow(10, Number(decimals || 0));\n  return new BigNumber(String(value)).div(multiplier);\n}\n\n/**\n * Calculates the number of leading zeros in the fractional part of a number.\n *\n * This function converts a number or a string representation of a number into\n * its decimal form and then counts the number of leading zeros present in the\n * fractional part of the number. This is useful for determining the precision\n * of very small numbers.\n *\n * @param numericValue - The number to analyze, which can be in the form\n * of a number or a string.\n * @returns The count of leading zeros in the fractional part of the number.\n */\nexport const getLeadingZeroCount = (numericValue: number | string): number => {\n  const numToString = new BigNumber(numericValue, 10).toString(10);\n  const fractionalPart = numToString.split('.')[1] ?? '';\n  return fractionalPart.match(/^0*/u)?.[0]?.length ?? 0;\n};\n\n/**\n * This formats a number using Intl\n * It abbreviates large numbers (using K, M, B, T)\n * And abbreviates small numbers in 2 ways:\n * - Will format to the given number of decimal places\n * - Will format up to 4 decimal places\n * - Will ellipse the number if longer than given decimal places\n *\n * @param numericAmount - The number to format\n * @param opts - The options to use when formatting\n * @returns The formatted number\n */\nexport const formatAmount = (\n  numericAmount: number,\n  opts?: FormatOptions,\n): string => {\n  // create options with defaults\n  const options = { ...defaultFormatOptions, ...opts };\n\n  const leadingZeros = getLeadingZeroCount(numericAmount);\n  const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;\n  const isLargeNumber = numericAmount > 999;\n\n  const handleShouldEllipse = (decimalPlaces: number): boolean =>\n    Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;\n\n  if (isLargeNumber) {\n    return Intl.NumberFormat('en-US', {\n      notation: 'compact',\n      compactDisplay: 'short',\n      maximumFractionDigits: 2,\n    }).format(numericAmount);\n  }\n\n  if (isDecimal) {\n    const ellipse = handleShouldEllipse(options.decimalPlaces);\n    const formattedValue = Intl.NumberFormat('en-US', {\n      minimumFractionDigits: ellipse ? options.decimalPlaces : undefined,\n      maximumFractionDigits: options.decimalPlaces,\n    }).format(numericAmount);\n\n    return ellipse ? `${formattedValue}...` : formattedValue;\n  }\n\n  // Default to showing the raw amount\n  return numericAmount.toString();\n};\n\nexport const getAmount = (\n  amount: string,\n  decimals: string,\n  options?: FormatOptions,\n): string => {\n  if (!amount || !decimals) {\n    return '';\n  }\n\n  const numericAmount = calcTokenAmount(\n    amount,\n    parseFloat(decimals),\n  ).toNumber();\n\n  return formatAmount(numericAmount, options);\n};\n"]}