UNPKG

@iamsuz/color-kit

Version:

A toolkit to generate random colors and identify color names

49 lines (48 loc) 1.21 kB
export type ColorMatch = { /** * - The original hex color value. */ inputColor: string; /** * - The name of the matched color. */ colorName: string; /** * - The hex value of the closest match or null if not found. */ closestHex: string | null; /** * - Whether the color is an exact match or not. */ exactMatch: boolean; /** * - The distance between the input color and the closest match (optional). */ distance?: number | undefined; }; export type IC = { /** * - Function to get the closest color match. */ name: (color: string) => ColorMatch; /** * - Function to convert hex to RGB. */ rgb: (color: string) => number[]; /** * - Function to calculate the distance between two RGB colors. */ calculateDistance: (rgb1: number[], rgb2: number[]) => number; }; /** * This function identifies the give color hex value or its closest color * @param {*} hex * @returns Object */ export function identifyColor(hex: any): ColorMatch; /** * This function converts hex color to rgb value * @param {*} hex * @returns */ export function hexToRgb(hex: any): number[];