mirror of
https://github.com/gethomepage/homepage.git
synced 2026-08-31 01:15:53 -07:00
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
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:
@@ -136,7 +136,7 @@ module.exports = {
|
||||
|
||||
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(
|
||||
parseFloat(value / k ** i),
|
||||
|
||||
@@ -27,11 +27,11 @@ describe("rate formatter", () => {
|
||||
it.each([
|
||||
["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"],
|
||||
["binary bytes as mebibytes", 512, { binary: true, bits: false, decimals: 1 }, "0.0 MiB/s"],
|
||||
["binary kibibytes as mebibytes", 15 * 1024, { 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", 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 gibibytes as mebibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2,048.0 MiB/s"],
|
||||
["binary bits as mebibits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "0.0 Mibit/s"],
|
||||
["binary gibibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2.0 GiB/s"],
|
||||
["binary bits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "15.0 kibit/s"],
|
||||
])("formats %s", (_description, value, options, expected) => {
|
||||
expect(formatRate(value, "en", options)).toBe(expected);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user