mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-14 13:16:11 +01:00
feat: generalize render chars
This commit is contained in:
1 parent
99bae8f2c5
commit
698731cb9a
4 files changed
+41
-36
No files matched your search
@@ -0,0 +1,23 @@
|
||||
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(", ");
|
||||
}
|
||||
Reference in new issue
Block a user