Socket
Socket
Sign inDemoInstall

colorjs

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    colorjs

Color lib. Supports rgba, hsva, hsla and conversions via a simple API.


Version published
Weekly downloads
12
increased by20%
Maintainers
1
Install size
118 kB
Created
Weekly downloads
 

Readme

Source

colorjs

colorjs provides simple API that may be used to create colors (RGBA, HSVA, HSLA) and perform various color related operations (conversions and such).

Examples

Making red (#FF0000)

color.rgba('red');
color.rgba('#FF0000');
color.rgba('FF0000');

color.hsva('red');
color.hsva('#FF0000');
color.hsva('FF0000');

color.hsla('red');
color.hsla('#FF0000');
color.hsla('FF0000');

color.rgba({r: 1});
color.hsva({s: 1, v: 1});

color.rgba().r(1);
color.hsva().s(1).v(1);

Getter/setter notation

var c = color.rgba('red');

c.r(0.5);

c.r(); // should return 0.5

toArray

var c = color.rgba('red');

c.toArray(); // [1, 0, 0, 1]

toHex

var c = color.rgba('red');

c.toHex(); // 'ff0000'

toCSS

var c = color.rgba('red');
c.toCSS(); // 'rgb(255,0,0)'

c.a(0.5);
c.toCSS(); // 'rgba(255,0,0,0.5)'

Chaining

var c = color.rgba('red');

c.r(0.5).b(0.5); // chains

c.toArray(); // [0.5, 0.5, 0, 1]

Bounds

var c = color.hsva({h: 10, s: -10, v: 5, a: -2});

c.toArray(); // [1, 0, 1, 0]

Type conversions

var c1 = color.rgba('red');
var c2 = color.hsva(c1);

c2.toArray(); // [0, 1, 1, 1]

Other libraries

See https://github.com/bebraw/jswiki/wiki/Color-libraries .

License

colorjs is available under MIT license. See LICENSE for more details.

Keywords

FAQs

Last updated on 07 Jul 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc