Overview
Colvertize allows to conveniently convert colors between different formats and can apply conversion functions (like color inversion) using function composition.
It is heavily based on the color implementation of the excellent darkreader
Usage
Installation:
npm i --save colvertize# or yarn add colvertize
UMD support in browser:
Examples:
;convert'rebeccapurple', 'css-hex';// -> '#663399'convert'#123456', 'css-rgb';// -> 'rgb(18, 52, 86)'convert'#123456', 'css-hsl';// -> 'hsl(210, 65%, 20%)'convert'#123456', 'rgb';// -> {'r': 18, 'g': 52, 'b': 86, 'a': 1}convert'#123456', 'hsl';// -> {'h': 210, 's': 0.653846153846154, 'l': 0.20392156862745098, 'a': 1}// custom conversion functionsconvert'#ffffff', 'css-hex', invertColor// -> '#000000'
This following built-in conversion functions are supported:
;convert'#ff0000', 'css-hex', invert// -> '#00ffff'// dark (default: black), light (default: white), and threshold (default: 0.179) are optional optionsconvert'#ffff00', 'css-hex', invertDarkLight// -> '#111111'// factor (default: 2.2) is an optional optionconvert'#773300', 'css-hex', gammaCorrection// -> '#b47b00'// contrast (default: 1.0) and brightness (default: 0) are optional optionsconvert'#993300', 'css-hex', contrastBrightness// -> '#a60d00'
For more usage information checkout the tests