Apr 28, 2021
Thank you for these additions!
#2: Using an object here is a good idea, but this approach will become redundant if you have multiple keys for one value. In PHP8 you can comma-separate keys:
$fontWeight = match ($weight) {
100, 200 => "Super Thin",
300 => "Thin",
400, 500 => "Normal",
600, 700, 800 => "Bold",
900 => "Heavy",
default => "Not valid"
};
Also you can directly set a default value.
#3: It’s now even part of ES2020, so no need for the babel plugin anymore.