colorly-lite
v1.0.1
Published
A lightweight, dependency-free Node.js library for color manipulation, conversion, and accessibility.
Maintainers
Readme
This file provides comprehensive documentation for the package.
colorly-lite 🎨
Effortless color manipulation for Node.js—lightweight, fast, and dependency-free.
📌 Features
✅ Convert between HEX, RGB, and HSL.
✅ Lighten, darken, saturate, and desaturate colors.
✅ Generate complementary and analogous colors.
✅ Check contrast ratios for accessibility.
✅ Zero dependencies—pure JavaScript, fast & efficient.
🚀 Installation
Install via npm, yarn, or pnpm:
npm install colorly-liteyarn add colorly-litepnpm add colorly-lite🔧 Usage
1️⃣ Import the module
const ColorlyLite = require("colorly-lite");2️⃣ Convert Colors
const color = new ColorlyLite("#ff5733");
console.log(color.color); // { r: 255, g: 87, b: 51 }
console.log(color.toHsl()); // { h: 11, s: 100, l: 60 }
console.log(color.toHex()); // "#ff5733"3️⃣ Manipulate Colors
console.log(color.lighten(20)); // "#ff9985"
console.log(color.darken(20)); // "#992d1a"
console.log(color.saturate(20));// "#ff401a"
console.log(color.desaturate(20));// "#c16857"4️⃣ Generate Color Schemes
console.log(color.getComplementary()); // "#33b3ff"
console.log(color.getAnalogous()); // ["#ff8533", "#ff5733", "#ff3333"]5️⃣ Check Contrast
const white = new ColorlyLite("#ffffff");
console.log(white.contrastWith("#000000")); // 21.0 (Max contrast)
console.log(white.contrastWith("#bbbbbb")); // Low contrast📖 API Reference
new ColorlyLite(color)
- Accepts a HEX (#RRGGBB or #RGB), RGB string ("rgb(255,87,51)"), or HSL string ("hsl(11,100%,60%)").
- Throws an error if the input is invalid.
Color Conversion Methods
toHex()→ Returns the color in HEX format.toRgb()→ Returns{ r, g, b }object.toHsl()→ Returns{ h, s, l }object.hslToHex(h, s, l)→ Converts HSL to HEX.
Color Manipulation Methods
lighten(percent)→ Lightens the color bypercent%.darken(percent)→ Darkens the color bypercent%.saturate(percent)→ Increases saturation.desaturate(percent)→ Decreases saturation.
Color Harmony Methods
getComplementary()→ Returns the complementary color.getAnalogous()→ Returns an array of analogous colors.
Contrast Methods
contrastWith(color)→ Returns contrast ratio between two colors.
🧪 Running Tests
Run the test suite using Jest:
npm test🛠 Contributing
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch - Commit changes:
git commit -m "Add new feature" - Push:
git push origin feature-branch - Open a Pull Request.
📜 License
MIT License © 2025 colorly-lite
Feel free to use, modify, and distribute this package. 🚀
Your colorly-lite package is now production-ready! 🎨🚀
