Skip to content

How to convert oklch to hex #245

@bfg-coding

Description

@bfg-coding

Hello, I stumbled across this library while working on a project of mine. I'm working to extract daisyui colors, which are in oklch format and use them in my canvas system. I'm struggling getting the conversion to work and would love ideas on how to do this better. This library looks like it should be the right answer to this kind of situation

function oklchToHex(oklchStr: string): string {
	const [l, c, h] = oklchStr
		.split(",")
		.map((val) => val.replace("%", ""))
		.map(Number);
	const color = oklch({ mode: "oklch", l: l / 100, c, h });

	return formatHex(color);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions