bigbuffet-rw/app/soapbox/utils/numbers.js
2021-11-16 07:12:55 -06:00

14 lines
422 B
JavaScript

import React from 'react';
import { FormattedNumber } from 'react-intl';
export const isNumber = number => typeof number === 'number' && !isNaN(number);
export const shortNumberFormat = number => {
if (!isNumber(number)) return '•';
if (number < 1000) {
return <FormattedNumber value={number} />;
} else {
return <span><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</span>;
}
};