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

colorpedia

v1.1.1

Published

Package useful to everything you want to do with colors.

Readme

Colorpedia

npm version CI License: MIT

Colorpedia is a comprehensive color manipulation and conversion library for JavaScript and Node.js. It provides utilities to convert between color formats, adjust brightness, generate lighter or darker shades.

Table of Contents

Installation

Install Colorpedia using npm or yarn:

npm install colorpedia
yarn add colorpedia

Features

  • Convert colors between HEX and RGB formats.
  • Generate lighter or darker shades of colors.
  • Invert colors and calculate lightness levels.
  • Comprehensive support for color manipulation.

Usage/Examples

1. Convert Functions

HEX and RGB

  • hexToRgb(hex: string): { r: number, g: number, b: number } | null
const { convert } = require("colorpedia");

const { r, g, b } = convert.hexToRgb("#6c34f2"); // { r: 108, g: 52, b: 242 }

Converts a hexadecimal color to an RGB object.

  • rgbToHex(r: number, g: number, b: number): string | null
const { convert } = require("colorpedia");

const hex = convert.rgbToHex(108, 52, 242); // "#6c34f2"

Converts an RGB color to a hexadecimal string.

HEX and HSL

  • hexToHsl(hex: string): { h: number, s: number, l: number } | null
const { convert } = require("colorpedia");

const { h, s, l } = convert.hexToHsl("#6c34f2"); // { h: 258, s: 88, l: 58 }

Converts a hexadecimal color to an HSL object (hue 0–360, saturation 0–100, lightness 0–100).

  • hslToHex(h: number, s: number, l: number): string | null
const { convert } = require("colorpedia");

const hex = convert.hslToHex(258, 88, 58); // "#6e36f2"

Converts an HSL color to a hexadecimal string.

HEX and RGBA

  • hexToRgba(hex: string): { r: number, g: number, b: number, a: number } | null
const { convert } = require("colorpedia");

const { r, g, b, a } = convert.hexToRgba("#6c34f280"); // { r: 108, g: 52, b: 242, a: 0.5 }

Converts an 8-digit HEX color (with alpha) to an RGBA object. Falls back to a: 1 for standard 6-digit HEX.

  • rgbaToHex(r: number, g: number, b: number, a?: number): string | null
const { convert } = require("colorpedia");

const hex = convert.rgbaToHex(108, 52, 242, 0.5); // "#6c34f280"

Converts RGBA values to an 8-digit HEX string. Alpha defaults to 1 if omitted.

RGB and HSL

  • rgbToHsl(r: number, g: number, b: number): { h: number, s: number, l: number } | null
const { convert } = require("colorpedia");

const { h, s, l } = convert.rgbToHsl(108, 52, 242); // { h: 258, s: 88, l: 58 }

Converts an RGB color to an HSL object.

  • hslToRgb(h: number, s: number, l: number): { r: number, g: number, b: number } | null
const { convert } = require("colorpedia");

const { r, g, b } = convert.hslToRgb(258, 88, 58); // { r: 110, g: 54, b: 242 }

Converts an HSL color to an RGB object.

RGB and RGBA

  • rgbaToRgb(r: number, g: number, b: number, a?: number): { r: number, g: number, b: number } | null
const { convert } = require("colorpedia");

const rgb = convert.rgbaToRgb(108, 52, 242, 0.5); // { r: 108, g: 52, b: 242 }

Strips the alpha channel from an RGBA color, returning a plain RGB object.

HSL and RGBA

  • rgbaToHsl(r: number, g: number, b: number, a?: number): { h: number, s: number, l: number } | null
const { convert } = require("colorpedia");

const hsl = convert.rgbaToHsl(108, 52, 242, 0.5); // { h: 258, s: 88, l: 58 }

Converts an RGBA color to HSL, ignoring the alpha channel.

  • hslToRgba(h: number, s: number, l: number, a?: number): { r: number, g: number, b: number, a: number } | null
const { convert } = require("colorpedia");

const rgba = convert.hslToRgba(258, 88, 58, 0.5); // { r: 110, g: 54, b: 242, a: 0.5 }

Converts an HSL color to RGBA. Alpha defaults to 1 if omitted.

2. Clearer (Lighten Color)

  • hex(hex: string, percentage: number): string | null
const { clearer } = require("colorpedia");

const lighterHex = clearer.hex("#6c34f2", 20); // "#823fff"

Generates a lighter shade of the given HEX color by a specified percentage.

  • rgb(r: number, g: number, b: number, percentage: number): { r: number, g: number, b: number } | null
