Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

color-diff

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

color-diff

Implemets the CIEDE2000 color difference algorithm, conversion between RGB and LAB color and mapping all colors in palette X to the closest or most different color in palette Y based on the CIEDE2000 difference.

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is color-diff?

The color-diff npm package is used for color difference calculations and color palette reduction. It provides utilities to find the closest color match from a palette and to calculate the difference between colors using various algorithms.

What are color-diff's main functionalities?

Calculate Color Difference

This feature allows you to calculate the difference between two colors. The `diff` function takes two color objects and returns a numerical value representing the difference.

const colorDiff = require('color-diff');

const color1 = { R: 255, G: 0, B: 0 };
const color2 = { R: 0, G: 255, B: 0 };
const difference = colorDiff.diff(color1, color2);
console.log(difference);

Find Closest Color

This feature allows you to find the closest color from a given palette. The `closest` function takes a color object and a palette array, and returns the closest matching color from the palette.

const colorDiff = require('color-diff');

const palette = [
  { R: 255, G: 0, B: 0 },
  { R: 0, G: 255, B: 0 },
  { R: 0, G: 0, B: 255 }
];
const color = { R: 128, G: 128, B: 0 };
const closestColor = colorDiff.closest(color, palette);
console.log(closestColor);

Palette Reduction

This feature allows you to reduce a set of colors to a given palette. The `map_palette` function takes an array of colors and a palette, and returns a new array where each color is replaced by the closest color from the palette.

const colorDiff = require('color-diff');

const colors = [
  { R: 255, G: 0, B: 0 },
  { R: 0, G: 255, B: 0 },
  { R: 0, G: 0, B: 255 },
  { R: 128, G: 128, B: 0 }
];
const palette = [
  { R: 255, G: 0, B: 0 },
  { R: 0, G: 255, B: 0 }
];
const reducedColors = colorDiff.map_palette(colors, palette);
console.log(reducedColors);

Other packages similar to color-diff

Keywords

FAQs

Package last updated on 31 May 2023

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc