color-converter-by-kidker
v1.0.1
Published
`color-converter-by-kidker` is a TypeScript-based library that allows you to easily convert between various color formats.
Downloads
11
Maintainers
Readme
Color Converter
color-converter-by-kidker
is a TypeScript-based library that allows you to easily convert between various color formats.
Supported formats:
- RGB
- HSL
- CMYK
- HEX
Supported Conversions:
- RGB to HSL, CMYK, HEX
- HSL to RGB, CMYK, HEX
- CMYK to RGB, HSL, HEX
- HEX to RGB, HSL, CMYK
Installation
You can install the package using npm:
npm install color-converter-by-kidker
Usage:
import { convertColor, ColorFormat } from 'color-converter-by-kidker';
const rgbColor = "rgb(255, 0, 0)";
const hslColor = "hsl(191, 20%, 10%)";
const cmykColor = "cmyk(26%, 66%, 34%, 88%)";
const hexColor = "#035bc8";
const rgbToHsl = convertColor(rgbColor,ColorFormat.hsl); // hsl(0, 100%, 50%)
const rgbToCmyk = convertColor(rgbColor,ColorFormat.cmyk); // cmyk(0%, 100%, 100%, 0%)
const rgbToHex = convertColor(rgbColor,ColorFormat.hex); // #FF0000
const hslToRgb = convertColor(hslColor,ColorFormat.rgb); // rgb(20, 29, 31)
const hslToCmyk = convertColor(hslColor,ColorFormat.cmyk); // cmyk(35.5%, 6.5%, 0%, 87.8%)
const hslToHex = convertColor(hslColor,ColorFormat.hex); // #141D1F
const cmykToRgb = convertColor(cmykColor,ColorFormat.rgb); // rgb(23, 10, 20)
const cmykToHsl = convertColor(cmykColor,ColorFormat.hsl); // hsl(314, 39.4%, 6.5%)
const cmykToHex = convertColor(cmykColor,ColorFormat.hex); // #170A14
const hexToRgb = convertColor(hexColor,ColorFormat.rgb); // rgb(3, 91, 200)
const hexToHsl = convertColor(hexColor,ColorFormat.hsl); // hsl(213, 97%, 39.8%)
const hexToCmyk = convertColor(hexColor,ColorFormat.cmyk); // cmyk(98.5%, 54.5%, 0%, 21.6%)
const invalidRgb = "rgb(300, -10, 700)";
const invalidHsl = "hsl(200, 50 50)";
const invalidCmyk = "cmyk(50, 50, 50, 50)";
const invalidHex = "#GGGGGG";
const outputColor = convertColor(invalidRgb,ColorFormat.hex) // Error: Invalid input color format.
const outputColor = convertColor(invalidHsl,ColorFormat.rgb) // Error: Invalid input color format.
const outputColor = convertColor(invalidCmyk,ColorFormat.hsl) // Error: Invalid input color format.
const outputColor = convertColor(invalidHex,ColorFormat.rgb) // Error: Invalid input color format.
License
This project is licensed under the MIT License.
Author
kidker 95