bigbuffet-rw/app/soapbox/utils/numbers.js
2021-07-13 14:26:34 -05:00

14 lines
415 B
JavaScript

import React from 'react';
import { FormattedNumber } from 'react-intl';
const isNumber = number => typeof number === 'number' && number !== NaN;
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>;
}
};