Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rgb-hex

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rgb-hex - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

24

index.js
'use strict';
/* eslint-disable no-mixed-operators */
module.exports = (red, green, blue) => {
module.exports = (red, green, blue, alpha) => {
const isPercent = (red + (alpha || '')).toString().includes('%');
if (typeof red === 'string') {
const res = red.match(/\b\d{1,3}\b/g).map(Number);
const res = red.match(/(0?\.?\d{1,3})%?\b/g).map(Number);
// TODO: use destructuring when targeting Node.js 6

@@ -10,2 +12,5 @@ red = res[0];

blue = res[2];
alpha = res[3];
} else if (alpha !== undefined) {
alpha = parseFloat(alpha);
}

@@ -22,3 +27,16 @@

return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1);
if (typeof alpha === 'number') {
if (!isPercent && alpha >= 0 && alpha <= 1) {
alpha = Math.round(255 * alpha);
} else if (isPercent && alpha >= 0 && alpha <= 100) {
alpha = Math.round(255 * alpha / 100);
} else {
throw new TypeError(`Expected alpha value (${alpha}) as a fraction or percentage`);
}
alpha = (alpha | 1 << 8).toString(16).slice(1);
} else {
alpha = '';
}
return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1) + alpha;
};

4

package.json
{
"name": "rgb-hex",
"version": "2.0.0",
"description": "Convert RGB color to HEX",
"version": "2.1.0",
"description": "Convert RGB(A) color to HEX",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": "sindresorhus/rgb-hex",

# rgb-hex [![Build Status](https://travis-ci.org/sindresorhus/rgb-hex.svg?branch=master)](https://travis-ci.org/sindresorhus/rgb-hex)
> Convert RGB color to HEX
> Convert RGB(A) color to HEX

@@ -23,2 +23,11 @@

//=> '282a36'
rgbHex(65, 131, 196, 0.2);
//=> '4183c433'
rgbHex(40, 42, 54, '75%');
//=> '282a36c0'
rgbHex('rgba(40, 42, 54, 75%)');
//=> '282a36c0'
```

@@ -25,0 +34,0 @@

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