npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

color-diff

v1.4.0

Published

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.

Downloads

704,410

Readme

color-diff

Build Status Coverage Status

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

Installation

npm install color-diff --save

Tests

Are located in the test/ folder and are run by:

npm test

Usage

// CommonJS
const { 
  closest, 
  furthest,
  diff, 
  mapPalette,
  paletteMapKey,
  rgbaToLab,
  mapPaletteLab,
  labPaletteMapKey,
} = require("color-diff");

// ESM
import {
  closest,
  furthest,
  diff,
  mapPalette,
  paletteMapKey,
  rgbaToLab,
  mapPaletteLab,
  labPaletteMapKey,
} from "color-diff";

closest(color, palette, bc)

Returns the closest color. The parameter bc is optional and is used as background color when the color and/or palette uses alpha channels.

const color = { R: 255, G: 1, B: 30 };
// red, green, blue
const palette = [ {R: 255, G: 0, B: 0 },
                {R: 0, G: 255, B: 0 },
                {R: 0, G: 0, B: 255} ];

closest(color, palette); // {R: 255, G: 0, B: 0 }, red

The result above is obvious, but diff.closest could deal with more complicated cases.

furthest(color, palette, bc)

Returns the most different color. The parameter bc is optional and is used as background color when the color and/or palette uses alpha channels.

const color = { R: 255, G: 255, B: 255 };
// black, white
const palette = [ {R: 0, G: 0, B: 0 }, {R: 255, G: 255, B: 255 } ];

furthest(color, palette); // {R: 0, G: 0, B: 0 }, black

The result above is obvious, but diff.furthest could deal with more complicated cases.

mapPalette(palette1, palette2)

Returns a mapping from the colors in palette1 to palette2.

paletteMapKey(color)

Return the palette map key for the color, to be used with the result from mapPalette.

diff(color1, color2, bc)

Returns the difference between the lab colors color1 and color2. The parameter bc is optional and is used as background color when one of the colors uses alpha channels.

rgba color

Object

RGBAColor is an object containing 4 properties: 'R', 'G', 'B', 'A', where 'A' is optional OR 'r', 'g', 'b', 'a', where 'a' is optional . Such as:

{ R: 255, G: 1, B: 0 }

There is an optional property 'A', which specifies the alpha channel between 0.0 and 1.0. If not present the color will be treated as fully opaque, i.e. A = 1.0.

Each RGBA-color is transformed into a RGB-color before being used to calculate the CIEDE2000 difference, using the specified background color (defaults to white).

lab color

Object

LabColor is an object containing 3 properties 'L', 'a', 'b' such as:

{ L: 100, a: 0.005, b: -0.010 }

palette

Array.<RGBAColor>

Color palette array which contains many RGBAColor objects.

Author

Markus Ekholm

License

3-clause BSD. For details see COPYING.