simple-color-converter
v2.1.13
Published
This is a simple colors converter, works for almost any color. Has a built in color identifier for converting strings to color. Supported convert colors: from and to CMYK, grayscale, hex3, hex4, hex6, hex8, html, hsl, hsv, lab, pantone, ral, rgb, rgba, rg
Downloads
3,785
Maintainers
Readme
Simple color converter for (almost) Any Color
It covers most colors formats from Pantone, Ral, Hex 3/4/6/8, HTML, sRgb, CMYK, etc for converting from -> and -< to. It's designed with simplicity in mind. you can pass data and specify the format or just let is guess what color you are trying to pass as string.
Install
$ npm install simple-color-converter
Usage
const simpleColorConverter = require('simple-color-converter');
var color = new simpleColorConverter({
ral: { ral: 3009 },
to: 'cmyk'
})
console.log(color) // { c: 0, m: 53, y: 60, k: 60 }
Supported colors
Expected input value list [here].
Expected output value list [here].
| color system | object | array | string | | --- | --- | --- | --- | | cmyk | {c: 39, m: 0, y: 39, k: 7} | [39, 0, 39.7] | 'cmyk 39 0 39 7' | grayscale | | | '78' | | hex3 | | | '#9E9' | | hex4 | | | '#9E9F' | | hex6 | | | '#90EE90' | | hex8 | | | '#90EE90FF' | | html | | | 'Light Green' | | hsl | { h: 120, s: 73.4, l: 74.9 } | [120, 73.4, 74.9] | 'hsl 120 73.4 74.9' | | hsv | { h: 120, s: 39.4, l: 93.3 } | [120, 39.4, 93.3] | 'hsl 120 39.4 93.3' | | lab | {l: 86.5, a: -46.3, b: 36.9} | [86.5, -46.3, 36.9] | 'lab 86.5 -46.3 36.9' | | pantone | {name: '358C'} | | 'pantone 358C' | | ral | { ral : 6019 } | | 'ral 6019'| | rgb | { r: 144, g: 238, b: 144 } | [144, 238, 144] | 'rgb 144 238 144'| | rgba | { r: 144, g: 238, b: 144, a: 1 } | [144, 238, 144, 1] | 'rgba 144 238 144 1'| | rgb decimal | | | 'rgb decimal 6812065' | | w | { r: 144, g: 238, b: 144, a: 1 } | [144, 238, 144, 1] | 'w 544' | | xyz | { x: 44, y: 69, z: 45 } | [44, 69, 45] | 'xyz 44 69 45' | | yuv | { y: 180, u: 113.2, v: 73.5 } | [ 180, 113.2, 73.5 ] | 'yuv 180 113.2 73.5' |
From
Any of the colors mentioned above. You can specify the color and it will be faster of just use the built in color detector.
// faster
var fasterColor = new simpleColorConverter({
rgb: {r: 10, g: 200, b: 50},
to: 'cmyk'
})
// slower but more convenient
var slowerColor = new simpleColorConverter({
color: 'rgb 10 200 50',
to: 'cmyk'
})
| Extra From colors | note | | --- | --- | | color | Autoidentify color | | hex | Autoidentify hex color | | android | hex8 |
Flags
flags are the arguments used for special modifiers. The most useful one is rendering grayscale color, but there is a debugger and a hexref flag created if you need to convert a color but also output a close hex similar color(in case of online color convertors).
const simpleColorConverter = require('simple-color-converter');
var color = simpleColorConverter({
hex3: '#228',
to: 'cmyk',
grayscale: true
})
console.log(color) // { c: 0, m: 0, y: 0, k: 87 }
| flag | output | data type | default | note | | --- | --- | --- | --- | --- | | grayscale | grayscale value in the from format | boolean | false | | | hexref | Reference value in hex format | boolean | false | For Hex it equels Hex6 | | debug | this prevents the object cleanup | boolean | false | |
Future
I am working on version 3 or this package and the new version will be a modern setter and getter based color convertor. A much modern way of approaching this problem.
Contribute
If there are any features you would like to support, or want to add it directly please send us a pull request. I`m more then happy.
If you have any suggestions or you spotted an aberrant behavior or bugs, don't hesitate to send me an email.
License
Copyright © 2019, Radu Dragan. Licensed under the MIT License.
Thank you
I`m Radu, Thank you for using my color convertor, I hope it is useful for you. I genuinely excited to build this kind of solutions.