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

pretty-bytes

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-bytes - npm Package Compare versions

Comparing version 3.0.1 to 4.0.0

21

index.js
'use strict';
var numberIsNan = require('number-is-nan');
const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
module.exports = function (num) {
if (typeof num !== 'number' || numberIsNan(num)) {
throw new TypeError('Expected a number, got ' + typeof num);
module.exports = num => {
if (typeof num !== 'number' || Number.isNaN(num)) {
throw new TypeError(`Expected a number, got ${typeof num}`);
}
var exponent;
var unit;
var neg = num < 0;
var units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const neg = num < 0;

@@ -22,7 +19,7 @@ if (neg) {

exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1);
num = Number((num / Math.pow(1000, exponent)).toFixed(2));
unit = units[exponent];
const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);
const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));
const unit = UNITS[exponent];
return (neg ? '-' : '') + num + ' ' + unit;
return (neg ? '-' : '') + numStr + ' ' + unit;
};
{
"name": "pretty-bytes",
"version": "3.0.1",
"version": "4.0.0",
"description": "Convert bytes to a human readable string: 1337 → 1.34 kB",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},

@@ -35,5 +35,2 @@ "scripts": {

],
"dependencies": {
"number-is-nan": "^1.0.0"
},
"devDependencies": {

@@ -40,0 +37,0 @@ "ava": "*",

@@ -9,3 +9,3 @@ # pretty-bytes [![Build Status](https://travis-ci.org/sindresorhus/pretty-bytes.svg?branch=master)](https://travis-ci.org/sindresorhus/pretty-bytes)

*Note that it uses base-10 (eg. kilobyte).
*Note that it uses base-10 (e.g. kilobyte).
[Read about the difference between kilobyte and kibibyte.](http://pacoup.com/2009/05/26/kb-kb-kib-whats-up-with-that/)*

@@ -41,2 +41,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
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