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('#FF );5733 '// { r: 255 , g:87 , b:51 }
Returns
Object with r, g, b values (0-255)
rgbToHex
Signature
rgbToHex(r: number, g: number, b: number): stringConvert RGB values to HEX color.
Example
import { rgbToHex }from '@toolpouch/sdk/colors' ;const hex = rgbToHex(255 ,87 ,51 );// '#FF 5733 '
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('#FF );5733 '// { 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('#FF );5733 '// { hex: '#FF , rgb:5733 ''rgb( , hsl:255 ,87 ,51 )''hsl( }9 ,100 %,60 %)'
Returns
Object with hex, rgb, and hsl string representations