Skip to content
assigns names to colors
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitignore
.nvmrc
LICENSE
README.md
colors.js
index.js
package-lock.json
package.json
test.js

README.md

colornamify

Gives names to colors

npm install colornamify
Also available as a Visual Studio Code Extension!

Short Description

There are only two real problems in computer science: Naming things, cache invalidation, and off-by-one errors. colornamify aims to partially solve problems[0] by giving names to to RGB colors.

Usage

colornamify expects an object containing r, g and b attributes, ranging from 0 to 255. It will return a string with an all lowercase color name.

const colornamify = require('colornamify')
let color = {
  r: 65,
  g: 45,
  b:  0,
}
let name = colornamify(color)
// name now contains 'zanzibar'

Notes

  • We are currently at 6691 unique color names, yay!
  • Invalid input will return null and not throw an error.
  • Lookups will be cached for performance.
  • Library uses a naive searching algorithm.
  • Self-contained, needs no dependencies.
  • Conversion between or accepting different color formats is not in the scope - various solutions already exist for this.
  • Color names are taken from many sources, check the comments in colors.js
  • With the exception of the default CSS named colors, the value of a color is not guaranteed to match the source from which the name is taken. This means do not use this library to precisely identify colors.

Todo

  • Check if we can use a more performant algorithm for lookup.

Shoutout

Big "Thank You!" goes out to Chirag Mehta whose work gave me some great ideas on my search for color naming solutions.

License

MIT

You can’t perform that action at this time.