Although there are a bunch of color conversion libraries on npm, I couldn't find one where it was simple to just import the conversions you want. While importing a library is not a big deal in node, for the browser there is not reason to load a whole library of code you are not using. Normally I find I only need one conversion.
Current API
Hexadecimal to HSL
; const paleCornflowerBlueHsl = ; console; // => { h: 210, s: 68, l: 80.3921568627451}
Hexadecimal to RGB
; const paleCornflowerBlueRgb = ; console; // => { r: 171, g: 205, b: 239 }
RGB to Hexadecimal
; const mintGreenHex = ; console; // => '#98FF98'
RGB to HSL
; const dreamyRedHsl = ; console; // => { h: 0, s: 70.13574660633485, l: 56.666666666666664 }
HSL to Hexadecimal
; const mauveHex = ; console; // => '#e0B3FF'
HSL to RGB
; const foamGreenRgb = ; console; // => { r: 140.83139999999997, g: 198.543, b: 102.35699999999997 }
Keeping it simple
In the spirit of keeping it unixy this library does not aim to round your results, or allow you to pass arguments with r g b / h s l properties, etc. If you wanna do that here are some really simple examples.
Passing objects with h s l properties
; const hslObjectToRgb = ; const foamGreenHsl = h: 96 s: 46 l: 59; const foamGreenRgb = ; console; // => { r: 140.83139999999997, g: 198.543, b: 102.35699999999997 }
Rounding results to two decimal places
;; const roundTo2Decimal = Math / 100;const roundObject = ; const foamGreenRgb = ; console; // => { r: 140.83, g: 198.54, b: 102.36 }