Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

color-forge

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-forge

Brewer ======

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Brewer

npm install color-brewer

A simple color system based on the work of https://github.com/dfcreative/color-space

Basic Usage

Creating a Color Instance

Colors can be made with the regular constructor pattern.

var color = new Color([255, 0, 0], 'rgb');

or

var color = Color.rgb([255, 0, 0]);

In addition, you can create a color from a hex code as follows.

Color.hex('#123');
Color.hex('123');
Color.hex('#112233');
Color.hex('112233');

See color-space for supported color spaces (it's pretty much all of them).

The format of a color object is as follows.

color {
	space,
	values
	[semi-private] originalColor
}

Converting Colors

color.convert('lab');

The result is a new object, and does not affect the original object. Additionally, the new object will store the original color, meaning unlimited conversions without loss.

assert.deepEqual(
    color.convert('lab').convert('hsl').convert('rgb').convert('xyz').values,
    color.convert('xyz').values
);

Mixing Colors

color1.mix(color2, [amount = 0.5, [mode = 'rgb']]);

Returns a new color object with the colors mixed according to amount (an amount of 0 gives color1, and 1 gives color2). Specifying a different mode will mix the color via that mode, allowing you to get even color spaces.

color1.mix(color2, 0.5, 'lab');

Color Operations

color1.add(color2);

All operations accept a color as the first and only argument. The available color operations are add, subtract, multiply, divide, screen, overlay, dodge, burn.

All operations are done via RGB.

Extra

color1.toString() // Gives a string like 'hsl(180, 60, 20)'
color1.toHex() // Gives the hex code

FAQs

Package last updated on 24 Apr 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc