New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@dynamize/color-utilities

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dynamize/color-utilities

Library to format, convert and work with colors.

latest
Source
npmnpm
Version
1.1.1
Version published
Weekly downloads
16
-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

cu-logo

Tools for all your color needs

Color utilities is a collection of tools used to work with colors.

Features

  • Color conversions (ansi16, ansi256, cmy, cmyk, tsl, hsl, hsv, lab, luv, lch xyz ...)
  • Color blending
  • Color harmony pallet creation
  • Color mixers ( such as getting shades, tints and tones)
  • Performing Chromatic adaptation

Table of Contents

About Color Utilities

Color Utilities aims to be a one-stop shop for any work related to colors, mostly built with pure functions One can use as little or as much of it as needed or wanted, avoiding unneeded project bloating. In the future, this library will most probably grow further.

Limits

Due to the nature of color spaces, certain conversions are more computationally taxing than others. Further, certain conversions lead to data loss like RGB to Ansi16 and then back to RGB will most probably result in a significant difference in color.

Documentation

npm install --save @dynamize/color-utilities

Dependencies

This library has no dependencies and is completely self-contained.

Importing

Importing is done using the ES static import declaration. Example:

import { Color } from "@dynamize/color-utilities";

In order to use the import declaration in a source file, the file must be interpreted by the runtime as a module.

Color

A Color class is a representation of a color in Color Utilities. Use case for this is when you know you will need values for more then one color space.

Usage examples:

import { Color } from "@dynamize/color-utilities";

const color = new Color("rgb", { red: 238, green: 200, blue: 27 });

console.log(color.data);
Param placeDescriptionFormats
1stSpace in which color values are passedadobe_98_rgb", "apple_rgb", "ansi16", "ansi256", "best_rgb", "beta_rgb", "bruce_rgb", "cie_rgb", "color_match_rgb", "cmy", "cmyk", "don_rgb_4", "eci_rgb_v2" "etka_space_ps5", "hcy", "hex", "hsi", "hsl", "hsv", "hunter_lab", "hwb", "lab", "lch_ab", "lch_uv", "luv", "lms", "ntsc_rgb", "pal_secam_rgb", "pro_photo_rgb", "rgb", "ryb", "tsl", "smpte_c_rgb", "wide_gamut_rgb", "uvw","xvycc", "xyy", "xyz", "ycbcr_BT601", "yccbccrc", "ycocg", "ydbdr", "yiq", "ypbpr"
2ndColor valuesnumber, string, or color data object
3rdoptional - colors spaces to computestring [] of "all"
  • The first argument we pass is a string value and it represents the space in which color values will be passed.
  • The second argument is the actual color values and it's passed in form of an object.
  • The third argument is optional and has a form of string array or a string "all", if not passed, automatically values for hex, hvs, lab, and cmyk, will be computed, alternatively color spaces listed in the array will be computed.

The result of the above example is:

 Color {
  rgb: { red: 238, green: 200, blue: 27, inGamut: true },
  xyz: { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 },
  hex: 'EEC81B',
  hsv: { hue: 49, saturation: 89, value: 93 },
  lab: {
    luminance: 81.60296053275202,
    a: -1.2482727232548951,
    b: 79.33052440955292
 },
 cmyk: {
   cyan: 0,
   magenta: 15.96638655462185,
   yellow: 88.65546218487395,
   key: 6.666666666666665
  }
 }

Lets see an alternative use:

import { Color } from "@dynamize/color-utilities";

const color = new Color("rgb", { red: 238, green: 200, blue: 27 }, [
  "hsl",
  "luv",
  "ryb",
  "tsl",
]);

console.log(color.data);

Result from the above example would be:

Color {
  rgb: { red: 238, green: 200, blue: 27, inGamut: true },
  xyz: { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 },
  hsl: { hue: 49, saturation: 86, lightness: 52 },
  luv: { L: 81.60296053275202, u: 33.50413039331645, v: 84.4716716630059 },
  ryb: { red: 63.346820809248555, yellow: 228, blue: 17 },
  tsl: {
    tint: 0.4209301051592921,
    saturation: 0.27240784750042124,
    lightness: 0.7515294117647058
  }
}

Note: If you noticed RGB and XYZ values are returned regardless, they are needed for two main family of spaces and there for are computed by default.

If "all" is passed as a third argument, all 45 spaces will be computed (the return example is to big to show here), this option is computationally tasking and it's not a good option for color pickers or other use cases where there is a high frequency of re computation. Accidentally the default (no third argument) will return values utilized in a Photoshop color picker (rgb, hsv, lab, cmyk and hex).

Conversions

Here is a list of all color conversion methods, they are standalone, and can be utilized on their own. Some of them might have multiple conversions and that will be stated in the table.

