xyzToLab
The xyzToLab
function converts XYZ color values to LAB color space.
Syntax
xyzToLab(x: number, y: number, z: number, asString?: true): string;
xyzToLab(x: number, y: number, z: number, asString?: false): { l: number; a: number; b: number };
xyzToLab(x: number, y: number, z: number, asString: boolean = true): string | { l: number; a: number; b: number };
Parameters
x
(number): The X component.y
(number): The Y component.z
(number): The Z component.asString
(boolean, optional): Whether to return the result as a string (default is true).
Returns
- string: The LAB color string in the format "lab(l, a, b)" if
asString
is true. - object: The LAB color as an object with properties
l
,a
, andb
ifasString
is false.
Throws
- Error: Throws an error if any of the color values are out of range.
Example
import { xyzToLab } from 'colore-js';
// Example usage as string
const labString = xyzToLab(41.24, 21.26, 1.93);
console.log(labString); // Output: "lab(53.23288% 80.109309 67.220068)"
// Example usage as object
const labObject = xyzToLab(41.24, 21.26, 1.93, false);
console.log(labObject); // Output: { l: 53.23288, a: 80.109309, b: 67.220068 }
Usage
The xyzToLab
function is useful for converting XYZ color values to the LAB color space, which can be beneficial for various color manipulations and adjustments in applications.