A modern, lightweight, and comprehensive color utility library for JavaScript/TypeScript.
- 🎯 Color Conversions - Convert between HEX, RGB, HSL, and named colors.
- 🔧 Color Manipulation - Adjust brightness, saturation, and more.
- 🔍 Color Validation - A set of functions to validate color formats.
- 📦 Tree Shakeable - Import only what you need for optimal bundle size.
- 🔒 Type Safe - Full TypeScript support with comprehensive type definitions.
- 🚀 Zero Dependencies - Lightweight and self-contained.
- 🌐 Cross Platform - Works in browsers and Node.js environments.
npm install colorupjsyarn add colorupjspnpm add colorupjsimport { hexToRgb, lighten, isDark } from 'colorupjs';
// Convert a hex color to RGB
const rgbColor = hexToRgb('#3498db'); // { r: 52, g: 152, b: 219 }
// Lighten a color
const lighterColor = lighten(rgbColor, 20); // { r: 123, g: 198, b: 248, a: 1 }
// Check if a color is dark
const isColorDark = isDark(rgbColor); // truehexToRgb(hex: string): { r: number; g: number; b: number }rgbToHex(r: number, g: number, b: number): stringhslToRgb(h: number, s: number, l: number): { r: number; g: number; b: number }rgbToHsl(r: number, g: number, b: number): { h: number; s: number; l: number }hexToHsl(hex: string): { h: number; s: number; l: number }nameToHex(name: string): stringHexToName(hex: string): string
isLight(color: RgbColor): booleanisDark(color: RgbColor): booleanadjustBrightness(color: RgbColor, amount: number): RgbColoradjustSaturation(color: RgbColor, amount: number): RgbColorlighten(color: RgbColor, amount: number): RgbColordarken(color: RgbColor, amount: number): RgbColorinvertColor(color: RgbColor): RgbColorgrayscale(color: RgbColor): RgbColor
isHexColor(value: unknown): value is HexColorisNamedColor(value: unknown): value is NamedColorisRgbColor(value: unknown): value is RgbColorisHslColor(value: unknown): value is HslColorisHsvColor(value: unknown): value is HsvColorisValidAlpha(value: unknown): value is numberisValidRgbComponent(value: unknown): value is numberisValidPercentage(value: unknown): value is numberisValidHue(value: unknown): value is numberdetectFormat(value: unknown): ColorFormat | nullvalidateColorInput(input: unknown): ValidationResult
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
- Color theory algorithms inspired by Adobe Color and Coolors.co
- WCAG guidelines implementation based on W3C specifications
- Blend mode calculations adapted from CSS Compositing specification
Made with ❤️ by Sandeep Guttula