NameDescriptionConversionsNotesParameter
ansi16ToRgbConverts an Ansi16 numeric value to sRGB valuesAnsi16 to sRGBPossible data lossnumber
ansi256ToRGBConverts an Ansi256 numeric value ro sRGB valuesAnsi256 to sRGBPossible data lossnumber
cmyToSRgbConverts colors CMY values in to sRGB valuesCYM to sRGBNo major data loss{ cyan: number, magenta: number, yellow: number}
cmykToRgbConverts colors CMYK values in to sRGB valuesCMYK to sRGBNo major data loss{ cyan: number, magenta: number, yellow: number, key: number }
hclToLabConverts colors HCL values in to CIE-L*ab valuesHCL to LABNo major data loss{ luminance: number, hue: number, chroma: number }
hcyToSrgbConverts colors HCY values in to sRGB valuesHCY to sRGBNo major data loss{ hue: number, chroma: number, Yluminance: number }
hexToRgbConverts a HEX string value in to sRGB valuesHEX to sRGBNo major data lossstring
hextToIntConverts a Hex string value in to a integer valueHEX to Integerstring
hexToDecimalConverts a Hex string value in to a decimal valueHEX to Decimalstring
hsiToSrgbConverts a colors HSI values in to sRGB valuesHSI to sRGBNo major data loss{ hue: number, saturation: number, intensity: number }
hslToToHexConverts a colors HSL values in to a HEX stringHSL to HEXNo major data loss{ hue: number, saturation: number, lightness: number }
hslToHsvConverts a colors HSL values in to HSV valuesHSL to HSVNo major data loss{ hue: number, saturation: number, lightness: number }
hslToRgbConverts a colors HSL values in to sRGB valuesHSL to sRGBNo major data loss{ hue: number, saturation: number, lightness: number }
hsvToAnsi16Converts a colors HSV values in to Ansi16 numericHSV to Ansi16Possible data loss{ hue: number, saturation: number, value: number }
hsvToHslConverts a colors HSV values in to HSL valuesHSV to HSLNo major data loss{ hue: number, saturation: number, value: number }
hsvToRgbConverts a colors HSV values in to sRGB valuesHSV to sRGBNo major data loss{ hue: number, saturation: number, value: number }
hwbToRgbConverts a colors HWB values in to sRGB valuesHWB to sRGBNo major data loss{ hue: number, whiteness: number, blackness: number }
labToLch_abConverts a colors CIE-L*ab values in to LCH(ab)LAB to LCHNo major data loss{ luminance: number, a: number, b: number }
labToSrgbConverts a colors CIE-L*ab values in to sRgbLAB to XYZ to sRGBNo major data loss{ luminance: number, a: number, b: number }
labToXyzConverts a colors CIE-L*ab values in to XYZLAB to XYZNo major data loss{ luminance: number, a: number, b: number }
hunterLabToXyzConverts a colors Hunter's Lab values in to XYZLAB to XYZNo major data loss{ luminance: number, a: number, b: number }
lch_abToLabConverts a colors LCH(ab) values in to CIE-L*abLCH to LABNo major data loss{ lightness: number, chroma: number, hue: number }
lch_abToXyzConverts a colors LCH(ab) values in to XYZLCH to XYZNo major data loss{ lightness: number, chroma: number, hue: number }
lch_uvToLuvConverts a colors LCH(uv) values in to LUVLCH to LUVNo major data loss{ lightness: number, chroma: number, hue: number }
lch_uvToXyzConverts a colors LCH(uv) values in to XYZLCH to XYZNo major data loss{ lightness: number, chroma: number, hue: number }
lmsToXyzConverts a colors LMS values in to XYZ valuesLMS to XYZNo major data loss{ long: number, medium: number, short: number }
luvToLch_uvConverts a colors LUV values to LCH(uv) valuesLUV to LCHNo major data loss{ L: number, u: number, v: number }
luvToXyzConverts a colors LUV values to XYZ valuesLUV to XYZNo major data loss{ L: number, u: number, v: number }
oKLCHToOKLabConverts a colors OKLCH values to LAB valuesOKLCH to RGBNo major data loss{ luminance: number, a: number, b: number }
oKLCHToSRGBConverts a colors OKLCH values to sRGB valuesOKLCH to LMS to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToAdobeRgbConverts a colors sRGB values in to Adobe 98 RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToAppleRgbConverts a colors sRGB values in to Apple RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToBestRgbConverts a colors sRGB values in to Best RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToBetaRgbConverts a colors sRGB values in to Beta RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToBruceRgbConverts a colors sRGB values in to Bruce RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToCieRgbConverts a colors sRGB values in to CIE RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToColorMatchRgbConverts a colors sRGB values in to Color Match RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToDonRgb4Converts a colors sRGB values in to DON RGB 4RGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToEtkaSpacePs5Converts a colors sRGB values in to Etka Space ps5RGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToNtscRgbConverts a colors sRGB values in to NTSC RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToPalSecamRgbConverts a colors sRGB values in to PAL/SECAM RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToProPhotoRgbConverts a colors sRGB values in to PRO PHOTO RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToSmpteCRgbConverts a colors sRGB values in to SMPTE-C RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToWideGamutRgbConverts a colors sRGB values in to Wide Gamut RGBRGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToEciRgbV2Converts a colors sRGB values in to ECI RGB V2RGB to XYZ to RGBNo major data loss{ red: number, green: number, blue: number }
sRgbToAnsi16Converts a colors sRGB values in to Ansi16 numericRGB to Ansi16Possible data loss{ red: number, green: number, blue: number }
sRgbToAnsi256Converts a colors sRGB values in to Ansi256 numericRGB to Ansi256Possible data loss{ red: number, green: number, blue: number }
sRgbToCmyConverts a colors sRGB values in to CMY valuesRGB to CMYNo major data loss{ red: number, green: number, blue: number }
sRgbToCmykConverts a colors sRGB values in to CMYK valuesRGB to CMYKNo major data loss{ red: number, green: number, blue: number }
sRgbToHcyConverts a colors sRGB values in to HCY valuesRGB to HCYNo major data loss{ red: number, green: number, blue: number }
sRgbToHexConverts a colors sRGB values in to a HEX stringRGB to HEXNo major data loss{ red: number, green: number, blue: number }
sRgbaToHexConverts a colors sRGBA values in to a HEX stringRGBA to HEXNo major data loss{ red: number, green: number, blue: number }
sRgbToHsiConverts a colors sRGB values in to HSI valuesRGB to HSINo major data loss{ red: number, green: number, blue: number }
sRgbToHslConverts a colors sRGB values in to HSL valuesRGB to HSLNo major data loss{ red: number, green: number, blue: number }
sRgbToHsvConverts a colors sRGB values in to HSV valuesRGB to HSVNo major data loss{ red: number, green: number, blue: number }
sRgbToHwgConverts a colors sRGB values in to HSV valuesRGB to HWGNo major data loss{ red: number, green: number, blue: number }
sRgbToLabConverts a colors sRGB values in to CIE-L*ab valuesRGB to XYZ to LABNo major data loss{ red: number, green: number, blue: number }
sRgbToLch_abConverts a colors sRGB values in to LCH(ab) valuesRGB to XYZ to LAB to LCHNo major data loss{ red: number, green: number, blue: number }
sRgbToLch_uvConverts a colors sRGB values in to LCH(uv) valuesRGB to XYZ to LUV to LCHNo major data loss{ red: number, green: number, blue: number }
sRgbToLuvConverts a colors sRGB values in to LUV valuesRGB to XYZ to LUVNo major data loss{ red: number, green: number, blue: number }
sRgbToRybConverts a colors sRGB values in to RYB valuesRGB to RYBNo major data loss{ red: number, green: number, blue: number }
sRGBToOKLCHConverts a colors sRGB values in to OKLch valuesRGB to LMS to LAB to LCHNo major data loss{ red: number, green: number, blue: number }
sRgbToTslConverts a colors sRGB values in to TSL valuesRGB to TSLNo major data loss{ red: number, green: number, blue: number }
sRgbToUvqConverts a colors sRGB values in to UVW valuesRGB to XYZ to UVWNo major data loss{ red: number, green: number, blue: number }
sRgbToYCbCrBT601Converts a colors sRGB values in to Y′CbCr (YUV)RGB to YCbCrNo major data loss{ red: number, green: number, blue: number }
sRgbToYCbCrBT709Converts a colors sRGB values in to Y′CbCr BT.709RGB to YCbCrNo major data loss{ red: number, green: number, blue: number }
sRgbToYDbDrConverts a colors sRGB values in to YDbDr valuesRGB to YDbDrNo major data loss{ red: number, green: number, blue: number }
sRgbToYPbPrConverts a colors sRGB values in to YPbPr valuesRGB to YPbPrNo major data loss{ red: number, green: number, blue: number }
sRgbToYcCbcCrcConverts a colors sRGB values in to YcCbcCrc valuesRGB to YcCbcCrcNo major data loss{ red: number, green: number, blue: number }
sRgbToYCgCoConverts a colors sRGB values in to YCoCg valuesRGB to YCoCgNo major data loss{ red: number, green: number, blue: number }
sRgbToYiqConverts a colors sRGB values in to YIQ valuesRGB to YIQNo major data loss{ red: number, green: number, blue: number }
sRgbToXvYccConverts a colors sRGB values in to xvYCC valuesRGB to xvYCCNo major data loss{ red: number, green: number, blue: number }
sRgbToXyzConverts a colors sRGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
adobeRgbToXyzConverts a colors Adobe 98 values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
appleRgbToXyzConverts a colors Apple RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
bestRgbToXyzConverts a colors Best RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
betaRgbToXyzConverts a colors Beta RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
bruceRgbToXyzConverts a colors Bruce RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
cieRgbToXyzConverts a colors CIE RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
colorMatchRgbToXyzConverts a colors COLOR MATCH RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
donRgb4ToXyzConverts a colors DON RGB 4 values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
etkaSpacePs5ToXyzConverts a colors ETKA SPACE PS5 values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
ntscRgbToXyzConverts a colors NTSC RGB values in to XYZ valuesRGB to XYZNo major data loss{ red: number, green: number, blue: number }
palSecamRgbToXyzConverts a colors PAL/SECAM RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
proPhotoRgbToXyzConverts a colors PRO PHOTO RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
smpteCRgbToXyzConverts a colors SMPTE-C RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
wideGamutRgbToXyzConverts a colors WIDE GAMUT RGB values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
eciRgbV2ToXyzConverts a colors ECI RGB V2 values in to XYZRGB to XYZNo major data loss{ red: number, green: number, blue: number }
rybToSrgbConverts a colors RYB values to a sRGB valuesRYB to RGBNo major data loss{ red: number, green: number, blue: number }
tslToSrgbConverts a colors TSL values to a sRGB valuesTSL to RGBNo major data loss{ red: number, green: number, blue: number }
uvwToXyzConverts a colors UVW values to a XYZ valuesUVW to XYZNo major data loss{ u: number, v: number, w: number }
xvYccToYcbcrBT601Converts a colors xvYCC values to Y′CbCr (YUV)xvYCC to YCbCrNo major data loss{ Y: number, Cb: number, Cr: number }
xvYccToSrgbConverts a colors xvYCC values to a SRGB valuesxvYCC to YCbCr to sRGBNo major data loss{ Y: number, Cb: number, Cr: number }
xyYToXyzConverts colors xyY values to XYZ valuesXYY to XYZNo major data loss{ x: number, y: number, Y: number }
xyzToAdobeRgbConverts colors XYZ values to Adobe 98 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToAppleRgbConverts colors XYZ values to Apple RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToBestRgbConverts colors XYZ values to Best RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToBetaRgbConverts colors XYZ values to Beta RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToBruceRgbConverts colors XYZ values to Bruce RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToCieRgbConverts colors XYZ values to CIE RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToColorMatchRgbConverts colors XYZ values to COLOR MATCH RGBXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToDonRgb4Converts colors XYZ values to DON RGB 4 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToEtkaSpacePs5Converts colors XYZ values to ETKA SPACE PS5 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToNtscRgbConverts colors XYZ values to NTSC RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToPalSecamRgbConverts colors XYZ values to PAL/SECAM RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToProPhotoRgbConverts colors XYZ values to PRO PHOTO RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToSmpteCRgbConverts colors XYZ values to SMPTE-C RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToWideGamutRgbConverts colors XYZ values to WIDE GAMUT RGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToEciRgbV2Converts colors XYZ values to ECI RGB V2 valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToLabConverts colors XYZ values to CIE-L*ab valuesXYZ to LABNo major data loss{ x: number, y: number, z: number }
xyzToLuvConverts colors XYZ values to LUV valuesXYZ to LUVNo major data loss{ x: number, y: number, z: number }
xyzToLch_uvConverts colors XYZ values to LCH(uv) valuesXYZ to LCHNo major data loss{ x: number, y: number, z: number }
xyzToUvwConverts colors XYZ values to UVW valuesXYZ to UVWNo major data loss{ x: number, y: number, z: number }
xyzToSrgbConverts colors XYZ values to sRGB valuesXYZ to RGBNo major data loss{ x: number, y: number, z: number }
xyzToLmsConverts colors XYZ values to LMS valuesXYZ to LMSNo major data loss{ x: number, y: number, z: number }
xyzToHunterLabConverts colors XYZ values to Hunter's Lab valuesXYZ to LABNo major data loss{ x: number, y: number, z: number }
xyzToXyYConverts colors XYZ values to XYY valuesXYZ to XYYNo major data loss{ x: number, y: number, z: number }
yCbCrBT601ToSrgbConverts colors Y′CbCr (YUV) values to sRGB valuesYCbCr to RGBNo major data loss{ Y: number, Cb: number, Cr: number }
yCbCrBT601ToXvYccConverts colors Y′CbCr (YUV) values to xvYCC valuesYCbCr to xvYCCNo major data loss{ Y: number, Cb: number, Cr: number }
yCbCrBT601ToYPbPrConverts colors Y′CbCr (YUV) values to YPbPr valuesYCbCr to YPbPrNo major data loss{ Y: number, Cb: number, Cr: number }
yCbCrBT709ToSrgbConverts colors Y′CbCr BT.709 values to sRGB valuesYCbCr to RGBNo major data loss{ Y: number, Cb: number, Cr: number }
ycCbcCrcToSrgbConverts colors YcCbcCrc values to sRGB valuesYcCbcCrc to RGBNo major data loss{ Yc: number, Cbc: number, Crc: number }
yCgCoToSrgbConverts colors YCoCg values to sRGB valuesYCoCg to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yDbDrToSrgbConverts colors YDbDr values to sRGB valuesYDbDr to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yiqToSrgbConverts colors YIQ values to sRGB valuesYIQ to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yPbPrToSrgbConverts colors YPbPr values to sRGB valuesYPbPr to RGBNo major data loss{ Y: number, Co: number, Cg: number }
yPbPrToYCbCrConverts colors YPbPr values to YCbCr valuesYPbPr to YCbCrNo major data loss{ Y: number, Co: number, Cg: number }

