3 * Parse byte `size` string.
10 module.exports = function(size) {
11 if ('number' == typeof size) return convert(size);
12 var parts = size.match(/^(\d+(?:\.\d+)?) *(kb|mb|gb|tb)$/)
13 , n = parseFloat(parts[1])
20 , tb: ((1 << 30) * 1024)
27 * convert bytes into string.
29 * @param {Number} b - bytes to convert
34 function convert (b) {
35 var tb = ((1 << 30) * 1024), gb = 1 << 30, mb = 1 << 20, kb = 1 << 10, abs = Math.abs(b);
36 if (abs >= tb) return (Math.round(b / tb * 100) / 100) + 'tb';
37 if (abs >= gb) return (Math.round(b / gb * 100) / 100) + 'gb';
38 if (abs >= mb) return (Math.round(b / mb * 100) / 100) + 'mb';
39 if (abs >= kb) return (Math.round(b / kb * 100) / 100) + 'kb';