Socket
Socket
Sign inDemoInstall

color-convert

Package Overview
Dependencies
0
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    color-convert

Plain color conversion functions


Version published
Weekly downloads
228M
decreased by-1.77%
Maintainers
0
Install size
145 kB
Created
Weekly downloads
 

Package description

What is color-convert?

The color-convert npm package is a library for converting colors between different color models such as RGB, HSL, HSV, HEX, and more. It provides functions for one-to-one, one-to-many, and many-to-one conversions.

What are color-convert's main functionalities?

RGB to HEX conversion

Converts an RGB color value to its HEX representation.

const convert = require('color-convert');
const hexColor = convert.rgb.hex(255, 255, 255);

HEX to HSL conversion

Converts a HEX color value to its HSL representation.

const convert = require('color-convert');
const hslColor = convert.hex.hsl('FFFFFF');

HSL to HSV conversion

Converts an HSL color value to its HSV representation.

const convert = require('color-convert');
const hsvColor = convert.hsl.hsv(360, 100, 100);

Keyword to RGB conversion

Converts a CSS keyword color value to its RGB representation.

const convert = require('color-convert');
const rgbColor = convert.keyword.rgb('blue');

ANSI 16 to HEX conversion

Converts an ANSI 16 color code to its HEX representation.

const convert = require('color-convert');
const hexColor = convert.ansi16.hex(90);

Other packages similar to color-convert

Readme

Source

color-convert

Color-convert is a library of plain color conversion functions. It converts between rgb, hsl, hsv, and cmyk:

colorConvert.rgb2hsl([140, 200, 100]));   // [96, 48, 59]

Install

node

For node with npm:

npm install color-convert

browser

Download the latest color-convert.js. All the methods are on the colorConvert object.

API

Color-convert converts all ways between rgb, hsl, hsv, cmyk, and CSS keyword. Also from rgb to xyz and lab (these two assume sRGB color profile):

var convert = require("color-convert");

convert.rgb2hsl([255, 255, 255])        // rgb -> hsl, hsv, cmyk, keyword, xyz, and lab

convert.hsl2rgb([360, 100, 100])        // hsl -> rgb, hsv, cmyk, and keyword

convert.hsv2rgb([360, 100, 100])        // hsv -> rgb, hsl, cmyk, and keyword

convert.cmyk2rgb([100, 100, 100, 100])  // cmyk -> rgb, hsl, hsv, and keyword

convert.keyword2rgb("blue")             // keyword -> rgb, hsl, hsv, and cmyk

convert.xyz2rgb([100, 100, 100])        // xyz -> rgb

Unrounded

To get the unrounded conversion, append Raw to the function name:

colorConvert.rgb2hslRaw([140, 200, 100]);   // [95.99999999999999, 47.619047619047606, 58.82352941176471]

Hash

There's also a hash of the conversion functions keyed first by the "from" color space, then by the "to" color space:

convert["hsl"]["hsv"]([160, 0, 20]) == convert.hsl2hsv([160, 0, 20])

Contribute

Please fork, add conversions, figure out color profile stuff for XYZ, LAB, etc. This is meant to be a basic library that can be used by other libraries to wrap color calculations in some cool way.

Keywords

FAQs

Last updated on 23 Jun 2011

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc