color2k ·
a color parsing and manipulation lib served in 2kB or less (1.4kB to be more precise)
color2k is a color parsing and manipulation library with the objective of keeping the bundle size as small as possible.
The bundle size is currently 1.4kB
Size comparison
lib | size | link |
---|---|---|
polished | 11.2kB | repo |
chroma-js | 13.7kB | repo |
color | 7.6kB | repo |
tinycolor2 | 5kB | repo |
color2k | 1.4kB | 😎 |
Installation
npm i --save color2k
If you need to server-side render any colors, you also need to install the node/ssr compatibility package.
# only needed in SSR environments (e.g. gatsby, next.js)
npm i --save @color2k/node
Usage
import { darken, transparentize } from 'color2k';
// e.g.
darken('blue', 0.1);
transparentize('red', 0.5);
How so small?
There are two secrets that keep this lib especially small:
- defer to the browser to parse colors via canvas
- small API footprint 🤷♀️
Credits
Heavy credits goes to polished.js and sass. Much of the implementation of this lib is copied from polished!