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

colorvert

v0.2.1

Published

Node universal color conversion tool.

Downloads

25

Readme

colorvert NPM version

This node module converts colors between CMYK, Lab, XYZ, RGB, HSL, HSV, and Hex colorspaces. Colorvert uses the transicc node module to provide ICC profile-based color conversions between several color spaces. If you only need conversions between ICC profiles (CMYK, Lab, XYZ, and RGB), look to that module.

For a JSON HTTP API: Check out the colorvert-api node module. It uses this module and express to serve HTTP endpoints that convert the input color to all other colorspaces. It's ideal for batch color conversions.


Installation Requirements

You must first install LittleCMS, an open source library written mostly in C for converting colors using ICC profiles. This shell script will get you there.

git clone https://github.com/mm2/Little-CMS.git
cd Little-CMS
./configure 
make 
make check 
sudo make install

Once you've installed that dependency, you're ready to install colorvert and get goin'!

npm install colorvert --save

Quick Examples

var cvert = require( "colorvert" );

// CMYK, XYZ, and Lab-based conversions require
// you to provide a callback function.
cvert.cmyk_to_rgb( 100, 0, 0, 0, function( err, rgb ){
	console.log( rgb );
});

// RGB, HSL, HSV, and hex conversions simply 
// return values.
var hex = cvert.rgb_to_hex( 0, 172, 236 );

Single Conversion

If you only need to convert from one color to another, just include that specific conversion module - it'll keep node from caching extra modules it won't need. Here's an example:

var cmyk_to_hex = require( "colorvert/cmyk/hex" );

cmyk_to_hex( 100, 0, 0, 0, function( err, hex ){
	console.log( hex );
});

CMYK, Lab & XYZ Conversions

These conversions require us to use the transicc node module that interacts with a command line utility. As a result, we have to wait for the response before doing anything with it, so you must provide a callback when converting to or from any of these formats. Here's an example:

cvert.cmyk_to_rgb( 100, 0, 0, 0, function( err, rgb ){
	console.log( rgb );
});

Math-only Conversions

If you're converting between RGB, HSL, HSV, or hex, the functions will simply return the value for you to use right away. Here's how that'll look.

var hex = cvert.rgb_to_hex( 0, 146, 210 );
console.log( hex );

Convert to ALL Other Colorspaces

Each of the colorspaces includes a module that converts to all other colorspaces. As a bonus, the output will also include the hex code of the inverted color, and will suggest the most readable text color to display over the input color. Use it like so:

cvert.cmyk_to_all( 100, 0, 0, 0, function( err, all ){
	console.log( all );
	/*
	Outputs:
	{
		"cmyk": {
			"c": "100",
			"m": "0",
			"y": "0",
			"k": "0"
		},
		"lab": {
			"l": 59,
			"a": -37,
			"b": -49
		},
		"hex": "#00a0e0",
		"hex_inverted": "#ff5f1f",
		"hex_readable": "#ffffff",
		"hsl": {
			"h": 197,
			"s": 100,
			"l": 43
		},
		"hsv": {
			"h": 197,
			"s": 100,
			"v": 87
		},
		"rgb": {
			"r": 0,
			"g": 160,
			"b": 224
		},
		"xyz": {
			"x": 52,
			"y": 71,
			"z": 197
		}
	}
	*/
});

Warning! :)

This module has been pretty reliable during all my tests and with everything I've thrown at it. That said, I haven't written tests for everything yet, so be sure to test it in your environment and with your input - if you find any issues, please post them on Github or submit a pull request!