Archived
Template
1
Fork 0
This repository has been archived on 2024-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
Contour/public/@shoelace-style/shoelace/cdn/chunks/chunk.QOV364KK.js

51 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2024-01-30 10:59:28 -05:00
import {
LocalizeController
} from "./chunk.NH3SRVOC.js";
import {
ShoelaceElement,
n
} from "./chunk.SEXBCYCU.js";
import {
__decorateClass
} from "./chunk.KIILAQWQ.js";
// src/components/format-bytes/format-bytes.component.ts
var SlFormatBytes = class extends ShoelaceElement {
constructor() {
super(...arguments);
this.localize = new LocalizeController(this);
this.value = 0;
this.unit = "byte";
this.display = "short";
}
render() {
if (isNaN(this.value)) {
return "";
}
const bitPrefixes = ["", "kilo", "mega", "giga", "tera"];
const bytePrefixes = ["", "kilo", "mega", "giga", "tera", "peta"];
const prefix = this.unit === "bit" ? bitPrefixes : bytePrefixes;
const index = Math.max(0, Math.min(Math.floor(Math.log10(this.value) / 3), prefix.length - 1));
const unit = prefix[index] + this.unit;
const valueToFormat = parseFloat((this.value / Math.pow(1e3, index)).toPrecision(3));
return this.localize.number(valueToFormat, {
style: "unit",
unit,
unitDisplay: this.display
});
}
};
__decorateClass([
n({ type: Number })
], SlFormatBytes.prototype, "value", 2);
__decorateClass([
n()
], SlFormatBytes.prototype, "unit", 2);
__decorateClass([
n()
], SlFormatBytes.prototype, "display", 2);
export {
SlFormatBytes
};