MCPcopy
hub / github.com/home-assistant/frontend / bytesToString

Function bytesToString

src/util/bytes-to-string.ts:1–10  ·  view source on GitHub ↗
(value = 0, decimals = 2)

Source from the content-addressed store, hash-verified

1export const bytesToString = (value = 0, decimals = 2): string => {
2 if (value === 0) {
3 return "0 Bytes";
4 }
5 const k = 1024;
6 decimals = decimals < 0 ? 0 : decimals;
7 const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
8 const i = Math.floor(Math.log(value) / Math.log(k));
9 return `${parseFloat((value / k ** i).toFixed(decimals))} ${sizes[i]}`;
10};

Callers 7

renderMethod · 0.90
_renderControlsCardMethod · 0.90
renderMethod · 0.90
renderMethod · 0.90
_renderSizeEstimateMethod · 0.90
renderMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…