Socket
Socket
Sign inDemoInstall

color2k

Package Overview
Dependencies
0
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    color2k

a color parsing and manipulation lib served in roughly 2kB


Version published
Weekly downloads
804K
decreased by-0.97%
Maintainers
1
Install size
286 kB
Created
Weekly downloads
 

Readme

Source

color2k

bundlephobia github status checks codecov weekly downloads semantic-release

a color parsing and manipulation lib served in roughly 2kB or less (2.8kB to be more precise)

color2k is a color parsing and manipulation library with the objective of keeping the bundle size as small as possible while still satisfying all of your color manipulation needs in an sRGB space.

The full bundle size is currently 2.8kB but gets as small as 2.1k with tree shaking.

Size comparison

libsize
chroma-js13.7kB
polished11.2kB
color7.6kB
tinycolor25kB
color2k2.8kB 😎

👋 Compare tree-shaken bundle outputs on bundlejs.com

Installation

Install with a package manager such as npm

npm i color2k

OR use with skypack.dev in supported environments (e.g. deno, modern browsers).

import { darken, transparentize } from 'https://cdn.skypack.dev/color2k?min';

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:

  1. Simplicity — only handles basic color manipulation functions
  2. Less branching in code — only support two color models as outputs, namely rgba and hsla

Why only rgba and hsla as outputs?

This lib was created with the use case of CSS-in-JS in mind. At the end of the day, all that matters is that the browser can understand the color string you gave it as a background-color.

Because only those two color models are supported, we don't have to add code to deal with optional alpha channels or converting to non-browser supported color models (e.g. CMYK).

We believe that this lib is sufficient for all of your color manipulation needs. If we're missing a feature, feel free to open an issue 😎.

Credits

Heavy credits goes to polished.js and sass. Much of the implementation of this lib is copied from polished!

API and Documentation

Head over to the docs site

Keywords

FAQs

Last updated on 08 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc