Skip to content

Home

HSL to object

Converts an hsl() color string to an object with the values of each color.

const toHSLObject = hslStr => {
  const [hue, saturation, lightness] = hslStr.match(/\d+/g).map(Number);
  return { hue, saturation, lightness };
};

toHSLObject('hsl(50, 10%, 10%)'); // { hue: 50, saturation: 10, lightness: 10 }

More like this

Start typing a keyphrase to see matching snippets.