2.0.1 • Published 5 years ago

color-convert v2.0.1

Weekly downloads
49,867,258
License
MIT
Repository
github
Last release
5 years ago

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, ansi, ansi16, hex strings, and CSS keywords (will round to closest):

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

convert.rgb.hsl(140, 200, 100);             // [96, 48, 59]
convert.keyword.rgb('blue');                // [0, 0, 255]

var rgbChannels = convert.rgb.channels;     // 3
var cmykChannels = convert.cmyk.channels;   // 4
var ansiChannels = convert.ansi16.channels; // 1

Install

$ npm install color-convert

API

Simply get the property of the from and to conversion that you're looking for.

All functions have a rounded and unrounded variant. By default, return values are rounded. To get the unrounded (raw) results, simply tack on .raw to the function.

All 'from' functions have a hidden property called .channels that indicates the number of channels the function expects (not including alpha).

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

// Hex to LAB
convert.hex.lab('DEADBF');         // [ 76, 21, -2 ]
convert.hex.lab.raw('DEADBF');     // [ 75.56213190997677, 20.653827952644754, -2.290532499330533 ]

// RGB to CMYK
convert.rgb.cmyk(167, 255, 4);     // [ 35, 0, 98, 0 ]
convert.rgb.cmyk.raw(167, 255, 4); // [ 34.509803921568626, 0, 98.43137254901961, 0 ]

Arrays

All functions that accept multiple arguments also support passing an array.

Note that this does not apply to functions that convert from a color that only requires one value (e.g. keyword, ansi256, hex, etc.)

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

convert.rgb.hex(123, 45, 67);      // '7B2D43'
convert.rgb.hex([123, 45, 67]);    // '7B2D43'

Routing

Conversions that don't have an explicitly defined conversion (in conversions.js), but can be converted by means of sub-conversions (e.g. XYZ -> RGB -> CMYK), are automatically routed together. This allows just about any color model supported by color-convert to be converted to any other model, so long as a sub-conversion path exists. This is also true for conversions requiring more than one step in between (e.g. LCH -> LAB -> XYZ -> RGB -> Hex).

Keep in mind that extensive conversions may result in a loss of precision, and exist only to be complete. For a list of "direct" (single-step) conversions, see conversions.js.

Contribute

If there is a new model you would like to support, or want to add a direct conversion between two existing models, please send us a pull request.

License

Copyright © 2011-2016, Heather Arthur and Josh Junon. Licensed under the MIT License.

colorchartjs-color@weirdwolfagency/themewindweb-desktop-helpercuc-gaf@huyhpham/rn-linearchetype-library@ghomekit/ghome-gboiler@ghomekit/ghome-gledstripcomponennentt@dinert/utilshomebridge-cynceasy-select-rnchinjowwchinjowvuedragdropuploadimagesreact-native-bluetooth2killi8n-react-native-fast-imagepipihomereact-hsb-colorpickerrn-send-smsspecify-importsbabel-specify-imports@icanpm/api-master@arisageha/react-lazyload@arisageha/react-lazyload-fix@oneplanetcrowd/developersrdclr-boilerplate@cashremit/cr-streamline-iconsnuomorphnuomorph-uirn-device-information@ff0000-tech/dps-local-staging@almeidaa/ms@ff0000-tech/dps-local-devreact-native-template-rfbase@doggistyle/librarycloud-archive-s3@passageid/passage-jsairscanairscan-examplebb-chatspeckybotreact-native-esc-pos-sahaabnode-red-color-convertershesha-react-components@borisovart/atol-kkt-module@frxf/frxfbackend-storiesdeneme323112sprite-nest@blackswap/uikit@steven-torres/jsxrstudio-one@texttree/demo-bsa-reference-rcl@fundefund/funde_ck@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjames@sonammalhotra/lotide@smishra17/lotide@cheapthrills/lotidediscord-music-botsreact-native-covid-sdkgql_din_modnoresca-tools-dev444bitgetafryxiconsreact-native-thanh-toast-librarymutasi-bcasalut_gongjang_first_modulesemantic-colorizer@jttechnic/interpreter@thanhnguyen14797/react-native-thanh-toast-library@l1nyanm1ng/react-picture-viewer@eginnovations/eginnovations-capacitor-pluginhexota@saeon/ol-react@saeon/quick-formauto-extractcthpb-plugin-socialrc-bullets-without-console@krystofcelba/homebridge-z2m@iobroker-community-adapters/iobroker.device-watcher@olivervorasai/slidermysql-formatreact-native-printer-brothersrn-pdf-reader-offlinecbmis-ai-toolbox@belko.tech/belko-multi-wallet-sdkmercury-uni@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-testasterjscogoportutils@b0th/testukor-remasteruncoded-connect@reversodev/oceanic-fleetlevibestliblevibestlib2
2.0.1

5 years ago

2.0.0

5 years ago

1.9.3

6 years ago

1.9.2

6 years ago

1.9.1

6 years ago

1.9.0

7 years ago

1.8.2

7 years ago

1.8.1

7 years ago

1.8.0

7 years ago

1.7.0

7 years ago

1.6.0

7 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.7.0

8 years ago

0.6.0

9 years ago

0.5.3

9 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.4

10 years ago

0.3.1

12 years ago

0.3.0

13 years ago

0.2.1

13 years ago

0.2.0

13 years ago

0.1.0

13 years ago