Closed SrBrahma closed 3 years ago
@SrBrahma Thank you for filing this, unfortunately handling transparent
is a bit tricky to do consistently. We've taken the stance to avoid guessing what the user wants if possible (usually just returning transparent
. We do not do this for parseToRgb
or parseToHsl
because they are leveraged by a lot of modules and are expected to return color objects for those internal implementations.
The changes necessary to allow them to accept transparent
would introduce a lot of bloat and would make typing looser than we prefer. This is something we are hoping we can clean up in the v5 rewrite, but won't be addressing this in v4.
Summary
Tried to use parseToRgb function with 'transparent' and it didn't accept it, an error was thrown. As it accepts 'red' etc, I think it should also accept 'transparent'.
Basic Example
Reasoning
Using transparent, at least on React Native that I uses, isn't uncommon. I am using this parseToRgb to get the alpha value in a new React Native package I am dev'ing, so I will have to manually check for 'transparent'. Far from a big deal, but polished could handle that, also avoiding unintended errors in other people code.