figmaFontStyle function

String figmaFontStyle(
  1. int weight, {
  2. bool italic = false,
})

Figma font style name for a CSS-style weight, e.g. 700 → Bold.

Implementation

String figmaFontStyle(int weight, {bool italic = false}) {
  final base = switch ((weight / 100).round().clamp(1, 9)) {
    1 => 'Thin',
    2 => 'ExtraLight',
    3 => 'Light',
    4 => 'Regular',
    5 => 'Medium',
    6 => 'SemiBold',
    7 => 'Bold',
    8 => 'ExtraBold',
    _ => 'Black',
  };
  if (!italic) return base;
  return base == 'Regular' ? 'Italic' : '$base Italic';
}