tryHex3 method

String tryHex3(
  1. String hex
)

hex == '#rrggbb' => '#rgb' else return unchanged

Implementation

String tryHex3(String hex) => (hex.length == 7 &&
        hex[1] == hex[2] &&
        hex[3] == hex[4] &&
        hex[5] == hex[6])
    ? '#${hex[1]}${hex[3]}${hex[5]}'
    : hex;