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

@xotic750/color

v1.1.3

Published

Color conversion and manipulation library

Downloads

7

Readme

@xotic750/color

JavaScript library for immutable color conversion and manipulation with support for CSS color strings.

const color = Color('#7743CE')
  .alpha(0.5)
  .lighten(0.5);
console.log(color.hsl().string()); // 'hsla(262, 59%, 81%, 0.5)'

console.log(
  color
    .cmyk()
    .round()
    .array(),
); // [ 16, 25, 0, 8, 0.5 ]

console.log(color.ansi256().object()); // { ansi256: 183, alpha: 0.5 }

Install

$ npm install color

Usage

import Color from 'color';

Constructors

const color = Color('rgb(255, 255, 255)');
const color = Color({r: 255, g: 255, b: 255});
const color = Color.rgb(255, 255, 255);
const color = Color.rgb([255, 255, 255]);

Set the values for individual channels with alpha, red, green, blue, hue, saturationl (hsl), saturationv (hsv), lightness, whiteness, blackness, cyan, magenta, yellow, black

String constructors are handled by color-string

Getters

color.hsl();

Convert a color to a different space (hsl(), cmyk(), etc.).

color.object(); // {r: 255, g: 255, b: 255}

Get a hash of the color value. Reflects the color's current model (see above).

color.rgb().array(); // [255, 255, 255]

Get an array of the values with array(). Reflects the color's current model (see above).

color.rgbNumber(); // 16777215 (0xffffff)

Get the rgb number value.

color.hex(); // 0xffffff

Get the hex value.

color.red(); // 255

Get the value for an individual channel.

CSS Strings

color.hsl().string(); // 'hsl(320, 50%, 100%)'

Calling .string() with a number rounds the numbers to that decimal place. It defaults to 1.

Luminosity

color.luminosity(); // 0.412

The WCAG luminosity of the color. 0 is black, 1 is white.

color.contrast(Color('blue')); // 12

The WCAG contrast ratio to another color, from 1 (same color) to 21 (contrast b/w white and black).

color.isLight(); // true
color.isDark(); // false

Get whether the color is "light" or "dark", useful for deciding text color.

Manipulation

Returns a new instance of Color.

color.negate(); // rgb(0, 100, 255) -> rgb(255, 155, 0)

color.lighten(0.5); // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%)
color.darken(0.5); // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%)

color.saturate(0.5); // hsl(100, 50%, 50%) -> hsl(100, 75%, 50%)
color.desaturate(0.5); // hsl(100, 50%, 50%) -> hsl(100, 25%, 50%)
color.grayscale(); // #5CBF54 -> #969696

color.whiten(0.5); // hwb(100, 50%, 50%) -> hwb(100, 75%, 50%)
color.blacken(0.5); // hwb(100, 50%, 50%) -> hwb(100, 50%, 75%)

color.fade(0.5); // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 0.4)
color.opaquer(0.5); // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 1.0)

color.rotate(180); // hsl(60, 20%, 20%) -> hsl(240, 20%, 20%)
color.rotate(-90); // hsl(60, 20%, 20%) -> hsl(330, 20%, 20%)

color.mix(Color('yellow')); // cyan -> rgb(128, 255, 128)
color.mix(Color('yellow'), 0.3); // cyan -> rgb(77, 255, 179)

// chaining
color
  .green(100)
  .grayscale()
  .lighten(0.6);