mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-14 13:16:11 +01:00
30 lines
832 B
TypeScript
30 lines
832 B
TypeScript
import type { CharacteristicOutput } from "./characteristics";
|
|
import type { CharacteristicRenderConfig } from "./characteristicsOrder";
|
|
|
|
export function renderCharacteristic(
|
|
characteristic: CharacteristicOutput,
|
|
config: CharacteristicRenderConfig
|
|
): string | null {
|
|
if (characteristic === null) return null;
|
|
|
|
if (config.render) return config.render(characteristic);
|
|
|
|
if (typeof characteristic === "number") {
|
|
if (Number.isFinite(characteristic)) {
|
|
if (config.decimals === undefined) {
|
|
return characteristic.toString();
|
|
}
|
|
|
|
return characteristic.toFixed(config.decimals);
|
|
}
|
|
|
|
return `${characteristic < 0 ? "-" : ""}∞`;
|
|
}
|
|
|
|
if (typeof characteristic === "string") {
|
|
return characteristic;
|
|
}
|
|
|
|
return characteristic.map((c) => renderCharacteristic(c, config)).join(", ");
|
|
}
|