diff --git a/packages/rolldown/src/app/components/display/FileSizeBadge.vue b/packages/rolldown/src/app/components/display/FileSizeBadge.vue index 14f10558..cc0c185c 100644 --- a/packages/rolldown/src/app/components/display/FileSizeBadge.vue +++ b/packages/rolldown/src/app/components/display/FileSizeBadge.vue @@ -20,7 +20,7 @@ const props = withDefaults( }, ) -const KB = 1024 +const KB = 1000 const MB = KB ** 2 const colorScale = [ diff --git a/packages/rolldown/src/app/utils/__tests__/format.test.ts b/packages/rolldown/src/app/utils/__tests__/format.test.ts index 61e1dc91..2b8333ad 100644 --- a/packages/rolldown/src/app/utils/__tests__/format.test.ts +++ b/packages/rolldown/src/app/utils/__tests__/format.test.ts @@ -3,20 +3,20 @@ import { describe, expect, it } from 'vitest' import { bytesToHumanSize, getContentByteSize, toTree } from '../format' describe('bytesToHumanSize', () => { - it('should return raw bytes (<1024)', () => { + it('should return raw bytes (<1000)', () => { expect(bytesToHumanSize(10)).toEqual([10, 'B']) }) it('should return kb with proper digits', () => { - expect(bytesToHumanSize(1024)).toEqual(['1', 'KB']) - expect(bytesToHumanSize(1024 * 1.5)).toEqual(['1.5', 'KB']) - expect(bytesToHumanSize(1024 * 1.666, 1)).toEqual(['1.7', 'KB']) + expect(bytesToHumanSize(1000)).toEqual(['1', 'kB']) + expect(bytesToHumanSize(1000 * 1.5)).toEqual(['1.5', 'kB']) + expect(bytesToHumanSize(1000 * 1.666, 1)).toEqual(['1.7', 'kB']) }) it('should return mb with proper digits', () => { - expect(bytesToHumanSize(1024 * 1024)).toEqual(['1', 'MB']) - expect(bytesToHumanSize(1024 * 1024 * 1.5)).toEqual(['1.5', 'MB']) - expect(bytesToHumanSize(1024 * 1024 * 1.666, 1)).toEqual(['1.7', 'MB']) + expect(bytesToHumanSize(1000 * 1000)).toEqual(['1', 'MB']) + expect(bytesToHumanSize(1000 * 1000 * 1.5)).toEqual(['1.5', 'MB']) + expect(bytesToHumanSize(1000 * 1000 * 1.666, 1)).toEqual(['1.7', 'MB']) }) // larger... diff --git a/packages/rolldown/src/app/utils/format.ts b/packages/rolldown/src/app/utils/format.ts index 87148dff..30a9bfb6 100644 --- a/packages/rolldown/src/app/utils/format.ts +++ b/packages/rolldown/src/app/utils/format.ts @@ -1,11 +1,11 @@ import type { ModuleDest, ModuleTreeNode } from '../../shared/types' export function bytesToHumanSize(bytes: number, digits = 2) { - const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'] - const i = Math.floor(Math.log(bytes) / Math.log(1024)) + const sizes = ['Bytes', 'kB', 'MB', 'GB', 'TB'] + const i = Math.floor(Math.log(bytes) / Math.log(1000)) if (i === 0) return [bytes, 'B'] - return [(+(bytes / 1024 ** i).toFixed(digits)).toLocaleString(), sizes[i]] + return [(+(bytes / 1000 ** i).toFixed(digits)).toLocaleString(), sizes[i]] } export function getContentByteSize(content: string) {