A javascript library to convert between various css colour formats.
Install niram
using any of the command below
yarn add niram
npm install niram
To convert colours:
import { convertColor } from 'niram'
const color = convertColor('hsl(120deg, 100%, 25%)')
console.log(color)
Above code will log the converted colour details to console as:
{
"name": "green",
"decimal": 8388863,
"hex": "#008000",
"rgb": "rgb(0, 128, 0)",
"rgba": "rgba(0, 128, 0, 1)",
"hsl": "hsl(120deg, 100%, 25%)",
"hsla": "hsla(120deg, 100%, 25%, 1)",
"opacity": 1
}
To validate colours:
import { validateColor } from 'niram'
const isColorValid = validateColor('hwb(120deg 0% 50% / 1)')
console.log(isColorValid)
// Outputs: true
Following are the supported colour formats (given with example)
-
Colour Keywords -
green
-
HEX -
#008000
or#0f0
-
RGB -
rgb(0, 128, 0)
orrgb(0 128 0)
-
RGBA -
rgba(0, 128, 0, 1)
orrgba(0 128 0 / 1)
-
HSL* -
hsl(120deg, 100%, 25%)
orhsl(120deg 100% 25%)
-
HSLA* -
hsla(120deg, 100%, 25%, 1)
orhsla(120deg 100% 25% / 1)
-
HWB*# -
hwb(120deg 0% 50% / 1)
-
LAB# -
lab(46.23 -51.7 49.9 / 1)
-
LCH# -
lch(46.28% 67.98 134.38 / 1)
* You can also use rad
instead of deg
# Support is only available for Validation
Following are currently unsupported for conversion, but support will be added soon.
hwb()
lab()
lch()