mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
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:
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", () => {
|
||||
|
||||
@@ -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, "");
|
||||
|
||||
Reference in new issue
Block a user