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

micro-color

v1.1.1

Published

A tiny (1 kB gzipped), limited & tree-shakeable color manipulation library

Downloads

28

Readme

micro-color

| Type | Info | | :----------: | :-----------------------------------------------------------: | | Gzipped | | | Minified | | | Tree-shaking | |

Data from Bundlephobia

Info

A tiny, limited and tree-shakable alternative to color. Based off of Robin Weser's small-color package.

It is very limited and optimized for runtime usage in the browser.

It only supports a subset of color and does not have input validation.

It has zero dependencies and supports tree-shaking, making its size even smaller depending on the functions used.

Installation

yarn add micro-color
npm i micro-color

Limitations

  1. Only valid CSS color strings can be used as inputs (rgb, rgba, hsl, hsla, hex)
  2. Output values are rounded to 2 or 4 decimal places (depending on the property)
  3. Only outputs RGBA or HSLA values (alpha is always provided, even if 1)
  4. Inputs are not validated (but adjustments are clamped to the valid values)

Usage

In order to use any manipulation function, we need to parse our color string.

Now we can manipulate it until we finally generate a string again.

import { parse, toRgb, desaturate, lighten, fade } from 'small-color'

const color = parse('rgb(255, 0, 100)')

const lightened = lighten(color, 0.5)
const saturated = desaturate(lightened, 0.3)
const faded = fade(saturated, 0.5)

const output = toRgb(faded)

console.log(output) // => "rgba(236, 147, 182, 0.5)"

API

parse(string): Color

Parses a CSS color string into a color object that the package can manipulate.

Accepts any "normal" CSS color string:

  • rgb(r, g, b)
  • rgba(r, g, b, a)
  • hsl(h, s, l)
  • hsla(h, s, l, a)
  • #rrggbb
  • #rrggbbaa
  • #rgb
  • #rgba

Example

parse('hsl(180, 50%, 75%)') // => { h: 0.5, s: 0.5, l: 0.75, a: 1 }
parse('rgb(128, 128, 128, 0.675)') // => { h: 0, s: 0, l: 0.5, a: 0.675 }
parse('#ffffff') // => { h: 0, s: 0, l: 1, a: 1 }
parse('#fff80') // => { h: 0, s: 0, l: 1, a: 0.5 }

lighten(Color, float): Color

Lightens a Color object by a given factor.

Supplied lighten factor should be provided as a number >= 0, where 0 is no increase and 1 is a 100% increase (double).

The lightness will not exceed 100%, or subceed 0%.

darken(Color, float): Color

Darkens a Color object by a given factor.

Supplied darken factor should be provided as a number between 0 and 1, where 0 is no decrease and 1 is a 100% decrease (black).

The lightness will not exceed 100%, or subceed 0%.

saturate(Color, float): Color

Increases saturation of a Color object by a given factor.

Supplied saturation factor should be provided as a number >= 0, where 0 is no increase in saturation and 1 is a 100% increase in saturation (doubled saturation).

The saturation will not exceed 100%, or subceed 0%.

desaturate(Color, float): Color

Desaturates a Color object by a given factor.

Supplied desaturation factor should be provided as a number between 0 and 1, where 0 is no decrease in saturation and 1 is a 100% decrease in saturation.

The saturation will not exceed 100%, or subceed 0%.

fade(Color, float): Color

Increases the opacity of a Color object by a given factor.

Supplied factor should be between 1 and 0, where 1 makes the color fully transparent, and 0 creates 0 change in opacity.

The alpha value will not exceed 1, or subceed 0.

opaquer(Color, float): Color

Decreases the opacity of a Color object by a given factor.

Supplied factor should be between 0 and 1, where 1 doubles the alpha value (2x more opaque), and 0 means no change in transparency.

The alpha value will not exceed 1, or subceed 0.

grayscale(Color): Color

Converts a Color object to grayscale. (Removes all saturation.)

hueShift(Color, int): Color

Performs a hue shift with the supplied input. Positive for a right shift, negative for a left shift. Input should be an integer between -359 and 359 (but could be any number).

Wrapping (e.g. -180 shift on 90 becomes 270) is performed automatically.

toRgb(Color): string

Converts a Color object to a CSS-interpretable RGBA string, e.g. rgba(128, 128, 128, 0.75).

Note that the alpha is always included, even if it's 1.

toHsl(Color): string

Converts a Color object to a CSS-interpretable HSLA string, e.g. hsla(325, 75%, 66%, 0.75).

Note that the alpha is always included, even if it's 1.

License

micro-color is licensed under the MIT License.

Documentation is licensed under Creative Common License.

Original project created with ♥ by @robinweser and all the great contributors.