npm.io
1.0.0 • Published 3d ago

tiny-color-utils

Licence
MIT
Version
1.0.0
Deps
0
Size
19 kB
Vulns
0
Weekly
0

tiny-color-utils

A lightweight library for color conversions and manipulations.

Installation

npm install tiny-color-utils

Usage

import { hexToRgb, rgbToHex, lighten, darken, contrastRatio } from 'tiny-color-utils';

hexToRgb('#ff0000');           // { r: 255, g: 0, b: 0 }
rgbToHex(255, 0, 0);           // '#ff0000'
lighten('#333333', 20);        // lighter shade
darken('#cccccc', 20);         // darker shade
contrastRatio('#000', '#fff'); // 21

Available Functions

  • hexToRgb(hex) / rgbToHex(r, g, b) — Conversions
  • rgbToHsl(r, g, b) — RGB to HSL
  • lighten(hex, amount) / darken(hex, amount) — Adjust brightness
  • randomColor() — Generate random hex
  • isValidHex(hex) — Validate hex string
  • luminance(hex) — Relative luminance
  • contrastRatio(hex1, hex2) — WCAG contrast ratio
  • invert(hex) — Invert a color

Keywords