Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@utilify/colors

pattuzzoj9MIT1.0.1TypeScript support: included

A collection of utility functions for working with colors, including conversions between RGB, HEX, and HSL formats, as well as checks for color validity and type.

colors, isRgb, isHex, isHsl, rgbToHex, rgbToHsl, hexToHsl, hexToRgb, hslToHex, hslToRgb, utilify, utilities, utility functions, helper functions, JavaScript, TypeScript

readme

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:

`bash [npm] npm install @utilify/colors


```bash [yarn]
yarn add @utilify/colors

`bash [pnpm] 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.

```typescript [esm]
import { rgbToHsl, rgbToHex, isRgb } from '@utilify/colors';

`javascript [cjs] const { rgbToHsl, rgbToHex, isRgb } = require('@utilify/colors');


## Overview

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

### [rgbToHsl](./rgbToHsl.md)
```typescript
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.