UNPKG

@colormate/core

Version:

A modular and efficient color management library for JavaScript and TypeScript applications.

16 lines (15 loc) 503 B
// BrightnessAdjuster.ts import { ColorValidator } from '@validators/ColorValidator'; export class BrightnessAdjuster { static adjust(rgb, percent) { if (!ColorValidator.isValidRgb(rgb)) { throw new Error('Invalid RGB format'); } const adjustValue = (color) => Math.min(255, Math.max(0, color + (color * percent) / 100)); return { r: adjustValue(rgb.r), g: adjustValue(rgb.g), b: adjustValue(rgb.b), }; } }