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

real-colors

v1.0.1

Published

Color utility for Javascript

Downloads

14

Readme

npm real-colors

A utility library for working with colors in JavaScript.

81% Coverage MIT License v1.0.0

Installation

npm install real-colors

or

yarn add real-colors

API

Generate Color Client

import { createColorInstance } from 'real-colors';
// You may pass in a color map to createColorInstance
const Color = createColorInstance({ myColor: '#ff00ff' });
// Sample usage
const color = Color.named('myColor');
console.log(color.hexString); // #FF00FF

Creating Colors

static Color.fromHex(hex: string): Color

Creates a color from a hex string.

static Color.fromRGB(r: number, g: number, b: number, a?: number): Color

Creates a color from RGB values.

static Color.fromHSL(h: number, s: number, l: number, a?: number): Color

Creates a color from HSL values.

static Color.random(): Color

Creates a random color.

static Color.seededRandom(seed: number): Color

Creates a seeded random color.

static Color.named(name: string): Color

Creates a color from a named color. There is a set of named colors available by default, but you can add your own by passing in a color map to createColorInstance.

static Color.resolve(color: Color | string): Color

Resolves a color from a color or string. If a string is passed in, it will be parsed as a hex, rgb, rgba, hsl, or hsla color. If a color is passed in, it will be returned as is. If neither a string nor a color is passed in, an undefined behavior will occur.

Getters

Color.hex: string (can set)

Gets the hex string of the color.

Color.hexString: string

Gets the hex string of the color. This will include alpha value if it is not 1.

Color.hexStringNoPound

Gets the hex string of the color without the pound sign.

Color.hexStringNoAlpha: string

Gets the hex string of the color without the alpha value. This is equivalent to Color.hexString.

Color.rgb: { r: number, g: number, b: number }

Gets the RGB values of the color.

Color.rgba: { r: number, g: number, b: number, a: number }

Gets the RGBA values of the color.

Color.rgbString: string

Gets the RGB string of the color in the form of rgb(r, g, b).

Color.rgbaString: string

Gets the RGBA string of the color in the form of rgba(r, g, b, a).

Color.hsl: { h: number, s: number, l: number }

Gets the HSL values of the color.

Color.hsla: { h: number, s: number, l: number, a: number }

Gets the HSLA values of the color.

Color.hslString: string

Gets the HSL string of the color in the form of hsl(h, s%, l%).

Color.hslaString: string

Gets the HSLA string of the color in the form of hsla(h, s%, l%, a).

Color.kelvin: number

Gets the Kelvin temperature of the color.

Color.contrast: number

Gets the contrast ratio of the color relative to some arbitrary reference.

Operators

Color.opacity(opacity: number): Color

Sets the opacity of the color. The value may be in range 0-1 (float) or 0-100 (integer).

Color.lighten(amount: number): Color

Lightens the color by the given amount. The value may be in range 0-1 (float) or 0-100 (integer).

Color.darken(amount: number): Color

Darkens the color by the given amount. The value may be in range 0-1 (float) or 0-100 (integer).

Color.saturate(amount: number): Color

Saturates the color by the given amount. The value may be in range 0-1 (float) or 0-100 (integer).

Color.desaturate(amount: number): Color

Desaturates the color by the given amount. The value may be in range 0-1 (float) or 0-100 (integer).

Color.rotate(amount: number): Color

Rotates the color by the given amount. The value may be in range 0-360 (integer).

Color.shiftRGB(r: number, g: number, b: number): Color

Shifts the RGB values of the color by the given amount. The value may be in range 0-255 (integer).

Blend Modes

Not implemented yet

Color Relationships

Color.complement: Color

Gets the complement of the color.

Color.monochromatic: Color[]

Gets the monochromatic colors of the color (10 values);

Color.triadic: Color[]

Gets the triadic colors of the color.

Color.grayscale: Color

Gets the grayscale color of the color.

Complex Transformations

Color.multiply(matrix: number[]): Color

Generates a new colors based on a 3x3 matrix transformation. The formula is:

[ r' ]   [ a b c ]   [ r ]
[ g' ] = [ d e f ] * [ g ]
[ b' ]   [ g h i ]   [ b ]

The matrix is represented as an array of 9 numbers. The result is a new color with the same alpha value as the original color. All new values are clamped to the range 0-255 (integer).

Color.clamp(n: number): number

Clamps a color value to the range 0-255 (integer).

Color.invert(value: number = 1): Color

Inverts a Color. The value may be in range 0-1 (float).

Color.linear(slope: number = 1, intercept: number = 0): Color

Applies a linear transformation to a Color.

Color.linearContrast(value: number = 1): Color

Applies a linear contrast transformation to a Color.

Color.linearBrightness(value: number = 1): Color

Applies a linear brightness transformation to a Color.

Color.sepia(value: number = 1): Color

Applies a sepia transformation to a color;

Other Methods

static Color.checkAccessibile(foreground: Color, background: Color): boolean

Checks if a foreground color is accessible on a background color. Returns true if the contrast ratio is greater than 4.5, false otherwise.