1.0.1 • Published 6 months ago

@utilify/colors v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Color Utilities

The color utility functions provide a variety of methods for color conversion and validation operations. These functions help simplify common tasks, such as converting between different color formats and validating color strings.

Installation

To install the color utility functions, use one of the following commands, depending on your package manager:

npm install @utilify/colors
yarn add @utilify/colors
pnpm add @utilify/colors

After installation, you can import the functions into your project using either ESM or CJS.

Usage

This library supports both the ESM and CJS module systems.

import { rgbToHsl, rgbToHex, isRgb } from '@utilify/colors';
const { rgbToHsl, rgbToHex, isRgb } = require('@utilify/colors');

Overview

Here is an overview of the functions available in the color utilities package:

rgbToHsl

function rgbToHsl(rgb: string): string | null

Converts an RGB color string to its HSL representation.

rgbToHex

function rgbToHex(rgb: string): string | null

Converts an RGB color string to its hexadecimal representation.

isRgb

function isRgb(rgb: string): boolean

Checks if a given string is a valid RGB or RGBA color.

isHsl

function isHsl(hsl: string): boolean

Checks if a given string is a valid HSL or HSLA color.

isHex

function isHex(hex: string): boolean

Checks if a given string is a valid hexadecimal color, including the alpha channel.

hslToRgb

function hslToRgb(hsl: string): string | null

Converts an HSL color string to its RGB representation.

hslToHex

function hslToHex(hsl: string): string | null

Converts an HSL color string to its hexadecimal representation.

hexToRgb

function hexToRgb(hex: string): string | null

Converts a hexadecimal color string to its RGB representation.

hexToHsl

function hexToHsl(hex: string): string | null

Converts a hexadecimal color string to its HSL representation.