color2k

github.com ↗

Adjust CSS colours and calculate contrast with focused JavaScript functions.

SI Score
80/100
Pricing
Open Source AI reading, not confirmed
Free plan
Not confirmed
Sign-up required
Not confirmed

Ask SI about color2k

Answers use saved listing facts and recorded sources.
Homepage screenshot
Screenshot of the color2k homepage

What it does

color2k parses and manipulates sRGB colours in JavaScript. It handles common CSS inputs, including hex, RGB, HSL, named colours and transparency, and provides adjustment, interpolation and contrast functions. It is an open-source package released under MIT.

Lightness and saturation adjustments operate on HSL channels. For example, darkening by 0.1 subtracts ten percentage points of lightness; transparentize instead reduces the alpha channel. Both use decimal amounts between 0 and 1.

The output depends on the function. toHex returns hexadecimal text and includes alpha for a non-opaque colour; toRgba and toHsla return CSS strings. Parsing helpers return channel arrays. readableColor chooses black or white according to which has better contrast against the input.

A scale built with getScale takes a value from 0 to 1 and interpolates through its supplied colours. The library has no runtime dependencies and uses the MIT licence. Its sRGB focus excludes wide-gamut colour processing.

Strengths

  • Parsing accepts several common CSS colour notations.
  • Contrast helpers include a black-or-white foreground choice.

Watch out for

  • Colour processing is limited to sRGB.

Best for

  • JavaScript interfaces deriving colours and checking their contrast.

Sources