assertGamutTarget
Asserts gamut is undefined (the sRGB default) or a supported GamutTarget ('srgb' or 'display-p3'), narrowing its type. Anything else, such as the removed 'p3' spelling, throws instead of silently mapping to sRGB.
import { assertGamutTarget } from '@pbroom/color-kit/plane';target.ts:26function assertGamutTarget(
gamut: unknown,
fn: string,
): asserts gamut is GamutTarget | undefined;Parameters
- gamut
unknown - Value read from caller options or a query.
- fn
string - Public function name used as the message prefix.
Returns
asserts gamut is GamutTarget | undefined
Throws
- When
gamutis notundefined,'srgb'or'display-p3'(includingnull). The message is`${fn}: unknown gamut "${gamut}"`; for'p3'it adds'p3' is not supported; use 'display-p3'.
Example
import { assertGamutTarget } from '@pbroom/color-kit/plane';
assertGamutTarget('display-p3', 'render()'); // returns; narrows the type
assertGamutTarget('p3', 'render()');
// throws TypeError: render(): unknown gamut "p3". 'p3' is not supported; use 'display-p3'Also exported from
@pbroom/color-kitthe same declaration, re-exported