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

loose-rgb

v1.0.7

Published

Normalizes RGB color data types to a certain format

Downloads

35

Readme

Loose RGB

Normalizes RGB color data types to a certain format

npm version check status minified + gzip bundle size license: MIT

Description

Working with different color libraries gets cumbersome when they use different RGB value formats. Now you can normalize the outputs and convert your inputs.

Features

  • Normalize any RGB format to {r, g, b, [a]}
  • Convert {r, g, b, [a]} to any RGB format
  • RGBA support
  • Hex support

Installation

npm install loose-rgb

Usage

import looseRGB from "loose-rgb";

// Convert any type to `{r, g, b, [a]}`
looseRGB.normalize({red: 1, green: 2, blue: 3}) // ? {r: 1, g: 2, b: 3}
looseRGB.normalize("FFBB00AA") // ? {r: 255, g: 187, b: 0, a: 0.66796875}

// Convert `{r, g, b, [a]}` to any type
looseRGB.convert.toCSSValue({r: 255, g: 187, b: 0, a: 0.66796875}) // ? rgba(255, 187, 0, 0.66796875)
looseRGB.convert.toUpperKeys({r: 1, g: 2, b: 3}) // ? {R: 1, G: 2, B: 3}

// Composing the above methods
import {convert, normalize} from "loose-rgb";

const anyToHex = (rgba) => convert.toHex(normalize(rgba));
anyToHex([1, 2, 3, 0.4]) // ? #01020366

Normalize

looseRGB.normalize(color: RGBUnkown)

Input any color value as color (see convert).

Convert

looseRGB.convert[to{ColorType}](color: RGBLowerKeys)

Input an {r, g, b, [a]} color to get a reformatted value. See supported formats for methods.

Supported Formats

  • .toLowerKeys()
    • {r: 1, g: 2, b: 3}
    • {r: 1, g: 2, b: 3, a: 0.4}
  • .toUpperKeys()
    • {R: 1, G: 2, B: 3}
    • {R: 1, G: 2, B: 3, A: 0.4}
  • .toFullKeys()
    • {red: 1, green: 2, blue: 3}
    • {red: 1, green: 2, blue: 3, alpha: 0.4}
  • .toArray()
    • [1, 2, 3]
    • [1, 2, 3, 0.4]
  • .toCSSValue() Supports with and without spacing between commas, leading zero on decimal
    • "rgb(0, 213, 34)"
    • "rgba(0, 213, 34,.12)"
  • .toHex() Supports with and without pound, case insensitive, with shorthand
    • "#fff"
    • "#000000"
    • "#FFBB00AA"
    • "123"
    • "FFFF"

License

Copyright Evelyn Hathaway, MIT License