You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The functions toRgb, toHsl etc. are some practical functions, but only if the given color is a string. It could be very nice if they could take into account colors that have already been converted by fx. hexToRgb like:
toHsl(hexToRgb('#ffdd56'))
The above code will fail because the argument passed into toHsl is no longer a string. This is useful when you make a utility function that takes in some sort of color and you just want to make sure that it is a rgb object for manipulating.
concretely I have some code like this:
// My utility functionexportconstmix=(base,mixed,mixPct)=>{mixPct=pct(mixPct);if(mixPct===1){returnisString(mixed) ? mixed : formatRgb(mixed);}if(mixPct===0){returnisString(base) ? base : formatRgb(base);}if(isString(base)){base=toRgb(base);}if(isString(mixed)){mixed=toRgb(mixed);}constclr=colorMix(base,mixed,mixPct);returnformatRgb(clr);};
On a side note to this, it could be cool if the mix method could do the conversion under the hood so I don't have use toRgb (or similar) before to perform the mixture.
So this:
mix('#f0b','#b1f',0.5);
Instead_ of this:
mix(hexToRgb('#f0b'),hexToRgb('#b1f'),0.5);
Tokimon
changed the title
toRgb and similar function should take into account already converted colors
toRgb and similar functions should take into account already converted colors
May 18, 2020
The functions
toRgb
,toHsl
etc. are some practical functions, but only if the given color is a string. It could be very nice if they could take into account colors that have already been converted by fx.hexToRgb
like:The above code will fail because the argument passed into
toHsl
is no longer a string. This is useful when you make a utility function that takes in some sort of color and you just want to make sure that it is a rgb object for manipulating.concretely I have some code like this:
It could be nice not to have to do:
just because I want to make sure the color is in the RGB format.
In my case I am testing it something like this:
The text was updated successfully, but these errors were encountered: