Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The rgb2hex npm package is a utility that allows you to convert RGB color values to hexadecimal color codes. This can be useful in various scenarios such as web development, graphic design, and any other field where color manipulation is required.
Convert RGB to Hex
This feature allows you to convert an RGB color string to its hexadecimal representation. In this example, the RGB color 'rgb(255, 0, 0)' is converted to the hex color '#ff0000'.
const rgb2hex = require('rgb2hex');
const hexColor = rgb2hex('rgb(255, 0, 0)');
console.log(hexColor); // { hex: '#ff0000', alpha: 1 }
Convert RGBA to Hex
This feature allows you to convert an RGBA color string to its hexadecimal representation, including the alpha value. In this example, the RGBA color 'rgba(255, 0, 0, 0.5)' is converted to the hex color '#ff0000' with an alpha value of 0.5.
const rgb2hex = require('rgb2hex');
const hexColor = rgb2hex('rgba(255, 0, 0, 0.5)');
console.log(hexColor); // { hex: '#ff0000', alpha: 0.5 }
The color-convert package provides a wide range of color conversions, including RGB to Hex. It supports many other color models and conversions, making it more versatile than rgb2hex.
The color package is a comprehensive library for color manipulation and conversion. It supports RGB to Hex conversion along with many other color formats and operations, offering more functionality compared to rgb2hex.
The tinycolor2 package is a small, fast library for color manipulation and conversion. It supports RGB to Hex conversion and offers additional features like color mixing, lightening, darkening, and more, making it a more feature-rich alternative to rgb2hex.
Parse any rgb or rgba string into a hex color. Lightweight library, no dependencies!
via NPM:
$ npm install rgb2hex
via Bower
$ bower install rgb2hex
Include rgb2hex.js
in your web app, by loading it as usual:
<script src="rgb2hex.js"></script>
var rgb2hex = require('rgb2hex');
console.log(rgb2hex('rgb(210,43,2525)'));
/**
* returns:
* {
* hex: '#d22bff',
* alpha: 1
* }
*/
console.log(rgb2hex('rgba(12,173,22,.67)'));
/**
* returns:
* {
* hex: '#d22bff',
* alpha: 0.67
* }
*/
rgb2hex can be also loaded with AMD:
require(['rgb2hex'], function (rgb2hex) {
// ...
});
Please fork, add specs, and send pull requests! In lieu of a formal styleguide, take care to maintain the existing coding style.
FAQs
lightweight rgb/rgba to hex parser
We found that rgb2hex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.