From 2ec39369a6c99d02141216338915a836815a25de Mon Sep 17 00:00:00 2001 From: JeroenRoodIHS <37173130+JeroenRoodIHS@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:46:40 +0100 Subject: [PATCH 1/3] Right the heuristic wrongs Support naming conventions of any casing, and be indiscriminate on separators (currently supporting: "-", "_" and "."). --- src/utils/text/getFontWeight.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/utils/text/getFontWeight.ts b/src/utils/text/getFontWeight.ts index 4410152..02148f5 100644 --- a/src/utils/text/getFontWeight.ts +++ b/src/utils/text/getFontWeight.ts @@ -1,17 +1,16 @@ -export const getFontWeight = (fontWeight: string) => { - const inputFontWeight = fontWeight.toLowerCase(); - +function getFontWeight(fontWeight){ + const inputFontWeight = fontWeight.toLowerCase().replaceAll(/[-_.]/gi,""); const weights = { 100 : ["thin", "hairline", "100"], - 200 : ["extra-light", "extraLight", "ultra-light", "ultraLight", "200"], + 200 : ["extralight","ultralight", "200"], 300 : ["light", "300"], 400 : ["normal", "regular", "book", "400"], 500 : ["medium", "500"], - 600 : ["semi-bold", "semiBold", "demi-bold", "demiBold", "600"], + 600 : ["semibold", "demibold", "600"], 700 : ["bold", "700"], - 800 : ["ultra-bold", "ultraBold", "extra-bold", "extraBold", "800"], + 800 : ["ultrabold", "extrabold", "800"], 900 : ["black", "heavy", "900"], - 950 : ["extra-black", "ultra-black", "extraBlack", "ultraBlack", "950"] + 950 : ["extrablack", "ultrablack", "950"] } return Object.keys(weights).find(weight => weights[weight].includes(inputFontWeight)) || 400; -}; +} From c184a131863d516dd5bd9ea3174caeef7b03529c Mon Sep 17 00:00:00 2001 From: JeroenRoodIHS <37173130+JeroenRoodIHS@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:01:02 +0100 Subject: [PATCH 2/3] Update getFontWeight.ts, resolve merge conflict --- src/utils/text/getFontWeight.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/text/getFontWeight.ts b/src/utils/text/getFontWeight.ts index 02148f5..727d766 100644 --- a/src/utils/text/getFontWeight.ts +++ b/src/utils/text/getFontWeight.ts @@ -12,5 +12,5 @@ function getFontWeight(fontWeight){ 900 : ["black", "heavy", "900"], 950 : ["extrablack", "ultrablack", "950"] } - return Object.keys(weights).find(weight => weights[weight].includes(inputFontWeight)) || 400; + return Number(Object.keys(weights).find(weight => weights[weight].includes(inputFontWeight))) || 400; } From c36a77503b2eda908d56d4d6a36959ae66974678 Mon Sep 17 00:00:00 2001 From: JeroenRoodIHS <37173130+JeroenRoodIHS@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:02:18 +0100 Subject: [PATCH 3/3] Update getFontWeight.ts --- src/utils/text/getFontWeight.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/text/getFontWeight.ts b/src/utils/text/getFontWeight.ts index 727d766..7646755 100644 --- a/src/utils/text/getFontWeight.ts +++ b/src/utils/text/getFontWeight.ts @@ -13,4 +13,4 @@ function getFontWeight(fontWeight){ 950 : ["extrablack", "ultrablack", "950"] } return Number(Object.keys(weights).find(weight => weights[weight].includes(inputFontWeight))) || 400; -} +};