From d4e7754b1a37e6c76bbbb2a783f91dfc72a723b0 Mon Sep 17 00:00:00 2001 From: James Mockett <1166188+jamesmockett@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:20:36 +0000 Subject: [PATCH] Add comment to conversion function --- libs/@guardian/source-foundations/src/utils/typography.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/@guardian/source-foundations/src/utils/typography.ts b/libs/@guardian/source-foundations/src/utils/typography.ts index 7b8832b7d..5efba090e 100644 --- a/libs/@guardian/source-foundations/src/utils/typography.ts +++ b/libs/@guardian/source-foundations/src/utils/typography.ts @@ -1,10 +1,15 @@ -const REGEX_FONT_SIZE = /font-size:\s(\d+\.\d+)rem/; +/* + * Convert font size in typography preset from default rem value to pixels + */ export const presetToPx = (preset: string) => { + const REGEX_FONT_SIZE = /font-size:\s(\d+\.\d+)rem/; + const matches = preset.match(REGEX_FONT_SIZE); if (matches?.[1]) { const pxVal = parseFloat(matches[1]) * 16; return preset.replace(REGEX_FONT_SIZE, `font-size: ${pxVal}px`); } + return preset; };