diff --git a/packages/bruno-app/src/themes/light.js b/packages/bruno-app/src/themes/light.js
index e95b0e45e..55b1d0eaf 100644
--- a/packages/bruno-app/src/themes/light.js
+++ b/packages/bruno-app/src/themes/light.js
@@ -7,7 +7,7 @@ const lightTheme = {
colors: {
text: {
green: '#047857',
- danger: 'rgb(185, 28, 28)',
+ danger: '#B91C1C',
muted: '#838383',
purple: '#8e44ad',
yellow: '#d97706'
diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js
index 937e1a3b5..f839ba850 100644
--- a/packages/bruno-app/src/utils/common/index.js
+++ b/packages/bruno-app/src/utils/common/index.js
@@ -196,4 +196,23 @@ export const getEncoding = (headers) => {
export const multiLineMsg = (...messages) => {
return messages.filter(m => m !== undefined && m !== null && m !== '').join('\n');
+}
+
+export const formatSize = (bytes) => {
+ // Handle invalid inputs
+ if (isNaN(bytes) || typeof bytes !== 'number') {
+ return '0B';
+ }
+
+ if (bytes < 1024) {
+ return bytes + 'B';
+ }
+ if (bytes < 1024 * 1024) {
+ return (bytes / 1024).toFixed(1) + 'KB';
+ }
+ if (bytes < 1024 * 1024 * 1024) {
+ return (bytes / (1024 * 1024)).toFixed(1) + 'MB';
+ }
+
+ return (bytes / (1024 * 1024 * 1024)).toFixed(1) + 'GB';
}
\ No newline at end of file
diff --git a/packages/bruno-app/src/utils/common/index.spec.js b/packages/bruno-app/src/utils/common/index.spec.js
index 81153674a..89eeebf2e 100644
--- a/packages/bruno-app/src/utils/common/index.spec.js
+++ b/packages/bruno-app/src/utils/common/index.spec.js
@@ -1,6 +1,6 @@
const { describe, it, expect } = require('@jest/globals');
-import { normalizeFileName, startsWith, humanizeDate, relativeDate, getContentType } from './index';
+import { normalizeFileName, startsWith, humanizeDate, relativeDate, getContentType, formatSize } from './index';
describe('common utils', () => {
describe('normalizeFileName', () => {
@@ -148,4 +148,40 @@ describe('common utils', () => {
expect(getContentType(undefined)).toBe('');
});
});
+
+ describe('formatSize', () => {
+ it('should format bytes', () => {
+ expect(formatSize(0)).toBe('0B');
+ expect(formatSize(1023)).toBe('1023B');
+ });
+
+ it('should format kilobytes', () => {
+ expect(formatSize(1024)).toBe('1.0KB');
+ expect(formatSize(1048575)).toBe('1024.0KB');
+ });
+
+ it('should format megabytes', () => {
+ expect(formatSize(1048576)).toBe('1.0MB');
+ expect(formatSize(1073741823)).toBe('1024.0MB');
+ });
+
+ it('should format gigabytes', () => {
+ expect(formatSize(1073741824)).toBe('1.0GB');
+ expect(formatSize(1099511627776)).toBe('1024.0GB');
+ });
+
+ it('should format decimal values', () => {
+ expect(formatSize(1126.5)).toBe('1.1KB');
+ expect(formatSize(1153433.6)).toBe('1.1MB');
+ expect(formatSize(1153433600)).toBe('1.1GB');
+ expect(formatSize(1024.1)).toBe('1.0KB');
+ expect(formatSize(1048576.1)).toBe('1.0MB');
+ });
+
+ it('should format invalid inputs', () => {
+ expect(formatSize(null)).toBe('0B');
+ expect(formatSize(undefined)).toBe('0B');
+ expect(formatSize(NaN)).toBe('0B');
+ });
+ });
});