Skip to content

JavaScript library to convert color format from RGB to HEX and vice versa

Notifications You must be signed in to change notification settings

mkousta/color-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

colorformat

A simple JavaScript library to convert color format from RGB to HEX and vice versa

Installation

npm install colorformat

Example use cases

Convert an RGB to HEX:

cf = require('colorformat');

cf.rgbToHex(230, 241, 246); // => '#e6f1f6'

//  or with string input
cf.rgbToHex('230', '241', '246'); // => '#e6f1f6'

Convert a HEX to RGB:

cf = require('colorformat');

cf.hexToRgb('#e6f1f6'); //=> [ 230, 241, 246 ]

// or if you want a string for styling
cf.hexToRgb('#e6f1f6', { styling: true }); //=> 'rgb(230, 241, 246)'

The simplest browser use

Load the script node_modules/colorformat/index.js and then simply:

ColorFormat.rgbToHex(230, 241, 246); // => '#e6f1f6'

Note: Supports UMD for easier browser use with the tools of your preference.

How to run tests

npm test

About

JavaScript library to convert color format from RGB to HEX and vice versa

Resources

Stars

Watchers

Forks

Packages

No packages published