Color object output
Read numeric channels when you need values for a color picker, renderer or calculation. Use toObject(space) to keep the space with the channels, or toArray(space) when the caller already knows the channel order.
Example
import { colore } from 'colore-js';
const blue = colore('#2563eb');
console.log(blue.toRgb()); // { r: 37, g: 99, b: 235, alpha: 1 }
console.log(blue.toOklch().l.toFixed(3)); // '0.546'
Syntax
Parameters
Throws
A ColorError if the space name is unsupported.
Keep an exact copy for later calculations
import { colore } from 'colore-js';
const blue = colore('#2563eb');
const saved = blue.toObject('srgb-linear');
console.log(colore(saved).equals(blue, 0)); // true
Numeric conversions can produce out-of-range values. For example, P3 red gives an sRGB red channel above 255 through toRgb(). Use toGamut() if the caller requires an in-gamut result.
Related
- Color spaces and ranges for channel units
- Color string output for CSS strings
- Precision, rounding and equality