npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

color-forge

v1.0.18

Published

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

Downloads

7

Readme

Color Forge

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

npm install color-forge
var colorForge = require('color-forge');

See doc.md for full documentation.

Basic Usage

Creating a Color Instance

Colors can be made with the regular constructor pattern with the parameters values, alpha = 1, space = 'rgb'.

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

or since the alpha defaults to 1, and the color space defaults to 'rgb', this can be written as follows.

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

To create a color in a specific space, you may also use the following shorthand, which accepts the parameters values, alpha = 1.

var color = Color.hsl([180, 100, 50], 1);
var color = Color.hsl([180, 100, 50]);

In addition, you can create a color from a hex code as follows, with the leading hash (#) being optional.

Color.hex('#123');
Color.hex('#112233');
Color.hex('#1234'); // has alpha of ~0.26
Color.hex('#1223344'); // has alpha of ~0.26

Color.hex('123');

You can also create a color from a css name.

Color.css('rebeccapurple');

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,
	alpha,
	/* 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

Accepts the paremeters otherColor, 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
color1.toCss();        // Gives css value if exactly identical, else null
color1.toClosestCss(); // Gives closest css

Licence

MIT