Color Converter

In situations where you might need to covert from one space into multiple spaces, you can use a color converter. Color Converter is faster and less task-intensive than using Color. There are two prebuilt Color Converters, RGB Converter and the XYZ Converter.

RGB Converter

RGB Converter is a prebuilt Color Converter that takes a single attribute of a type: { red: number, green: number, blue: number } or { r: number, g: number, b: number }.

It has a single method, "get" and it takes an attribute of type string which represents a color space you would like back. Supported conversion are: adobe_98_rgb, apple_rgb, ansi16, ansi256, best_rgb, beta_rgb, bruce_rgb, cie_rgb, color_match_rgb, cmy, cmyk, don_rgb_4, etka_space_ps5, eci_rgb_v2, hcy, hex, hsi, hsl, hsv, hwb, lab, lch_ab, lch_uv, luv, ntsc_rgb, pal_secam_rgb, pro_photo_rgb, ryb, smpte_c_rgb, tsl, uvw, wide_gamut_rgb, ycbcr_BT601, ycbcr_BT709, ycbcr_BT2020, ydbdr, ypbpr, yccbccrc, ycocg, yiq, xvycc, xyz.

Usage example:

import { RgbConverter } from "@dynamize/color-utilities";

const rgbCon = new RgbConverter({ red: 238, green: 200, blue: 27 });

