7 lines
311 B
JavaScript
7 lines
311 B
JavaScript
// TODO: Try to implement this: https://twitter.com/fireship_dev/status/1565424801216311297
|
|
export const kFormatter = num => {
|
|
const regex = /\B(?=(\d{3})+(?!\d))/g
|
|
|
|
return Math.abs(num) > 9999 ? `${Math.sign(num) * +((Math.abs(num) / 1000).toFixed(1))}k` : Math.abs(num).toFixed(0).replace(regex, ',')
|
|
}
|