Socket
Socket
Sign inDemoInstall

color-convert

Package Overview
Dependencies
0
Maintainers
2
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.55%
Maintainers
2
Install size
30.0 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

Changelog

Source

0.5.3 - 2015-06-02

  • Fixed: hsl2hsv does not return NaN anymore when using [0,0,0] (#15)

Check out commit logs for older releases

Readme

Source

color-convert Build Status

Color-convert is a color conversion library for JavaScript and node. It converts all ways between rgb, hsl, hsv, hwb, cmyk, and CSS keywords:

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

converter.rgb(140, 200, 100).hsl()   // [96, 48, 59]

converter.keyword("blue").rgb()      // [0, 0, 255]

Install

npm install color-convert

API

Color-convert exports a converter object with getter/setter methods for each color space. It caches conversions:

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

converter.rgb(140, 200, 100).hsl()   // [96, 48, 59]

converter.rgb([140, 200, 100])       // args can be an array

Plain functions

Get direct conversion functions with no fancy objects:

require("color-convert").rgb2hsl([140, 200, 100]);   // [96, 48, 59]

Unrounded

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

convert.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])

Other spaces

There are some conversions from rgb (sRGB) to XYZ and LAB too, available as rgb2xyz(), rgb2lab(), xyz2rgb(), and xyz2lab().

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 02 Jun 2015

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