JavaScript

const toHSLArray = (hslStr) => {
  const hslArr = hslStr.match(/\d+/g)?.map(Number)
  if (hslArr && hslArr.length >= 3) {
    return [hslArr[0], hslArr[1], hslArr[2]]
  }
}

TypeScript

export const toHSLArray = (
  hslStr: string
): [number, number, number] | undefined => {
  const hslArr = hslStr.match(/\d+/g)?.map(Number)
  if (hslArr && hslArr.length >= 3) {
    return [hslArr[0], hslArr[1], hslArr[2]]
  }
}

Example

toHSLArray('hsla(241, 77%, 54%, 1)')
> [241, 77, 54]

Till next time, take care ✌

Helpful?

If you think this is helpful 🎈
Don't keep it to yourself 🙊

Share it with your lovely followers at twitter 🗽

lets connect viatwitter