const RANGE = 1000 // 1000 for MB, 1024 for MiB.
const PRECISION = 0 // Decimal places.

export default function getSize (string) {
  if (typeof string !== 'string') {
    throw new TypeError('Invalid type')
  }
  const number = Number.parseInt(string, 10)
  const i = Math.max(Math.floor(Math.log(number) / Math.log(RANGE)), 0)
  return `${Number((number / Math.pow(RANGE, i)).toFixed(PRECISION)) * 1} ${['B', 'kB', 'MB', 'GB', 'TB'][i]}`
}
