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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nearest-human-color

v1.0.3

Published

Find the nearest approximate human color

Downloads

54

Readme

nearest-human-color

Find the nearest approximation of a color given a predefined list of colors.

Usage

var colors = {
  red: '#f00',
  yellow: '#ff0',
  blue: '#00f'
};

var nearestHumanColor = require('nearest-human-color').from(colors);

nearestHumanColor('#800'); // => { name: 'red', value: '#f00', rgb: { r: 255, g: 0, b: 0 }, distance: 119 }
nearestHumanColor('#ffe'); // => { name: 'yellow', value: '#ff0', rgb: { r: 255, g: 255, b: 0 }, distance: 238 }

How it works

Finding the nearest color is a specific case of the "nearest neighbor search" (or NNS) problem. The predefined colors can be thought of as points in 3D space where the X, Y, and Z axes represent each color's red, green, and blue (RGB) values. So finding the nearest color to any given value amounts to finding the closet neighbor to the point where that color would reside when plotted in such a 3D space.

From the Wikipedia article on the subject:

The simplest solution to the NNS problem is to compute the distance from the query point to every other point in the database, keeping track of the "best so far". This algorithm, sometimes referred to as the naive approach, has a running time of O(Nd) where N is the cardinality of S and d is the dimensionality of M. There are no search data structures to maintain, so linear search has no space complexity beyond the storage of the database. Naive search can, on average, outperform space partitioning approaches on higher dimensional spaces.

This library uses an approach to approximate what the human eye sees. Performance should be totally fine unless there are many pre-defined colors to search (and even then, it will probably only matter if you're calling nearestHumanColor a ton of times).

The library then takes the results from the Euclidean color differencial, and then average it with CIEDE2000 color differencial calculation to obtain an approximation of closest color as a human eye would see.

The approach is a combination of the two methods listed here, with some tweaking to imrpove output: https://en.wikipedia.org/wiki/Color_difference

The most realistic optimization that could be made here would probably be to cache results so that multiple calls for the same color can return immediately.

Special Thanks

Special thanks to the following individuals as portions of their projects were used for this project.

  • dtao The code in this project was originally forked from their nearest-color library and would not be possible without this impressive work. https://github.com/dtao/nearest-color

  • Qix- The code used for the rgb to lab conversion is from this project. https://github.com/Qix-/color-convert

  • markusn The CIEDE2000 color differencial algorithym is from this project. https://github.com/markusn/color-diff