console.log(rgbCon.get("hsv"));

This will return HSV values for the above-given color.

XYZ Converter

XYZ Converter is a prebuilt Color Converter that takes a single attribute of a type: { x: number, y: number, z: number }.

It has a single method, "get" and it takes an attribute of type string which represents a color space you would like back. Supported conversion are: lab, lch_ab, lch_uv, luv, uvw, rgb, adobe_98_rgb, apple_rgb, best_rgb, beta_rgb, bruce_rgb, cie_rgb, color_match_rgb, don_rgb_4, etka_space_ps5, eci_rgb_v2, ntsc_rgb, pal_secam_rgb, pro_photo_rgb, smpte_c_rgb, wide_gamut_rgb, xyy, lms, hunters_lab.

Usage example:

import { XyzConverter } from "@dynamize/color-utilities";

const xyzCon = new XyzConverter({ red: 238, green: 200, blue: 27 });

console.log(xyzCon.get("luv"));

This will return LUV values for the above-given color.

Color Blending

In Color Utilities, there are two ways you can blend colors: either by using the standalone method "blend" or by using a Color Blender.

Blender

Color Blender is quite powerful, it allows you to blend two colors in rgb ,cmyk, hex, hsl ,hsv, hwb, hex, ryb and xyz formats. The two colors do not have to be in the same format to blend them, and the returned color can have any of the following formats: rgb ,cmyk, hex, hsl ,hsv, hwb, hex, ryb, xyz.

