shelving
Version:
Toolkit for using data in JavaScript.
37 lines (36 loc) • 1.65 kB
TypeScript
import type { AnyCaller } from "./function.js";
export declare const HEX3_REGEXP: RegExp;
export declare const HEX6_REGEXP: RegExp;
/** Things that can be converted to a `Color` instance. */
export type PossibleColor = Color | string;
/** Represent a color. */
export declare class Color {
/** Make a `Color` from an unknown value. */
static from(possible: unknown): Color | undefined;
readonly r: number;
readonly g: number;
readonly b: number;
readonly a: number;
constructor(r?: number, g?: number, b?: number, a?: number);
/** Convert this color to a six or eight digit hex color. */
get hex(): string;
/** Convert this color to an `rgb()` string. */
get rgb(): string;
/** Convert this color to an `rgba()` string. */
get rgba(): string;
/** Get the sRGB luminance of this color. */
get luminance(): number;
/** Is this color light. */
get isLight(): boolean;
/** Is this color dark. */
get isDark(): boolean;
toString(): string;
}
/** Is an unknown value a `Color` instance. */
export declare function isColor(value: unknown): value is Color;
/** Assert that an unknown value is a `Color` instance. */
export declare function assertColor(value: unknown, caller?: AnyCaller): asserts value is Color;
/** Convert an unknown value to a `Color` instance, or return `undefined` if conversion fails. */
export declare function getColor(value: unknown): Color | undefined;
/** Convert a possible color to a `Color` instance, or throw `RequiredError` if it can't be converted. */
export declare function requireColor(value: PossibleColor, caller?: AnyCaller): Color;