Skip to main content

@omega/color@1.2.11
Built and signed on GitHub Actions

Various color conversions.

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
6 months ago (1.2.11)
function parseHexToHSL
parseHexToHSL(hex: string): null | Array<number>

Attempts to parse a string as a RGB(A) hex color code into a HSL(A) array.

Examples

Parsing a long form RGBA hex code with alpha:

const hex = '#FF000069' // Red

const hsl = parseHexToHSL(hex)

console.debug(hsl) // [ 0 , 100 , 50 , 69 ]

Parsing a short form RGB hex code without #:

const hex = 'F00' // Red

const hsl = parseHexToHSL(hex)

console.debug(hsl) // [ 0 , 100 , 50 ]

Parsing an invalid hex color code:

const hex = 'Invalid'

const hsl = parseHexToHSL(hex)

console.debug(hsl) // null

Parameters

String possibly containing a hex RGB(A) color code.

Return Type

null | Array<number>

[ 𝗛𝘂𝗲 0 - 360 , 𝗦𝗮𝘁𝘂𝗿𝗮𝘁𝗶𝗼𝗻 0 - 100 , 𝗟𝗶𝗴𝗵𝘁𝗻𝗲𝘀𝘀 0 - 100 , ( 𝗔𝗹𝗽𝗵𝗮 0 - 255 ) ]

Returns null if no color code could be matched.

Add Package

deno add jsr:@omega/color

Import symbol

import { parseHexToHSL } from "@omega/color/HSL";

---- OR ----

Import directly with a jsr specifier

import { parseHexToHSL } from "jsr:@omega/color/HSL";

Add Package

npx jsr add @omega/color

Import symbol

import { parseHexToHSL } from "@omega/color/HSL";

Add Package

yarn dlx jsr add @omega/color

Import symbol

import { parseHexToHSL } from "@omega/color/HSL";

Add Package

pnpm dlx jsr add @omega/color

Import symbol

import { parseHexToHSL } from "@omega/color/HSL";

Add Package

bunx jsr add @omega/color

Import symbol

import { parseHexToHSL } from "@omega/color/HSL";