World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
Display numeric physical quantities with their units after the value (#1143)
Rudy Mizrahi Celekli2bab83cfb232
diff --git a/web/src/objectValue.ts b/web/src/objectValue.tsindex 6378827c..f650295c 100644--- a/web/src/objectValue.ts+++ b/web/src/objectValue.ts@@ -19,7 +19,8 @@ export function fmtObjectValue(v: Record<string, unknown> | null): string | nullnotation: Math.abs(v.value) >= 10000 ? "compact" : "standard",maximumFractionDigits: 2,}).format(v.value);- return `${unit}${n}`;+ // Currency symbols precede an amount; physical units follow a quantity.+ return /\p{Sc}/u.test(unit) ? `${unit}${n}` : `${n} ${unit}`;}const val = String(v.value);if (!unit) return val;diff --git a/web/src/objectValue.units.test.ts b/web/src/objectValue.units.test.tsnew file mode 100644index 00000000..351a9347--- /dev/null+++ b/web/src/objectValue.units.test.ts@@ -0,0 +1,11 @@+import { describe, expect, it } from "vitest";+import { fmtObjectValue } from "./objectValue";++describe("adopted physical quantities", () => {+ it.each(["kg", "MW", "km", "m²"])("keeps %s after the numeric quantity", (unit) => {+ expect(fmtObjectValue({ value: 42, unit })).toBe(`42 ${unit}`);+ });+ it("still places currency symbols before adopted amounts", () => {+ expect(fmtObjectValue({ value: 42, unit: "$" })).toBe("$42");+ });+});