Coder Social home page Coder Social logo

nicolasleroux / colorsys Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netbeast/colorsys

0.0 1.0 0.0 757 KB

:art: Minimalistic color converter for RGB, HSV, HSL, CMYK, HEX and CSS strings

Home Page: http://getyeti.co

License: MIT License

JavaScript 100.00%

colorsys's Introduction

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/[email protected]/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.

  • colorsys.parseCss(color: string) will parse a color string in an object with the same keys.
  • colorsys.stringify(color: Object) will output a valid css string.
  • colorsys.rgb_to_hsl({ r: 255, g: 255, b: 255 }) => { h: 0 , s: 0 , l: 100 }
  • colorsys.rgb_to_hsv({ r: 255, g: 255, b: 255 }) => { h: 0 , s: 0 , v: 100 }

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

  • colorsys.hslToRgb
  • colorsys.hsvToRgb
  • colorsys.rgbToHex
  • colorsys.hexToRgb
  • colorsys.hsvToHex
  • colorsys.hexToHsv
  • colorsys.hslToHex
  • colorsys.hexToHsl
  • colorsys.rgb2cmyk
  • colorsys.cmyk2rgb

Other methods:

  • Generate a random hex color: colorsys.random()
  • Rotate a color hue: colorsys.rotateHue(120, 120) will output 240. You can also use HSL or HSV objects as rotateHue(hsv, 120) will output an object containing {h: 240}.

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

Contact

  • Mail us: staff [at] netbeast.co
  • Report a bug or enter discussion at issues
  • Twitter

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

works with yeti

colorsys's People

Contributors

pablopi avatar jsdario avatar ashish-kale avatar brendanberkley avatar lucasgarci avatar guillaumeleclerc avatar luisfpinto avatar victormartingarcia avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.