Fcolor
Bun

function

color

function color(
input: ColorInput,
outputFormat?: 'number' | 'hex' | 'ansi' | 'ansi-16' | 'ansi-16m' | 'ansi-256' | 'css' | 'HEX' | 'hsl' | 'lab' | 'rgb' | 'rgba'
): null | string;

Converts formats of colors

@param input

A value that could possibly be a color

@param outputFormat

An optional output format

function color(
input: ColorInput,
outputFormat: '[rgb]'
): null | [number, number, number];

Convert any color input to rgb

@param input

Any color input

@param outputFormat

Specify [rgb] to output as an array with r, g, and b properties

function color(
input: ColorInput,
outputFormat: '[rgba]'
): null | [number, number, number, number];

Convert any color input to rgba

@param input

Any color input

@param outputFormat

Specify [rgba] to output as an array with r, g, b, and a properties

function color(
input: ColorInput,
outputFormat: '{rgb}'
): null | { b: number; g: number; r: number };

Convert any color input to a number

@param input

Any color input

@param outputFormat

Specify {rgb} to output as an object with r, g, and b properties

function color(
input: ColorInput,
outputFormat: '{rgba}'
): null | { a: number; b: number; g: number; r: number };

Convert any color input to rgba

@param input

Any color input

@param outputFormat

Specify {rgba} to output as an object with r, g, b, and a properties

function color(
input: ColorInput,
outputFormat: 'number'
): null | number;

Convert any color input to a number

@param input

Any color input

@param outputFormat

Specify number to output as a number

Referenced types

type ColorInput = { a: number; b: number; g: number; r: number } | [number, number, number] | [number, number, number, number] | Uint8Array | Uint8ClampedArray | Float32Array | Float64Array | string | number | { toString(): string }

Valid inputs for color