number-format.js 381 B

12345678910111213
  1. export function abbreviateCount(value, unit) {
  2. let n = value
  3. if (unit === 'thousand') {
  4. if (n > 9999) n = (n / 10000).toFixed(1) + 'w'
  5. else if (n > 999) n = (n / 1000).toFixed(1) + 'k'
  6. }
  7. if (unit === 'hundred' && n > 99) n = '99+'
  8. return n
  9. }
  10. export function bytesToMegabytes(limit, withUnit = true) {
  11. return (limit / (1024 * 1024)).toFixed(1) + (withUnit ? 'MB' : '')
  12. }