import moment from 'moment'

const toDuration = function (second) {
  return moment({ hour: 0, minute: 0, second: 0 }).second(second).format('mm:ss')
}

let bytesToSize = function (bytes) {
  let sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
  if (bytes === 0) {
    return 'n/a'
  }
  let i = Math.ceil(Math.floor(Math.log(bytes) / Math.log(1024)))
  return `${Math.round(bytes / Math.pow(1024, i), 2)} ${sizes[i]}`
}

export default {
  toDuration,
  bytesToSize
}
