JavaScript Color Parsing - TinyColor
I threw together a color parsing library to help make my JavaScript colorpicker as small and accurate as possible. It is called TinyColor. One of the main goals is a small footprint - it clocks in at 8.98KB (3.41KB gzipped).
I have written in more detail about this on my TinyColor page. In it, I talk about the Color conversion, input recognition, color manipulation, scheme (combination) generation, and more.
January 16th, 2012 at 7:09 pm
very nice!
check oute this patteren to scrap a few more bytes for places like line 185
from
to
better looking and less code
January 20th, 2012 at 9:56 am
Yes, many of the conversion functions were modified from other sources, so I didn’t make many changes besides changing the bounding of the parameters (normalizing the input to a 0-1 scale).
I usually avoid nested ternary expressions because it is hard to visually parse them out (at least when reading the code months later) so I end up explicitly parenthesizing the nesting, which makes it a little more verbose.
September 18th, 2013 at 3:02 pm
I think I’ve found some errors in your library. I tried to change the opacity of a color, but it did not gave the expected result. One of the problems is that the toRgbString function uses the variable named “a” instead of “this.alpha”. An other problem is, that the tinycolor function does not always gives back a tinycolor object, so sometimes some of the methods are not available.
September 19th, 2013 at 12:57 pm
To change the alpha values, try color1.setAlpha(). For the other issue, can you open an issue here: https://github.com/bgrins/TinyColor/issues/new with the steps to reproduce?