Socket
Socket
Sign inDemoInstall

@theodorejb/color-detect

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

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
473
increased by0.85%
Maintainers
1
Install size
5.55 kB
Created
Weekly downloads
 

Changelog

Source

[2.0.0] - 2022-11-20

Added

  • colorLuminance() function which implements the W3C algorithm to determine a color's relative luminance.

Changed

  • Renamed colorToRgbaArray() to simply colorToRgba().

Fixed

  • isLightColor() now correctly follows W3C algorithm for comparing color contrast.

Readme

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

Last updated on 20 Nov 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc