What is @kurkle/color?
The @kurkle/color npm package is designed for color manipulation and conversion. It provides a set of tools for parsing colors, converting them between different formats (e.g., HEX, RGB, HSL), and manipulating their properties (e.g., brightness, alpha). This package can be particularly useful in web development, data visualization, and any application where color manipulation is required.
What are @kurkle/color's main functionalities?
Parsing and converting colors
This feature allows the parsing of color strings in various formats and their conversion into other formats. The example demonstrates converting an RGB color to its hexadecimal representation.
"const {color} = require('@kurkle/color');\nconst col = color('rgb(255, 99, 132)');\nconsole.log(col.hexString()); // Outputs: '#FF6384'"
Manipulating color properties
This feature enables the manipulation of color properties such as lightness. The example shows how to make a color lighter by a certain percentage.
"const {color} = require('@kurkle/color');\nconst col = color('hsl(100, 50%, 50%)').lighten(0.2);\nconsole.log(col.hslString()); // Outputs a lighter HSL color string"
Alpha transparency manipulation
This feature allows for the manipulation of the alpha transparency of a color. The example demonstrates changing the alpha value of an RGBA color.
"const {color} = require('@kurkle/color');\nconst col = color('rgba(255, 99, 132, 0.5)').alpha(0.75);\nconsole.log(col.rgbaString()); // Outputs an RGBA color string with updated alpha"
Other packages similar to @kurkle/color
chroma-js
chroma-js is a powerful library for all kinds of color conversions and color scales. Compared to @kurkle/color, chroma-js offers a broader range of color manipulation capabilities, including color scales, interpolation, and more complex transformations.
color
The 'color' package provides similar functionalities for color parsing, conversion, and manipulation. It supports a wide range of color models. Compared to @kurkle/color, it might offer a slightly different API and additional color models.
tinycolor2
tinycolor2 is a small, fast library for color manipulation and conversion in JavaScript. It offers functionality similar to @kurkle/color but with a focus on simplicity and minimal footprint. It might be preferred for projects where size is a critical factor.
@kurkle/color
Overview
Fast and small CSS color parsing and manipulation library.
Parsing
Supported formats:
blue
transparent
#aaa
#bbba
#1A2b3c
#f1f2f388
rgb(255, 255, 255)
rgb(255, 0, 0, 0.5)
rgb(50%, 50%, 50%, 50%)
rgb(0 0 100% / 80%)
rgba(200, 20, 233, 0.2)
rgba(200, 20, 233, 2e-1)
hsl(240deg, 100%, 50.5%)
hsl(0deg 100% 50%)
hsla(12, 10%, 50%, .3)
hsla(-1.2, 10.2%, 50.9%, 0.4)
hwb(240, 100%, 50.5%)
hwb(244, 100%, 100%, 0.6)
hsv(240, 100%, 50.5%)
hsv(244, 100%, 100%, 0.6)
Docs
typedocs
note The docs are for the ESM module. UMD module only exports the default export
Benchmarks
benchmarks
Size visualization
color.min.js
License
@kurkle/color
is available under the MIT license.