New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rgb-from-hex

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rgb-from-hex

A simple Javascript/TypeScript package that converts hexadecimal color codes to RGB format.

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

rgb-from-hex

A simple Javascript/TypeScript package that converts hexadecimal color codes to RGB format.

Installation

You can install the package using npm:

npm install rgb-from-hex

Usage

import rgbFromHex from 'rgb-from-hex';

// Convert hex to RGB object
const rgbObject = rgbFromHex('#3498db');
console.log(rgbObject); // { red: 52, green: 152, blue: 219 }

// Convert hex to RGB CSS string
const rgbCss = rgbFromHex('#3498db', { outputType: 'rgb-css' });
console.log(rgbCss); // "rgb(52,152,219)"

// Convert hex to RGB array
const rgbArray = rgbFromHex('#3498db', { outputType: 'array' });
console.log(rgbArray); // [52, 152, 219]

API

rgbFromHex(hex, options)

Converts a hexadecimal color code to RGB format.

  • hex: The input hexadecimal color code (e.g., #3498db).
  • options: (Optional) An object with the following property:
    • outputType: Specifies the output type. Can be 'object', 'rgb-css', or 'array'. Defaults to 'object'.

Returns an RGB object with red, green, and blue properties, an RGB CSS string, or an RGB array, based on the specified output type.

Returns null if the input hex code is invalid.

License

This project is licensed under the MIT License - see the LICENSE file for details.

FAQs

Package last updated on 21 Dec 2023

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