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

@talesoft/color

v0.1.4

Published

Color JS ========

Downloads

3

Readme

Color JS

A color manipulation and conversion library.

It's supposed to ease up creation of JS-based frontend themes when using CSS in JavaScript.

It's written for React's Styled Components and Emotion CSS and designed to work well with it, but does work well anywhere where you need color manipulation and automatic generation of color schemes.

What can it do

  • Parsing of different color formats
    • 866 different color names (List)
    • Hexadecimal colors (e.g. #f0a or #ef0bac)
    • CSS color functions (e.g. rgb(255, 127, 0) or hsla(180, 1, .5))
  • Convert colors between different color spaces. Supported/planned spaces:
    • [x] RGB/RGBA
    • [x] HSL/HSLA
    • [ ] HSV/HSVA
    • [ ] CMYK Approximation
    • [ ] CIE-XYZ
    • [ ] CIE-LAB
  • Retrieving information from colors
    • Get RGB information (amount of red, green and blue)
    • Get HSL information (hue/color tone, saturation, lightness)
    • Get alpha information (transparency)
  • Color manipulation
    • darken, lighten, saturate and desaturate colors
    • Change color properties like the amount of red or green
    • inverse and mix colors
    • Change transparency of colors (fade in, fade out)
    • Generate complementary or similar colors
  • Easily generate color schemes and palettes from base colors
    • Complementary schemes (playing with hues)
    • Shades, tints and tones of colors

Installation

Yarn:

yarn add @talesoft/color

NPM:

npm i @talesoft/color

TypeScript Types included.

Usage

Directly access known colors and manipulate them:

import Color from '@talesoft/color'

const darkRed = Color.red.darken(.2)
console.log(`Dark red is: ${darkRed}`) // "Dark red is: #900"

Works well with e.g. Styled-Components/Emotion CSS for React:

const StyledDiv = styled.div`
    background-color: ${Color.mediumCarmine.darken(.1).fadeOut(.2)};
    color: ${Color.palatinatePurple};
`

Use Color.parse function to quickly parse and modify own colors.

import Color from '@talesoft/color'

const darkRed = Color.parse('#f00')
    .darken(.2)

console.log(`Dark red is: ${darkRed}`)

Color.parse and dye support most commonly known ways to write colors

import Color, { dye } from '@talesoft/color'

const red = Color.parse('#f00')

const green = Color.parse('#00ff00')

const green = Color.parse('green')

const yellow = Color.parse('rgb(255, 255, 0)')

const redToo = Color.parse('hsl(0, 1, .5)')

// Percent values are allowed anywhere

const redAgain = Color.parse('rgb(100%, 0%, 0%)')

Pick from a growing list of color manipulation functions. Don't worry about color spaces. All operations are immutable.

const color = Color.pastelYellow

// Get RGB Values
console.log(color.red, color.green, color.blue) // 253, 253, 150

// Get HSL Values
console.log(color.hue, color.saturation, color.lightness) // 60, 0.790..., 0.962...

// Get the transparency/opacity
console.log(color.opacity) // 1

// Modify Red value
color = color.withRed(255)

// Modify Green Value
color = color.withGreen(255)

// Modify Blue value
color = color.withBlue(255)

// Modify Hue value (color tone)
color = color.withHue(180)

// Modify saturation
color = color.withSaturation(.4)

// Modify lightness
color = color.withLightness(.2)

// Modify opacity/transparency
color = color.withOpacity(.5)

// Get complementary color
color = color.complement()

// Mix colors
color = color.mix(Color.red) // Using subtractive model by default
color = color.mix(Color.red, MixMode.RGB_ADDITIVE)

// Lighten/darken a color
color = color.lighten(.1)
color = color.darken(.2)

// Tint or tone colors (increase or decrease saturation)
color = color.tint(.1)
color = color.tone(.2)

// Invert a color
color = color.invert()

// Get the grayscale version of color
color = color.grayscale()

// Increase/decrease opacity of a color
color = color.fadeIn(.2)
color = color.fadeOut(.1)

// Cast to strings/output
console.log(color.toFunctionExpression()) // e.g. "rgb(255,43,45)"
console.log(color.toHexExpression()) // e.g. "#34ca3f"

// Perfectly fitting string representation for CSS
console.log(color.toString())
console.log(`Color: ${color}`)

Easily create automatically generated color schemes from your colors:

import { dye } from '@talesoft/color';

const { primary, secondary } = Color.parse('#f00').complements
// primary will be red, secondary will be green (the complementary color)

const shadesOfGrey = Color.gray.shades
shadesOfGrey.lightest
shadesOfGrey.lighter
shadesOfGrey.light
shadesOfGrey.normal
shadesOfGrey.dark
shadesOfGrey.darker
shadesOfGrey.darkest

// Complex hue rotation schemes are supported
const {
    primary,
    secondary,
    tertiary,
    quartenary
} = Color.parse('#ce5a62').tetradicComplements

// Easily run your own scheme
import { darken } from '@talesoft/color';

const { firstShade, secondShade, thirdShade } = Color.parse('#ce5a62')
    .createScheme(
        ['firstShade','secondShade','thirdShade'],
        darken,
        { start: .2, step: .2 },
    )