fix(import): match the molar-mass annotation by the shape Apple writes

The catch-all angle-bracket pattern read as an HTML sanitiser to static analysis. The annotation Apple writes is a number, so the pattern now matches exactly that, and a unit with anything else between the brackets stays unknown instead of being silently trimmed into a lookup.
This commit is contained in:
Marc-André Bombeck committed 2026-09-10 03:25:16 +02:00
1 parent 3d163d3602
commit fd337a4e7a
2 files changed
+7 -3

No files matched your search

@@ -30,6 +30,8 @@ describe("convertHkValue", () => {
99.0858,
4,
);
expect(isConvertibleHkUnit("mmol<180>/L")).toBe(true);
expect(isConvertibleHkUnit("mmol<x>/L")).toBe(false);
});
it("keeps the small calorie apart from the large one", () => {
+5 -3
View File
@@ -120,10 +120,12 @@ const HK_UNITS: Record<string, HkUnitSpec> = {
/**
* Apple writes molar units with the substance's molar mass inline —
* `mmol<180.156>/L` for blood glucose. The annotation is informational;
* strip it so the lookup sees the plain unit.
* `mmol<180.156>/L` for blood glucose. The annotation is a number and
* informational; strip exactly that shape so the lookup sees the plain
* unit. Anything else between angle brackets is not a unit Apple writes
* and stays unknown.
*/
const MOLAR_MASS_ANNOTATION = /<[^>]*>/g;
const MOLAR_MASS_ANNOTATION = /<\d+(?:\.\d+)?>/g;
function normaliseUnitString(unit: string): string {
return unit.trim().replace(MOLAR_MASS_ANNOTATION, "");