Socket
Socket
Sign inDemoInstall

@theodorejb/color-detect

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@theodorejb/color-detect

Convert CSS color strings to RGBA and check whether they are light or dark


Version published
Weekly downloads
411
increased by41.24%
Maintainers
1
Weekly downloads
 
Created
Source

color-detect

npm version

Convert color strings to an RGBA array, and determine if the color is light or dark.

  • Includes TypeScript definitions
  • No dependencies
  • Native ES module compatible with modern browsers and build tools

Installation

npm install @theodorejb/color-detect --save

Usage

import {colorToRgba, isLightColor, rgbaToCssString} from '@theodorejb/color-detect';

// convert CSS colors to an RGBA array
colorToRgba('red'); // [255, 0, 0, 255]
colorToRgba('#123'); // [17, 34, 51, 255]
colorToRgba('rgb(80, 160, 240)'); // [80, 160, 240, 255]

// detect whether a color is light or dark
isLightColor(colorToRgba('red')); // true
isLightColor(colorToRgba('#663399')); // false
isLightColor(colorToRgba('yellow')); // true
isLightColor(colorToRgba('lime')); // true
isLightColor(colorToRgba('green')); // false

// convert an RGBA array to CSS color string
let chocolateRgb = colorToRgba('chocolate');
rgbaToCssString(chocolateRgb); // "rgba(210, 105, 30, 1)"

Author

Theodore Brown
https://theodorejb.me

License

MIT

Keywords

FAQs

Package last updated on 20 Nov 2022

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