ToolPouch

Colors

Work with colors: convert between HEX, RGB, and HSL formats.

Install the SDK

npm install @toolpouch/sdkView on npm →

Import from this module

import { functionName } from '@toolpouch/sdk/colors'

hexToRgb

Signature

hexToRgb(hex: string): { r: number; g: number; b: number }

Convert HEX color to RGB values.

Example

import { hexToRgb } from '@toolpouch/sdk/colors';
const rgb = hexToRgb('#FF5733');
// { r: 255, g: 87, b: 51 }

Returns

Object with r, g, b values (0-255)

rgbToHex

Signature

rgbToHex(r: number, g: number, b: number): string

Convert RGB values to HEX color.

Example

import { rgbToHex } from '@toolpouch/sdk/colors';
const hex = rgbToHex(255, 87, 51);
// '#FF5733'

Returns

HEX color string

hexToHsl

Signature

hexToHsl(hex: string): { h: number; s: number; l: number }

Convert HEX color to HSL values.

Example

import { hexToHsl } from '@toolpouch/sdk/colors';
const hsl = hexToHsl('#FF5733');
// { h: 9, s: 100, l: 60 }

Returns

Object with h (0-360), s (0-100), l (0-100)

colorConvert

Signature

colorConvert(input: string): { hex: string; rgb: string; hsl: string }

Convert color from any format (HEX, RGB) to all formats.

Example

import { colorConvert } from '@toolpouch/sdk/colors';
const colors = colorConvert('#FF5733');
// { hex: '#FF5733', rgb: 'rgb(255, 87, 51)', hsl: 'hsl(9, 100%, 60%)' }

Returns

Object with hex, rgb, and hsl string representations