Color Converter

Design

Convert between HEX, RGB, and HSL with lighten/darken helpers.

Import

Import
import { color } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
color.hexToRgbhex: string{ r, g, b }Convert HEX to RGB
color.rgbToHexr: number, g: number, b: numberstringConvert RGB to HEX
color.rgbToHslr: number, g: number, b: number{ h, s, l }Convert RGB to HSL
color.hslToRgbh: number, s: number, l: number{ r, g, b }Convert HSL to RGB
color.hexToHslhex: string{ h, s, l }Convert HEX to HSL
color.hslToHexh: number, s: number, l: numberstringConvert HSL to HEX
color.convertinput: stringobjectConvert any color format
color.isValidHexhex: stringbooleanValidate a HEX color
color.lightenhex: string, amount: numberstringLighten a color by percentage
color.darkenhex: string, amount: numberstringDarken a color by percentage

Examples

HEX to RGB
import { color } from 'toolmetry';

const rgb = color.hexToRgb('#3B82F6');
// { r: 59, g: 130, b: 246 }
Full Conversion
import { color } from 'toolmetry';

const all = color.convert('#3B82F6');
// { hex: "#3b82f6", rgb: {r:59,g:130,b:246},
//   hsl: {h:217,s:91,l:60},
//   cssRgb: "rgb(59, 130, 246)",
//   cssHsl: "hsl(217, 91%, 60%)" }
Lighten/Darken
import { color } from 'toolmetry';

const lighter = color.lighten('#3B82F6', 20);
const darker = color.darken('#3B82F6', 20);

Try It Live