Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@transloadit/prettier-bytes

Package Overview
Dependencies
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transloadit/prettier-bytes - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

4

package.json
{
"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 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc