mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-14 21:26:08 +01:00
23 lines
696 B
TypeScript
23 lines
696 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 (typeof characteristic === "number") {
|
||
|
|
if (Number.isFinite(characteristic)) {
|
||
|
|
if (config.decimals === undefined) {
|
||
|
|
return characteristic.toString();
|
||
|
|
}
|
||
|
|
|
||
|
|
return characteristic.toFixed(config.decimals);
|
||
|
|
}
|
||
|
|
|
||
|
|
return `${characteristic < 0 ? "-" : ""}∞`;
|
||
|
|
}
|
||
|
|
|
||
|
|
return characteristic.map((c) => renderCharacteristic(c, config)).join(", ");
|
||
|
|
}
|