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
661
increased by57.38%
Maintainers
1
Install size
6.35 kB
Created
Weekly downloads
 

Changelog

Source

[1.0.0] - 2018-03-15

  • Initial release

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
  • Works with Webpack and Rollup module bundlers, as well as modern browsers
  • No dependencies

Installation

npm install @theodorejb/color-detect --save

Usage

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

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

// convert an RGBA array to CSS color string
rgbaToCssString(colorToRgbaArray('blue')); // rgba(0, 0, 255, 1)

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

Author

Theodore Brown
https://theodorejb.me

License

MIT

Keywords

FAQs

Last updated on 15 Mar 2018

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