Usage example:

import { Blender } from "@dynamize/color-utilities";

const color = new Blender(
  { c: 0, m: 7, y: 100, k: 0 },
  { h: 0, s: 100, v: 100 },
  { weight: 0.67, returnType: "hex" }
);

console.log(color.color);

Color Blender can return two things: color or blend data. Color will just be a color value in the format that was requested, blend data will give you more information. Below, you can see the blend data for the above example:

{
    color1: {
      data: { cyan: 0, magenta: 7, yellow: 100, key: 0 },
      rgb: { red: 255, green: 237.14999999999998, blue: 0, inGamut: true },
      amount: 0.67,
    },
    color2: {
      data: { hue: 0, saturation: 100, value: 100 },
      rgb: { red: 255, green: 0, blue: 0, inGamut: true },
      amount: 0.32999999999999996,
    },
    resultColor: "FF9F00",
  }

blend

Using the blend method is pretty straight-forward. It takes three parameters, the first two being the RGB values of colors to blend, and the last one is a percentage of the first color, the remaining percentage will be allocated to the second one.

Usage example:

import { blend } from "@dynamize/color-utilities";

const blended = blend(
  { red: 255, green: 237, blue: 0 },
  { red: 255, green: 0, blue: 0 },
  0.67
);

console.log(blended);

Color Harmonies

With Color utilities, you can also generate a number of Harmony pallets. For more information about Harmonies, visit: https://simplified.com/blog/colors/color-harmony All Harmonies are a standalone functions and they all the a color in a HSL format ({ hue: number, saturation: number, lightness: number }) and return an array of hex values. In addition, in addition the second optional parameter is a boolean, which represents if returned hex values should start with a #.

Analogous

Usage example:

import { analogousHarmony } from "@dynamize/color-utilities";

const pallet = analogousHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Clash

Usage example:

import { clashHarmony } from "@dynamize/color-utilities";

const pallet = clashHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Complementary

Usage example:

import { complementaryHarmony } from "@dynamize/color-utilities";

const pallet = complementaryHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Split Complementary

Usage example:

import { splitComplementaryHarmony } from "@dynamize/color-utilities";

const pallet = splitComplementaryHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { splitComplementaryCWHarmony } from "@dynamize/color-utilities";

const pallet = splitComplementaryCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { splitComplementaryCCWHarmony } from "@dynamize/color-utilities";

const pallet = splitComplementaryCCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Four Tone

Usage example:

import { fourToneCWHarmony } from "@dynamize/color-utilities";

const pallet = fourToneCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fourToneCCWHarmony } from "@dynamize/color-utilities";

const pallet = fourToneCCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Five Tone

Usage example:

import { fiveToneAHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneAHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneBHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneBHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneCHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneCHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneDHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneDHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { fiveToneEHarmony } from "@dynamize/color-utilities";

const pallet = fiveToneEHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Six Tone

Usage example:

import { sixToneCWHarmony } from "@dynamize/color-utilities";

const pallet = sixToneCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Usage example:

import { sixToneCCWHarmony } from "@dynamize/color-utilities";

const pallet = sixToneCCWHarmony(
  { hue: 49, saturation: 86, lightness: 52 },
  true
);

console.log(pallet);

Neutral

Usage example:

import { neutralHarmony } from "@dynamize/color-utilities";

const pallet = neutralHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Square

import { squareHarmony } from "@dynamize/color-utilities";

const pallet = squareHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Tetradic

import { tetradicHarmony } from "@dynamize/color-utilities";

const pallet = tetradicHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Triadic

import { triadicHarmony } from "@dynamize/color-utilities";

const pallet = triadicHarmony({ hue: 49, saturation: 86, lightness: 52 }, true);

console.log(pallet);

Color Mixes

Color Utilities also provides three types of color mixes you can get: Shades, Tints and Tones. All of these are generated by a standalone function that receives two arguments, the first being a base color in RGB format, and the second one is an optional options object that can have two values: size (number of colors generated in the pallet) and prefixed (boolean stating if the colors should start with a #). The return value is an array of strings representing hex values.

Tones

import { getTones } from "@dynamize/color-utilities";

const tones = getTones(
  { red: 238, green: 200, blue: 27 },
  { size: 10, prefixed: true }
);

console.log(pallet);

Tints

import { getTints } from "@dynamize/color-utilities";

const tones = getTints(
  { red: 238, green: 200, blue: 27 },
  { size: 10, prefixed: true }
);

console.log(pallet);

Shades

import { getShades } from "@dynamize/color-utilities";

const tones = getShades(
  { red: 238, green: 200, blue: 27 },
  { size: 10, prefixed: true }
);

console.log(pallet);

Chromatic adaptation

Chromatic adaptation can be preformed in two ways, either by using a standalone "adapt" function or by using an Adapter class.

Supported Illuminants

The following illuminant adaptations are supported:

CodeReference IlluminantDestination IlluminantDescription
A_BIlluminant A →Illuminant BIncandescent/tungsten to direct sunlight
A_CIlluminant A →Illuminant CIncandescent/tungsten to average daylight
A_D50Illuminant A →Illuminant D50Incandescent/tungsten to horizon light
A_D55Illuminant A →Illuminant D55Incandescent/tungsten to mid-morning light
A_D65Illuminant A →Illuminant D65Incandescent/tungsten to noon daylight
A_D75Illuminant A →Illuminant D75Incandescent/tungsten to north sky daylight
A_EIlluminant A →Illuminant EIncandescent/tungsten to equal energy
A_F2Illuminant A →Illuminant F2Incandescent/tungsten to cool white fluorescent
A_F7Illuminant A →Illuminant F7Incandescent/tungsten to daylight fluorescent
A_F11Illuminant A →Illuminant F11Incandescent/tungsten to narrow band white fluorescent
B_AIlluminant B →Illuminant ADirect sunlight to incandescent/tungsten
B_CIlluminant B →Illuminant CDirect sunlight to average daylight
B_D50Illuminant B →Illuminant D50Direct sunlight to horizon light
B_D55Illuminant B →Illuminant D55Direct sunlight to mid-morning light
B_D65Illuminant B →Illuminant D65Direct sunlight to noon daylight
B_D75Illuminant B →Illuminant D75Direct sunlight to north sky daylight
B_EIlluminant B →Illuminant EDirect sunlight to equal energy
B_F2Illuminant B →Illuminant F2Direct sunlight to cool white fluorescent
B_F7Illuminant B →Illuminant F7Direct sunlight to daylight fluorescent
B_F11Illuminant B →Illuminant F11Direct sunlight to narrow band white fluorescent
C_AIlluminant C →Illuminant AAverage daylight to incandescent/tungsten
C_BIlluminant C →Illuminant BAverage daylight to direct sunlight
C_D50Illuminant C →Illuminant D50Average daylight to horizon light
C_D55Illuminant C →Illuminant D55Average daylight to mid-morning light
C_D65Illuminant C →Illuminant D65Average daylight to noon daylight
C_D75Illuminant C →Illuminant D75Average daylight to north sky daylight
C_EIlluminant C →Illuminant EAverage daylight to equal energy
C_F2Illuminant C →Illuminant F2Average daylight to cool white fluorescent
C_F7Illuminant C →Illuminant F7Average daylight to daylight fluorescent
C_F11Illuminant C →Illuminant F11Average daylight to narrow band white fluorescent
D50_AIlluminant D50 →Illuminant AHorizon light to incandescent/tungsten
D50_BIlluminant D50 →Illuminant BHorizon light to direct sunlight
D50_CIlluminant D50 →Illuminant CHorizon light to average daylight
D50_D55Illuminant D50 →Illuminant D55Horizon light to mid-morning light
D50_D65Illuminant D50 →Illuminant D65Horizon light to noon daylight
D50_D75Illuminant D50 →Illuminant D75Horizon light to north sky daylight
D50_EIlluminant D50 →Illuminant EHorizon light to equal energy
D50_F2Illuminant D50 →Illuminant F2Horizon light to cool white fluorescent
D50_F7Illuminant D50 →Illuminant F7Horizon light to daylight fluorescent
D50_F11Illuminant D50 →Illuminant F11Horizon light to narrow band white fluorescent
D55_AIlluminant D55 →Illuminant AMid-morning light to incandescent/tungsten
D55_BIlluminant D55 →Illuminant BMid-morning light to direct sunlight
D55_CIlluminant D55 →Illuminant CMid-morning light to average daylight
D55_D50Illuminant D55 →Illuminant D50Mid-morning light to horizon light
D55_D65Illuminant D55 →Illuminant D65Mid-morning light to noon daylight
D55_D75Illuminant D55 →Illuminant D75Mid-morning light to north sky daylight
D55_EIlluminant D55 →Illuminant EMid-morning light to equal energy
D55_F2Illuminant D55 →Illuminant F2Mid-morning light to cool white fluorescent
D55_F7Illuminant D55 →Illuminant F7Mid-morning light to daylight fluorescent
D55_F11Illuminant D55 →Illuminant F11Mid-morning light to narrow band white fluorescent
D65_AIlluminant D65 →Illuminant ANoon daylight to incandescent/tungsten
D65_BIlluminant D65 →Illuminant BNoon daylight to direct sunlight
D65_CIlluminant D65 →Illuminant CNoon daylight to average daylight
D65_D50Illuminant D65 →Illuminant D50Noon daylight to horizon light
D65_D55Illuminant D65 →Illuminant D55Noon daylight to mid-morning light
D65_D75Illuminant D65 →Illuminant D75Noon daylight to north sky daylight
D65_EIlluminant D65 →Illuminant ENoon daylight to equal energy
D65_F2Illuminant D65 →Illuminant F2Noon daylight to cool white fluorescent
D65_F7Illuminant D65 →Illuminant F7Noon daylight to daylight fluorescent
D65_F11Illuminant D65 →Illuminant F11Noon daylight to narrow band white fluorescent
D75_AIlluminant D75 →Illuminant ANorth sky daylight to incandescent/tungsten
D75_BIlluminant D75 →Illuminant BNorth sky daylight to direct sunlight
D75_CIlluminant D75 →Illuminant CNorth sky daylight to average daylight
D75_D50Illuminant D75 →Illuminant D50North sky daylight to horizon light
D75_D55Illuminant D75 →Illuminant D55North sky daylight to mid-morning light
D75_D65Illuminant D75 →Illuminant D65North sky daylight to noon daylight
D75_EIlluminant D75 →Illuminant ENorth sky daylight to equal energy
D75_F2Illuminant D75 →Illuminant F2North sky daylight to cool white fluorescent
D75_F7Illuminant D75 →Illuminant F7North sky daylight to daylight fluorescent
D75_F11Illuminant D75 →Illuminant F11North sky daylight to narrow band white fluorescent
E_AIlluminant E →Illuminant AEqual energy to incandescent/tungsten
E_BIlluminant E →Illuminant BEqual energy to direct sunlight
E_CIlluminant E →Illuminant CEqual energy to average daylight
E_D50Illuminant E →Illuminant D50Equal energy to horizon light
E_D55Illuminant E →Illuminant D55Equal energy to mid-morning light
E_D65Illuminant E →Illuminant D65Equal energy to noon daylight
E_D75Illuminant E →Illuminant D75Equal energy to north sky daylight
E_F2Illuminant E →Illuminant F2Equal energy to cool white fluorescent
E_F7Illuminant E →Illuminant F7Equal energy to daylight fluorescent
E_F11Illuminant E →Illuminant F11Equal energy to narrow band white fluorescent
F2_AIlluminant F2 →Illuminant ACool white fluorescent to incandescent/tungsten
F2_BIlluminant F2 →Illuminant BCool white fluorescent to direct sunlight
F2_CIlluminant F2 →Illuminant CCool white fluorescent to average daylight
F2_D50Illuminant F2 →Illuminant D50Cool white fluorescent to horizon light
F2_D55Illuminant F2 →Illuminant D55Cool white fluorescent to mid-morning light
F2_D65Illuminant F2 →Illuminant D65Cool white fluorescent to noon daylight
F2_D75Illuminant F2 →Illuminant D75Cool white fluorescent to north sky daylight
F2_EIlluminant F2 →Illuminant ECool white fluorescent to equal energy
F2_F7Illuminant F2 →Illuminant F7Cool white fluorescent to daylight fluorescent
F2_F11Illuminant F2 →Illuminant F11Cool white fluorescent to narrow band white fluorescent
F7_AIlluminant F7 →Illuminant ADaylight fluorescent to incandescent/tungsten
F7_BIlluminant F7 →Illuminant BDaylight fluorescent to direct sunlight
F7_CIlluminant F7 →Illuminant CDaylight fluorescent to average daylight
F7_D50Illuminant F7 →Illuminant D50Daylight fluorescent to horizon light
F7_D55Illuminant F7 →Illuminant D55Daylight fluorescent to mid-morning light
F7_D65Illuminant F7 →Illuminant D65Daylight fluorescent to noon daylight
F7_D75Illuminant F7 →Illuminant D75Daylight fluorescent to north sky daylight
F7_EIlluminant F7 →Illuminant EDaylight fluorescent to equal energy
F7_F2Illuminant F7 →Illuminant F2Daylight fluorescent to cool white fluorescent
F7_F11Illuminant F7 →Illuminant F11Daylight fluorescent to narrow band white fluorescent
F11_AIlluminant F11 →Illuminant ANarrow band white fluorescent to incandescent/tungsten
F11_BIlluminant F11 →Illuminant BNarrow band white fluorescent to direct sunlight
F11_CIlluminant F11 →Illuminant CNarrow band white fluorescent to average daylight
F11_D50Illuminant F11 →Illuminant D50Narrow band white fluorescent to horizon light
F11_D55Illuminant F11 →Illuminant D55Narrow band white fluorescent to mid-morning light
F11_D65Illuminant F11 →Illuminant D65Narrow band white fluorescent to noon daylight
F11_D75Illuminant F11 →Illuminant D75Narrow band white fluorescent to north sky daylight
F11_EIlluminant F11 →Illuminant ENarrow band white fluorescent to equal energy
F11_F2Illuminant F11 →Illuminant F2Narrow band white fluorescent to cool white fluorescent
F11_F7Illuminant F11 →Illuminant F7Narrow band white fluorescent to daylight fluorescent

adapt

"adapt" function which takes two arguments, first being XYZ values 0f the color to be adapted, and a string value representing reference illuminant and a destination illuminant.

import { adapt } from "@dynamize/color-utilities";

const adapted = adapt({ x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }, 'A_B');

console.log(adapted);

The above example will adapt from a from reference illuminant A to destination illuminant B.

Adapter

The Adapter class is a little bit more powerful but slower, it takes two optional arguments, first being color values, second is the color space of those values, if not passed default values will be for color white in XYZ format.

Here is a table of all available formats and values:

Param placeDescriptionFormats
# 1Color data{ r: number, g: number, b: number }, { red: number, green: number, blue: number }, { l: number, a: number, b: number }, { luminance: number, a: number, b: number }, { L: number, u: number, v: number }, { l: number, c: number, h: number }, { lightness: number, chroma: number hue: number }, { long: number, medium: number, short: number }, { u: number, v: number, w: number }, { x: number, y: number, Y: number }, { x: number, y: number, z: number }
# 2Color Space of the given coloradobe_98_rgb, apple_rgb, best_rgb, beta_rgb, bruce_rgb, cie_rgb, color_match_rgb, don_rgb_4, eci_rgb_v2, etka_space_ps5, ntsc_rgb, pal_secam_rgb, pro_photo_rgb, rgb, smpte_c_rgb, wide_gamut_rgb

Example 1:

import { Adapter } from "@dynamize/color-utilities";

const adapted = new Adapter(
  { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }
).adapt('A_B');

console.log(adapted);

Example 2:

import { Adapter } from "@dynamize/color-utilities";

const adapter = new Adapter();
const adapted = adapter.set(
  { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }
).adapt('A_B');

console.log(adapted);

The above example is using the "adapt" method with in the Adapter. The difference being that it takes an optional second argument, which is the desired color space of returned color values.

Example 3:

import { Adapter } from "@dynamize/color-utilities";

const adapter = new Adapter();
const adapted = adapter.set(
  { x: 56.11537464609447, y: 59.56827248834963, z: 9.578873171265526 }
).adapt(
  'A_B', 
  'adobe_98_rgb'
);

console.log(adapted);

Delta E / Color Difference

There are multiple ways to calculate the color difference or color distance. More information about color difference: https://en.wikipedia.org/wiki/Color_difference

NameDescriptionFormats
comparativeDistanceEuclidean distance{ red; number, green: number, blue: number }
deltaECIE76LabDelta E using the CIE76 algorithm{ luminance: number, a: number, b: number }
deltaECIE76LchDelta E using the CIE76 algorithm{ lightness: number, chroma: number, hue: number }
deltaECIE76RgbDelta E using the CIE76 algorithm{ red; number, green: number, blue: number }
deltaECIE94LabDelta E using the CIE94 algorithm{ luminance: number, a: number, b: number }
deltaECIE00LabDelta E using the CIE2000 algorithm{ luminance: number, a: number, b: number }
deltaECIE00RgbDelta E using the CIE2000 algorithm{ red; number, green: number, blue: number }

Usage examples:

import { comparativeDistance } from "@dynamize/color-utilities";

const diff = comparativeDistance(
  { red: 238, green: 200, blue: 27 },
  { red: 217, green: 122, blue: 37 }
  );

console.log(diff);

CIE 76

import { deltaECIE76Lab } from "@dynamize/color-utilities";

const diff = deltaECIE76Lab(
  { luminance: 81.60296053275202, a: -1.2482727232548951, b: 79.33052440955292 } ,
  { luminance: 60.61218950864361, a: 31.243719367882505, b: 58.52164206596838 }
  );

console.log(diff);
import { deltaECIE76Rgb } from "@dynamize/color-utilities";

const diff =  deltaECIE76Rgb(
  { red: 238, green: 200, blue: 27 },
  { red: 217, green: 122, blue: 37 }
  );

console.log(diff);

CIE 94

import { deltaECIE94Lab } from "@dynamize/color-utilities";

const diff = deltaECIE94Lab(
  { luminance: 81.60296053275202, a: -1.2482727232548951, b: 79.33052440955292 } ,
  { luminance: 60.61218950864361, a: 31.243719367882505, b: 58.52164206596838 }
  );

console.log(diff);

CIE 00

import { deltaECIE00Lab } from "@dynamize/color-utilities";

const diff = deltaECIE00Lab(
  { luminance: 81.60296053275202, a: -1.2482727232548951, b: 79.33052440955292 } ,
  { luminance: 60.61218950864361, a: 31.243719367882505, b: 58.52164206596838 }
  );

console.log(diff);
import { deltaECIE00Rgb } from "@dynamize/color-utilities";

const diff = deltaECIE00Rgb(
  { red: 238, green: 200, blue: 27 },
  { red: 217, green: 122, blue: 37 }
  );

console.log(diff);

Keywords

Color

FAQs

Package last updated on 14 Nov 2025

Did you know?

Socket

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