index.js
function format(value, unitInfo) {
  const unit = unitInfo.unit;
  const precision = unitInfo.precision || 0;
  let v = 0;
  switch (unit) {
    case 'GB':
      v = value / GB;
      break;
    case 'MB':
      v = value / MB;
      break;
    default:
      v = value;
      break;
  }
  v = parseFloat(Number(v).toFixed(precision));
  return v;
}
function format(value, unitInfo) {
  const unit = unitInfo.unit;
  const precision = unitInfo.precision || 0;
  let v = 0;
  switch (unit) {
    case 'GB':
      v = value / GB;
      break;
    case 'MB':
      v = value / MB;
      break;
    default:
      v = value;
      break;
  }
  v = parseFloat(Number(v).toFixed(precision));
  return v;
}
function format ( value , unitInfo ) { const unit = unitInfo . unit ; const precision = unitInfo . precision || 0 ; let v = 0 ; switch ( unit ) { case 'GB' : v = value / GB ; break ; case 'MB' : v = value / MB ; break ; default : v = value ; break ; } v = parseFloat ( Number ( v ) . toFixed ( precision ) ) ; return v ; }
Format the bytes by unit
@param {Number} value Bytes count
@param {Object} unitInfo {unit: String, precision: Number}
unit: 'GB', 'MB' or 'B'
precision: the precision of size, default is 0
@returns {Number}
Format the bytes by unit