Files
streamyfin/augmentations/number.ts
Lance Chant 796e12b4ac Chore: fix the storage reading and search colour
Fixed the storage calc to be GB instead of GIB so changed to 1000
instead of 1024
Changed some of the search colours

Signed-off-by: Lance Chant <13349722+lancechant@users.noreply.github.com>
2026-05-26 14:24:37 +02:00

36 lines
934 B
TypeScript

declare global {
interface Number {
bytesToReadable(decimals?: number): string;
secondsToMilliseconds(): number;
minutesToMilliseconds(): number;
hoursToMilliseconds(): number;
}
}
Number.prototype.bytesToReadable = function (decimals = 2) {
const bytes = this.valueOf();
if (bytes === 0) return "0 Bytes";
const k = 1000;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${Number.parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
};
Number.prototype.secondsToMilliseconds = function () {
return this.valueOf() * 1000;
};
Number.prototype.minutesToMilliseconds = function () {
return this.valueOf() * (60).secondsToMilliseconds();
};
Number.prototype.hoursToMilliseconds = function () {
return this.valueOf() * (60).minutesToMilliseconds();
};
export {};