const { clearer } = require("colorpedia");

const lighter = clearer.rgb(108, 52, 242, 20); // { r: 130, g: 63, b: 255 }

Generates a lighter shade of the given RGB color by a specified percentage.

  • hsl(h: number, s: number, l: number, percentage: number): { h: number, s: number, l: number } | null
const { clearer } = require("colorpedia");

const lighter = clearer.hsl(258, 88, 58, 20); // { h: 258, s: 88, l: 70 }

Increases the lightness channel of an HSL color by a specified percentage. More perceptually accurate than the RGB approach.

  • rgba(r: number, g: number, b: number, a: number, percentage: number): { r: number, g: number, b: number, a: number } | null
const { clearer } = require("colorpedia");

const lighter = clearer.rgba(108, 52, 242, 0.5, 20); // { r: 130, g: 63, b: 255, a: 0.5 }

Lightens an RGBA color by percentage (using the RGB channels), preserving the alpha value.

3. Darker (Darken Color)

  • hex(hex: string, percentage: number): string | null
const { darker } = require("colorpedia");

const darkerHex = darker.hex("#6c34f2", 20); // "#5629c1"

Generates a darker shade of the given HEX color by a specified percentage.

  • rgb(r: number, g: number, b: number, percentage: number): { r: number, g: number, b: number } | null
const { darker } = require("colorpedia");

const darkerRgb = darker.rgb(108, 52, 242, 20); // { r: 86, g: 41, b: 193 }

Generates a darker shade of the given RGB color by a specified percentage.

  • hsl(h: number, s: number, l: number, percentage: number): { h: number, s: number, l: number } | null
const { darker } = require("colorpedia");

const darker_hsl = darker.hsl(258, 88, 58, 20); // { h: 258, s: 88, l: 46 }

Decreases the lightness channel of an HSL color by a specified percentage. More perceptually accurate than the RGB approach.

  • rgba(r: number, g: number, b: number, a: number, percentage: number): { r: number, g: number, b: number, a: number } | null
const { darker } = require("colorpedia");

const darkerRgba = darker.rgba(108, 52, 242, 0.5, 20); // { r: 86, g: 41, b: 193, a: 0.5 }

Darkens an RGBA color by percentage (using the RGB channels), preserving the alpha value.

4. Invert Color

  • hex(hex: string): string | null
const { invert } = require("colorpedia");

const invertedHex = invert.hex("#6c34f2"); // "#93cb0d"

Inverts the color to its complementary shade.

  • rgb(r: number, g: number, b: number): { r: number, g: number, b: number } | null
const { invert } = require("colorpedia");

const invertedRgb = invert.rgb(108, 52, 242); // { r: 147, g: 203, b: 13 }

Inverts the RGB color values.

  • rgba(r: number, g: number, b: number, a: number): { r: number, g: number, b: number, a: number } | null
const { invert } = require("colorpedia");

const invertedRgba = invert.rgba(108, 52, 242, 0.5); // { r: 147, g: 203, b: 13, a: 0.5 }

Inverts the RGB channels, preserving the alpha value.

5. Lightness Calculation

  • hex(hex: string): number | null
const { lightness } = require("colorpedia");

const lightnessValue = lightness.hex("#6c34f2"); // 0.58

Calculates the lightness level of the color (0 = darkest, 1 = lightest).

  • rgb(r: number, g: number, b: number): number | null
const { lightness } = require("colorpedia");

const lightnessValue = lightness.rgb(108, 52, 242); // 0.58

Calculates the lightness level of an RGB color (0 = darkest, 1 = lightest).

6. Mix Colors

  • hex(hex1: string, hex2: string, weight?: number): string | null
const { mix } = require("colorpedia");

const mixed = mix.hex("#000000", "#ffffff");      // "#808080" (50/50)
const mixed = mix.hex("#ff0000", "#0000ff", 0.2); // 20% towards blue

Blends two HEX colors. weight (0–1) controls the balance towards the second color. Defaults to 0.5.

  • rgb(r1, g1, b1, r2, g2, b2, weight?: number): { r: number, g: number, b: number } | null
const { mix } = require("colorpedia");

const mixed = mix.rgb(255, 0, 0, 0, 0, 255, 0.5); // { r: 128, g: 0, b: 128 }

Blends two RGB colors. weight defaults to 0.5.

Contributing

We welcome contributions to Colorpedia! Here's how you can help:

  1. Fork the repository and make your changes.
  2. Open a pull request with a detailed description of your changes.

Support

If you encounter any issues or have questions, please open an issue on our GitHub issues page.