JSPM

@utilify/colors

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q5837F
  • License MIT

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.

Package Exports

  • @utilify/colors
  • @utilify/colors/dist/index.cjs
  • @utilify/colors/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@utilify/colors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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:

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.