color2k · ![https://badgen.net/bundlephobia/minzip/color2k](https://camo.githubusercontent.com/352866e8cb162ddb20944913614d2e84afd0ca6f2fe22fc44b6b3ad419a80665/68747470733a2f2f62616467656e2e6e65742f62756e646c6570686f6269612f6d696e7a69702f636f6c6f72326b)
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
lib | size | link |
---|---|---|
polished | 11.2kB | repo |
chroma-js | 13.7kB | repo |
color | 7.6kB | repo |
tinycolor2 | 5kB | repo |
color2k | 1.4kB | 😎 |
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
import { darken, transparentize } from 'color2k';
// e.g.
darken('blue', 0.1);
transparentize('red', 0.5);
There are two secrets that keep this lib especially small:
- defer to the browser to parse colors via canvas
- small API footprint 🤷♀️
Heavy credits goes to polished.js and sass. Much of the implementation of this lib is copied from polished!