npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rockstarpabitra/colorify

v2.0.0

Published

Tiny color converter: hex ↔ rgb ↔ hsl (with alpha), zero deps.

Readme


✨ Features

  • 🔁 Convert seamlessly between HEX ↔ RGB ↔ HSL
  • 🌈 Supports alpha transparency (RGBA / HSLA / HEXA)
  • ⚙️ Fully TypeScript-based and tree-shakeable
  • Zero dependencies — small and lightning-fast
  • 🧩 Modular architecture — built for extension (CMYK, LAB, etc.)
  • 📦 Works in Browser, Node.js, Deno, and modern bundlers

🆕 What’s New in v2.0.0

Version 2.0.0 marks a major refactor of the entire library for performance, scalability, and clarity.

  • 🚀 Completely Modular Codebase — split into models/, utils/, and types/
  • ⚙️ Improved precision & validation for all color conversions
  • 🧱 Better TypeScript exports and tree-shakable structure
  • 🧪 Refined unit tests with consistent precision rounding
  • 💡 Future-ready architecture for new color models (CMYK, LAB, HSV)
  • 🧠 Code rewritten for clarity, safety, and learning

📦 Installation

Using npm:

npm install @rockstarpabitra/colorify

Using yarn:

yarn add @rockstarpabitra/colorify

Using pnpm:

pnpm add @rockstarpabitra/colorify

🚀 Quick Start

✅ ESM Import

import { hexToRgb, rgbToHex, rgbToHsl, hslToRgb } from "@rockstarpabitra/colorify";

console.log(hexToRgb("#3498db"));
// → { r: 52, g: 152, b: 219 }

console.log(rgbToHex(255, 0, 0, 0.5));
// → "#ff000080"

console.log(rgbToHsl(255, 0, 0));
// → { h: 0, s: 100, l: 50 }

console.log(hslToRgb(120, 100, 50));
// → { r: 0, g: 255, b: 0 }

✅ CommonJS Require

const { hexToRgb, rgbToHex } = require("@rockstarpabitra/colorify");

console.log(hexToRgb("#00ff00"));
// → { r: 0, g: 255, b: 0 }

🧠 API Reference

🎨 hexToRgb(hex: string)

Converts a HEX color string to an RGB object.

| Input | Output Example | | ----------- | ---------------------------------- | | #3498db | { r: 52, g: 152, b: 219 } | | #ff000080 | { r: 255, g: 0, b: 0, a: 0.502 } |


🌈 rgbToHex(r: number, g: number, b: number, a?: number)

Converts RGB values to a HEX color string. Supports optional alpha (0 → 1).

| Input | Output | | ------------------ | ------------- | | (255, 0, 0) | "#ff0000" | | (255, 0, 0, 0.5) | "#ff000080" |


🔵 rgbToHsl(r: number, g: number, b: number, a?: number)

Converts RGB to HSL format.

| Input | Output | | ------------- | --------------------------- | | (255, 0, 0) | { h: 0, s: 100, l: 50 } | | (0, 255, 0) | { h: 120, s: 100, l: 50 } |


🟢 hslToRgb(h: number, s: number, l: number, a?: number)

Converts HSL values to RGB.

| Input | Output | | ---------------- | -------------------------- | | (240, 100, 50) | { r: 0, g: 0, b: 255 } | | (60, 100, 50) | { r: 255, g: 255, b: 0 } |


🟣 hexToHsl(hex: string)

Converts HEX directly to HSL.

| Input | Output | | --------- | ------------------------- | | #ff0000 | { h: 0, s: 100, l: 50 } |


🔴 hslToHex(h: number, s: number, l: number, a?: number)

Converts HSL directly to HEX.

| Input | Output | | -------------------- | ------------- | | (120, 100, 50) | "#00ff00" | | (60, 100, 50, 0.5) | "#ffff0080" |


⚙️ Notes

  • ✅ Supports short (#abc, #abcd) and long (#aabbcc, #aabbccdd) HEX formats
  • 🔢 Alpha values normalized between 0–1
  • 🎚 RGB uses 0–255, HSL uses 0–360° hue and 0–100% saturation/lightness
  • 🧮 All values automatically clamped and rounded

🧩 Example Use Case

import { hexToRgb, rgbToHsl, hslToHex } from "@rockstarpabitra/colorify";

// Lighten a color by 10%
function lighten(hex, percent = 10) {
  const hsl = rgbToHsl(...Object.values(hexToRgb(hex)));
  const lighter = { ...hsl, l: Math.min(hsl.l + percent, 100) };
  return hslToHex(lighter.h, lighter.s, lighter.l);
}

console.log(lighten("#e74c3c", 15)); 
// → "#ff7d6e"

🧪 Tests

All functions are unit-tested using Vitest.

Run tests locally:

npm test

🧱 Build Instructions

To build from source:

npm run build

Generated output:

dist/
 ├─ index.js       → ESM build
 ├─ index.cjs      → CommonJS build
 └─ index.d.ts     → Type definitions

✅ Summary Checklist — v2.0.0

| Status | Category | Description | |:------:|:----------|:-------------| | 🟢 | Version | Latest stable release — v2.0.0 | | 🟢 | Language | Written in TypeScript with full type definitions | | 🟢 | Architecture | Modular structure (models/, utils/, types/) | | 🟢 | Compatibility | Works with Browser, Node.js, and Deno | | 🟢 | Dependencies | Zero — 100% pure JavaScript | | 🟢 | Testing | Covered with Vitest unit tests | | 🟢 | Build System | Compiles via tsc and ships ESM + CJS builds | | 🟢 | Documentation | Complete README, LEARN.md, and DEVELOPERS_GUIDE.md | | 🟢 | License | Open Source under MIT License | | 🟢 | Performance | Optimized conversion logic & precision math | | 🟢 | Future-Ready | Designed for expansion — CMYK, LAB, HSV coming soon |

💡 Colorify.js v2.0.0 is clean, modular, and built for both developers and learners — blending math, code, and color in one elegant package.


🌍 Browser (CDN)

Use Colorify.js directly in the browser via jsDelivr:

<script type="module">
  import { hexToRgb } from "https://cdn.jsdelivr.net/npm/@rockstarpabitra/[email protected]/dist/index.js";
  console.log(hexToRgb("#ff00ff"));
</script>

🧩 Developer Resources

📘 Learn Colorify.js 💡 Developer’s Guide 🧾 Changelog


🧑‍💻 Author

Pabitra Banerjee 🧠 Full-Stack AI Engineer • Founder & CEO of MB WEBBER’S 💬 Passionate about technology, open source, and education. 🌐 sdepabitra.me


📜 License

This project is licensed under the MIT License. See the LICENSE file for details.