mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useCallback} from 'react' 2import {useLingui} from '@lingui/react' 3 4/** 5 * This matches `formatCount` from `view/com/util/numeric/format.ts`, but has 6 * additional truncation logic for large numbers. `roundingMode` should always 7 * match the original impl, regardless of if we add more formatting here. 8 */ 9export function useFormatPostStatCount() { 10 const {i18n} = useLingui() 11 12 return useCallback( 13 (postStatCount: number) => { 14 const isOver10k = postStatCount >= 10_000 15 return i18n.number(postStatCount, { 16 notation: 'compact', 17 maximumFractionDigits: isOver10k ? 0 : 1, 18 // @ts-expect-error - roundingMode not in the types 19 roundingMode: 'trunc', 20 }) 21 }, 22 [i18n], 23 ) 24}