Fix: auto-scale binary rate units instead of pinning to MiB/s (#6866)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
TowyTowy
2026-07-13 17:27:07 +02:00
committed by GitHub
parent e31a8f3776
commit 2c3b82a826
2 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ module.exports = {
const dm = options.decimals ? options.decimals : 0; const dm = options.decimals ? options.decimals : 0;
const i = options.binary ? 2 : Math.floor(Math.log(value) / Math.log(k)); const i = Math.floor(Math.log(value) / Math.log(k));
const formatted = new Intl.NumberFormat(lng, { maximumFractionDigits: dm, minimumFractionDigits: dm }).format( const formatted = new Intl.NumberFormat(lng, { maximumFractionDigits: dm, minimumFractionDigits: dm }).format(
parseFloat(value / k ** i), parseFloat(value / k ** i),
+4 -4
View File
@@ -27,11 +27,11 @@ describe("rate formatter", () => {
it.each([ it.each([
["zero bytes", 0, { binary: true, bits: false, decimals: 1 }, "0 B/s"], ["zero bytes", 0, { binary: true, bits: false, decimals: 1 }, "0 B/s"],
["decimal bytes", 15_000, { binary: false, bits: false, decimals: 1 }, "15.0 kB/s"], ["decimal bytes", 15_000, { binary: false, bits: false, decimals: 1 }, "15.0 kB/s"],
["binary bytes as mebibytes", 512, { binary: true, bits: false, decimals: 1 }, "0.0 MiB/s"], ["binary bytes", 512, { binary: true, bits: false, decimals: 1 }, "512.0 B/s"],
["binary kibibytes as mebibytes", 15 * 1024, { binary: true, bits: false, decimals: 1 }, "0.0 MiB/s"], ["binary kibibytes", 15 * 1024, { binary: true, bits: false, decimals: 1 }, "15.0 kiB/s"],
["binary mebibytes", 15 * 1024 ** 2, { binary: true, bits: false, decimals: 1 }, "15.0 MiB/s"], ["binary mebibytes", 15 * 1024 ** 2, { binary: true, bits: false, decimals: 1 }, "15.0 MiB/s"],
["binary gibibytes as mebibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2,048.0 MiB/s"], ["binary gibibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2.0 GiB/s"],
["binary bits as mebibits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "0.0 Mibit/s"], ["binary bits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "15.0 kibit/s"],
])("formats %s", (_description, value, options, expected) => { ])("formats %s", (_description, value, options, expected) => {
expect(formatRate(value, "en", options)).toBe(expected); expect(formatRate(value, "en", options)).toBe(expected);
}); });