logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

file_size_format.js (450B)


  1. const fileSizeFormat = (numArg) => {
  2. const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
  3. let num = numArg
  4. if (num < 1) {
  5. return num + ' ' + units[0]
  6. }
  7. const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1)
  8. num = (num / Math.pow(1024, exponent)).toFixed(2) * 1
  9. const unit = units[exponent]
  10. return { num, unit }
  11. }
  12. const fileSizeFormatService = {
  13. fileSizeFormat
  14. }
  15. export default fileSizeFormatService