New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

loose-rgb

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loose-rgb

Normalizes RGB color data types to a certain format

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source
Icon

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

Keywords

FAQs

Package last updated on 09 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc