Question : convert kb, mb, gb, tb to bytes
Answered by : topollo
function toBytes(size, type)
{ const types = ["B", "KB", "MB", "GB", "TB"]; const key = types.indexOf(type.toUpperCase()) if (typeof key !== "boolean") { return size * Math.pow(1024, key); } return "invalid type: type must be GB/KB/MB etc.";
}
console.log(toBytes(5, 'GB'))
Source : | Last Update : Fri, 24 Jun 22