coloration
Is a relatively small JavaScript library for converting between different color formats while being as efficient and as small as possible.
Features
- Simple to use and learn.
- Small (2kb minified and gzipped).
- Works in both node and in the browser (using tools like webpack).
- Compatible with es3 supporting implementations.
- Supports converting between HSV, HSL, RGB, HEX, CMYK.
Installation
npm i coloration
in your code
const coloration = require('coloration');
Usage
const coloration = require('coloration');
coloration.rgb.hex( 255, 255, 255 ); // returns '#ffffff'
coloration.rgb.hsv( 0, 0, 0 ); // returns [ 0, 0, 0 ]
coloration.rgb.hsl( 128, 0, 128 ); // returns [ 0, 0, 50.19607843137255 ]
coloration.rgb.cmyk( 0, 44, 66 ); // returns [ 0, 1, 0, 0.4980392156862745 ]
API
coloration is just an object which reference other objects which contain the desired conversion functionality.
meaning that it is perfectly safe to do this
const { rgb } = coloration;
rgb.hex( 0, 0, 0 ); // returns '000000'.
this
binding resulting in confusing and error prone behavior.
Note : That being said it is totally okay to reference any object that contain conversion methods, however you shouldn't reference the methods inside that object themselves, why ? because that make the function lose it's RGB
coloration.rgb.hex( red: number, green: number, blue: number ): string
Converts the given RGB values into a HEX string
coloration.rgb.hsv( red: number, green: number, blue: number ): number[]
Converts the given RGB values into HSV.
coloration.rgb.hsl( red: number, green: number, blue: number ): number[]
Converts the given RGB values into HSL.
coloration.rgb.cmyk( red: number, green: number, blue: number ): number[]
Converts the given RGB values into CMYK.
hex
coloration.hex.rgb( hexStr: string ): number[]
Converts the given HEX string into RGB.
coloration.hex.hsv( hexStr: string ): number[]
Converts the given HEX string into HSV.
coloration.hex.hsl( hexStr: string ): number[]
Converts the given HEX string into HSL.
coloration.hex.cmyk( hexStr: string ): number[]
Converts the given HEX string into CMYK.
HSV
coloration.hsv.rgb( hue: number, saturation: number, value: number ): number[]
c
Converts the given HSV values into RGB.
coloration.hsv.hex( hue: number, saturation: number, value: number ): string
Converts the given HSV values into a HEX string.
coloration.hsv.hsl( hue: number, saturation: number, value: number ): number[]
Converts the given HSV values into HSL.
coloration.hsv.cmyk( hue: number, saturation: number, value: number ): number[]
Converts the given HSV values into cmyk.
HSL
coloration.hsl.rgb( hue: number, saturation: number, value: number ): number[]
Converts the given HSL values into RGB.
coloration.hsl.hex( hue: number, saturation: number, value: number ): string
Converts the given HSL values into a HEX string.
coloration.hsl.hsv( hue: number, saturation: number, value: number ): number[]
Converts the given HSL values into HSV.
coloration.hsl.cmyk( hue: number, saturation: number, value: number ): number[]
Converts the given HSL values into cmyk.
CMYK
coloration.cmyk.rgb( cyan: number, magenta: number, yellow: number, black: number ): number[]
Converts the given CMYK values into RGB
coloration.cmyk.hex( cyan: number, magenta: number, yellow: number, black: number ): string
Converts the given CMYK values into a HEX string
coloration.cmyk.hsv( cyan: number, magenta: number, yellow: number, black: number ): number[]
Converts the given CMYK values into HSV
coloration.cmyk.hsl( cyan: number, magenta: number, yellow: number, black: number ): number[]
Converts the given CMYK values into HSL
To do
- Implementing some sort of caching to make the functions run a bit faster
- Adding more utility functions
Known bugs and issues
Right now there aren't any bugs, however if you find any strange behavior please head to the github page and open up an issue in the issue page.
License
MIT