This tiny library is very useful when you need to make simple conversions between hexadecimal and RGB values. It can convert an hexadecimal value into a RGB one and vice-versa. For example, you can easily transform #fff
into 255, 255, 255
.
You can install it via npm or Yarn:
# Using npm
$ npm install sth-hex-rgb
# Using Yarn
$ yarn add sth-hex-rgb
Note: if you're new in the web development, be aware that you can use either npm option or Yarn to install it, but not both at the same time.
You can use the Hexadecimal
to convert your hex value into an RGB object.
const hexadecimal = require('sth-hex-rgb').hexadecimal;
hexadecimal.toRGB('#ffffff');
// => { r: 255, g: 255, b: 255 }
hexadecimal.toRGB('#000');
// => { r: 0, g: 0, b: 0 }
hexadecimal.toRGB('ffffff');
// => { r: 255, g: 255, b: 255}
Just like the Hexadecimal
, the RGB
can be used when you want to convert your RGB object into an hexadecimal value.
const rgb = require('sth-hex-rgb').rgb;
rgb.toHexadecimal({ r: 255, g: 255, b: 255 });
// => #ffffff