@transloadit/prettier-bytes
Advanced tools
Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "@transloadit/prettier-bytes", | ||
"license": "MIT", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"private": false, | ||
@@ -15,3 +15,3 @@ "publishConfig": { | ||
"main": "./prettierBytes.js", | ||
"gitHead": "262a707c720fb52cf7e0e0488c5c870f2b3ffbc6" | ||
"gitHead": "1d649aa77fbabed471420f73f9433954452743bd" | ||
} |
@@ -6,7 +6,7 @@ // Adapted from https://github.com/Flet/prettier-bytes/ | ||
if (typeof num !== 'number' || isNaN(num)) { | ||
throw new TypeError('Expected a number, got ' + typeof num) | ||
throw new TypeError(`Expected a number, got ${typeof num}`) | ||
} | ||
var neg = num < 0 | ||
var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | ||
const neg = num < 0 | ||
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | ||
@@ -18,8 +18,8 @@ if (neg) { | ||
if (num < 1) { | ||
return (neg ? '-' : '') + num + ' B' | ||
return `${(neg ? '-' : '') + num} B` | ||
} | ||
var exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1) | ||
const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1) | ||
num = Number(num / Math.pow(1024, exponent)) | ||
var unit = units[exponent] | ||
const unit = units[exponent] | ||
@@ -29,6 +29,5 @@ if (num >= 10 || num % 1 === 0) { | ||
// decimal component. | ||
return (neg ? '-' : '') + num.toFixed(0) + ' ' + unit | ||
} else { | ||
return (neg ? '-' : '') + num.toFixed(1) + ' ' + unit | ||
return `${(neg ? '-' : '') + num.toFixed(0)} ${unit}` | ||
} | ||
return `${(neg ? '-' : '') + num.toFixed(1)} ${unit}` | ||
} |
@@ -24,3 +24,3 @@ const prettierBytes = require('./prettierBytes') | ||
it('should convert the specified number of bytes to a human-readable string like 236 MB', () => { | ||
testData.forEach(function (data) { | ||
testData.forEach((data) => { | ||
expect(prettierBytes(data[0])).toEqual(data[1]) | ||
@@ -27,0 +27,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3946
61