()
| 71 | }; |
| 72 | |
| 73 | export function useNumber() { |
| 74 | const locale = 'en-US'; |
| 75 | const format = formatNumber(locale); |
| 76 | const short = shortNumber(locale); |
| 77 | const currency = formatCurrency(locale); |
| 78 | |
| 79 | return { |
| 80 | currency, |
| 81 | format, |
| 82 | short, |
| 83 | shortWithUnit: (value: number | null | undefined, unit?: string | null) => { |
| 84 | if (isNil(value)) { |
| 85 | return 'N/A'; |
| 86 | } |
| 87 | if (unit === 'min') { |
| 88 | return fancyMinutes(value); |
| 89 | } |
| 90 | return `${short(value)}${unit ? ` ${unit}` : ''}`; |
| 91 | }, |
| 92 | formatWithUnit: ( |
| 93 | value: number | null | undefined, |
| 94 | unit?: string | null, |
| 95 | ) => { |
| 96 | if (isNil(value)) { |
| 97 | return 'N/A'; |
| 98 | } |
| 99 | if (unit === 'min') { |
| 100 | return fancyMinutes(value); |
| 101 | } |
| 102 | if (unit === '%') { |
| 103 | return `${format(round(value * 100, 1))}${unit ? ` ${unit}` : ''}`; |
| 104 | } |
| 105 | return `${format(value)}${unit ? ` ${unit}` : ''}`; |
| 106 | }, |
| 107 | }; |
| 108 | } |
no test coverage detected