@colormate/core
v0.5.1-beta-1
Published
A modular and efficient color management library for JavaScript and TypeScript applications.
Downloads
188
Maintainers
Readme
@colormate/core
A modular and efficient color utility library for TypeScript and JavaScript applications@colormate/core
provides fast and flexible color conversions, validation, adjustments, and color generation utilities, with an optimized, memoized architecture to boost performance.
Table of Contents
Installation
To get started with @colormate/core
, simply install it via npm:
npm install @colormate/core
Features
- Color Conversions: Convert between HEX, RGB, HSL, and CMYK formats.
- Color Validation: Validate HEX, RGB, HSL, and CMYK formats.
- Brightness Adjustments: Adjust the brightness of RGB colors by a given percentage.
- Complementary Color Generation: Generate complementary colors from HEX input.
- Memoization: Optimized conversion classes with built-in caching to prevent redundant calculations.
- Modular Structure: Organized for scalability and ease of maintenance.
Getting Started
Examples
1. Color Conversions
Convert between color formats, such as HEX to RGB, RGB to HSL, etc.
import { HexToRgb, RgbToHex, RgbToHsl, RgbToCmyk, CmykToRgb } from "@colormate/core";
// Convert HEX to RGB
const rgbColor = HexToRgb.convertHexToRgb("#FF5733"); // { r: 255, g: 87, b: 51 }
// Convert RGB to HEX
const hexColor = RgbToHex.convertRgbToHex({ r: 255, g: 87, b: 51 }); // #FF5733
2. Color Validation
Validate different color formats to ensure they follow proper specifications.
import { ColorValidator } from "@colormate/core";
const isValidHex = ColorValidator.isValidHex("#FF5733"); // true
const isValidRgb = ColorValidator.isValidRgb({ r: 255, g: 87, b: 51 }); // true
3. Brightness Adjustments
Adjust brightness by a percentage for RGB colors.
import { BrightnessAdjuster } from "@colormate/core";
const brighterColor = BrightnessAdjuster.adjust({ r: 100, g: 100, b: 100 }, 20); // Increase brightness by 20%
4. Complementary Color Generation
Generate the complementary color for any given HEX color.
import { ColorComplementary } from "@colormate/core";
const complementaryColor = ColorComplementary.getComplementary("#FF5733"); // The complementary HEX color
API Reference
Color Converters
HexToRgb.convertHexToRgb(hex: string): Rgb
Convert HEX to RGB.- hex:
string
– HEX color value. - Returns:
Rgb
– Object withr
,g
, andb
properties.
- hex:
RgbToHex.convertRgbToHex(rgb: Rgb): string
Convert RGB to HEX.- rgb:
Rgb
– Object withr
,g
, andb
properties. - Returns:
string
– HEX color value.
- rgb:
Color Validation
ColorValidator.isValidHex(hex: string): boolean
Checks if a HEX color is valid.- hex:
string
– HEX color value. - Returns:
boolean
– True if valid, false otherwise.
- hex:
ColorValidator.isValidRgb(rgb: Rgb): boolean
Checks if an RGB color is valid.- rgb:
Rgb
– Object withr
,g
, andb
properties. - Returns:
boolean
– True if valid, false otherwise.
- rgb:
Brightness Adjustments
BrightnessAdjuster.adjust(rgb: Rgb, percent: number): Rgb
Adjusts brightness by a percentage.- rgb:
Rgb
– Object withr
,g
, andb
properties. - percent:
number
– Percentage by which to adjust brightness. - Returns:
Rgb
– Adjusted RGB color.
- rgb:
Complementary Colors
ColorComplementary.getComplementary(hex: string): string
Generates the complementary color for a given HEX value.- hex:
string
– HEX color value. - Returns:
string
– Complementary HEX color.
- hex:
Contributing
We welcome contributions to improve @colormate/core
! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or fix.
- Submit a pull request with a detailed description.
Ensure that your code follows existing conventions and includes tests for any new functionality.
License
This project is licensed under the MIT License. See the LICENSE file for more details.