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

@transloadit/prettier-bytes

Package Overview
Dependencies
Maintainers
5
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.3.4 to 0.3.5

.turbo/turbo-build.log

2

dist/prettierBytes.d.ts

@@ -1,2 +0,2 @@

declare const _default: (num: number) => string;
declare const _default: (input: number) => string;
export = _default;
"use strict";
module.exports = function prettierBytes(num) {
if (typeof num !== 'number' || Number.isNaN(num)) {
throw new TypeError(`Expected a number, got ${typeof num}`);
module.exports = function prettierBytes(input) {
if (typeof input !== 'number' || Number.isNaN(input)) {
throw new TypeError(`Expected a number, got ${typeof input}`);
}
const neg = num < 0;
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const neg = input < 0;
let num = Math.abs(input);
if (neg) {
num = -num;
}
if (num < 1) {
return `${(neg ? '-' : '') + num} B`;
if (num === 0) {
return '0 B';
}
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1);
num = Number(num / 1024 ** exponent);
const value = Number(num / 1024 ** exponent);
const unit = units[exponent];
if (num >= 10 || num % 1 === 0) {
return `${(neg ? '-' : '') + num.toFixed(0)} ${unit}`;
}
return `${(neg ? '-' : '') + num.toFixed(1)} ${unit}`;
return `${value >= 10 || value % 1 === 0 ? Math.round(value) : value.toFixed(1)} ${unit}`;
};
//# sourceMappingURL=prettierBytes.js.map
{
"name": "@transloadit/prettier-bytes",
"version": "0.3.4",
"version": "0.3.5",
"repository": {

@@ -12,14 +12,11 @@ "type": "git",

"types": "dist/prettierBytes.d.ts",
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1",
"tsc": "tsc --build --clean && tsc --build"
"build": "tsc --build --clean && tsc --build",
"typecheck": "tsc --noEmit",
"test": "tsx --test src/**/*.test.ts",
"test:watch": "tsx --test --watch src/**/*.test.ts"
},
"publishConfig": {
"access": "public"
},
"gitHead": "714bbf75e54490ceb20bea49a728230668d456c1"
}
}
// Adapted from https://github.com/Flet/prettier-bytes/
// Changing 1000 bytes to 1024, so we can keep uppercase KB vs kB
// ISC License (c) Dan Flettre https://github.com/Flet/prettier-bytes/blob/master/LICENSE
export = function prettierBytes(num: number): string {
if (typeof num !== 'number' || Number.isNaN(num)) {
throw new TypeError(`Expected a number, got ${typeof num}`)
export = function prettierBytes(input: number): string {
if (typeof input !== 'number' || Number.isNaN(input)) {
throw new TypeError(`Expected a number, got ${typeof input}`)
}
const neg = num < 0
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const neg = input < 0
let num = Math.abs(input)

@@ -16,17 +16,12 @@ if (neg) {

if (num < 1) {
return `${(neg ? '-' : '') + num} B`
if (num === 0) {
return '0 B'
}
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1)
num = Number(num / 1024 ** exponent)
const value = Number(num / 1024 ** exponent)
const unit = units[exponent]
if (num >= 10 || num % 1 === 0) {
// Do not show decimals when the number is two-digit, or if the number has no
// decimal component.
return `${(neg ? '-' : '') + num.toFixed(0)} ${unit}`
}
return `${(neg ? '-' : '') + num.toFixed(1)} ${unit}`
return `${value >= 10 || value % 1 === 0 ? Math.round(value) : value.toFixed(1)} ${unit}`
}

Sorry, the diff of this file is not supported yet

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