netbeast / colorsys

:art: Minimalistic color converter for RGB, HSV, HSL, CMYK, HEX and CSS strings
http://getyeti.co
MIT License
57 stars 16 forks source link
cmyk color css-string hex hsv javascript library npm random rgb

colorsys

CircleCI npm version

Colorsys is a simple javascript color conversion library that allows bidirectional color conversion. Lightweight, immutable. With support for RGB, HEX, HSV, HSL and CMYK and CSS strings.

install

With npm

npm install colorsys

Load on browser or copy paste into your code

<script src="https://unpkg.com/colorsys@1.0.11/colorsys.js"></script>

example

var colorsys = require('colorsys')
const hsl = colorsys.parseCss('hsl(0, 0%, 100%)') //  { h: 0, s: 0, l: 100 }
colorsys.hsl2Hex(hsl) // '#ffffff'
const hsv = colorsys.rgb_to_hsv({r: 255, g: 255, b: 255 })
colorsys.stringify(hsv) // 'hsv(0, 0%, 100%)'
// Parsing an hex string will result in a RGB object!
colorsys.parseCss('#ff00ff') // { r: 255, g: 0, b: 255 }

For more examples please visit the tests

API

For any method the input arguments can be an object (r: 50, g: 100, b: 0} or a set of integers 50, 100, 0. You have aliases in both snake_case (hex_to_hsl) or rgb2Hex, hsv2Rgb form.

Try with any combination. Look at the source to double check!

Other methods:

There are some formats missing like YIQ, HWB, ansii and ansi16. Please help us to complete this library making a pull request.

Contact

This repo is shared with :heart: from Netbeast. This package powers Yeti Smart Home and is used in production.

works with yeti