|
|
@ -25,6 +25,24 @@ i18n
|
|
|
|
i18n.services.formatter.add("bytes", (value, lng, options) =>
|
|
|
|
i18n.services.formatter.add("bytes", (value, lng, options) =>
|
|
|
|
prettyBytes(parseFloat(value), { locale: lng, ...options })
|
|
|
|
prettyBytes(parseFloat(value), { locale: lng, ...options })
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i18n.services.formatter.add("rate", (value, lng, options) => {
|
|
|
|
|
|
|
|
if (value === 0) return "0 Bps";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bits = options.bits ? value : value / 8;
|
|
|
|
|
|
|
|
const k = 1024;
|
|
|
|
|
|
|
|
const dm = options.decimals ? options.decimals : 0;
|
|
|
|
|
|
|
|
const sizes = ["Bps", "Kbps", "Mbps", "Gbps", "Tbps", "Pbps", "Ebps", "Zbps", "Ybps"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const i = Math.floor(Math.log(bits) / Math.log(k));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formatted = new Intl.NumberFormat(lng, { maximumFractionDigits: dm, minimumFractionDigits: dm }).format(
|
|
|
|
|
|
|
|
parseFloat(bits / k ** i)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return `${formatted} ${sizes[i]}`;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
i18n.services.formatter.add("percent", (value, lng, options) =>
|
|
|
|
i18n.services.formatter.add("percent", (value, lng, options) =>
|
|
|
|
new Intl.NumberFormat(lng, { style: "percent", ...options }).format(parseFloat(value) / 100.0)
|
|
|
|
new Intl.NumberFormat(lng, { style: "percent", ...options }).format(parseFloat(value) / 100.0)
|
|
|
|
);
|
|
|
|
);
|
|
|
|