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 🙏

© 2025 – Pkg Stats / Ryan Hefner

kolory

v1.1.2

Published

A lightweight, versatile JavaScript library for manipulating and exploring colors in web projects, supporting conversions, palette generation, and dynamic effects.

Readme

Kolory

Paint your projects with vibrant Kolory

npm npm downloads bundlephobia jsDelivr

Overview

Kolory is a lightweight, versatile, and zero-dependency JavaScript library designed for seamless color manipulation and exploration. It supports multiple color formats (HEX, RGB, RGBA, HSL, HSLA) and provides built-in ANSI escape code support for styling terminal output. With a simple and intuitive API, Kolory empowers developers to work with colors effortlessly in both Node.js and browser environments.

Whether you're converting colors, generating dynamic palettes, or enhancing CLI output with vibrant formatting, Kolory is your go-to tool for all things color.

Features

  • Multiple Color Formats: Work with HEX, RGB, RGBA, HSL, and HSLA formats effortlessly.
  • Prebuilt Distributions: Available in ESM, CommonJS, and IIFE formats for maximum compatibility.
  • Zero Dependencies: Lightweight with a minimal footprint for optimal performance.
  • TypeScript Support: First-class TypeScript definitions for a type-safe development experience.
  • Cross-Platform: Compatible with Node.js, Deno, and modern browsers.
  • ANSI Styling: Built-in support for 4-bit, 8-bit, and 24-bit ANSI escape codes to style CLI output.

Installation

Kolory can be installed via all major package managers or used directly in the browser via a CDN.

Using Package Managers

# npm
npm install kolory

# yarn
yarn add kolory

# pnpm
pnpm add kolory

# bun
bun add kolory

Using CDN (Browser)

Include Kolory in your HTML for browser-based projects:

<!-- UNPKG -->
<script src="https://unpkg.com/kolory/dist/index.iife.js"></script>

<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/kolory/dist/index.iife.js"></script>

<!-- ESM (Modern Browsers) -->
<script type="module">
  import kolory from 'https://esm.sh/kolory';
</script>

Usage

Kolory provides a straightforward API to access and manipulate colors in various formats. Below are examples for different environments.

ESM (Modern JavaScript)

import kolory, { hex, rgb, rgba, hsl, hsla } from 'kolory';

console.log(kolory.hex.blue_metal);
console.log(hex.blue_metal);
console.log(rgb.blue_metal);

CommonJS

const { hex, rgb } = require('kolory');

console.log(hex.sunset_orange);
console.log(rgb.sunset_orange);

Browser (IIFE via CDN)

<script src="https://unpkg.com/kolory/dist/index.iife.js"></script>
<script>
  console.log(kolory.hex.blue_metal);
</script>

Color Data Structure

Kolory organizes colors in a structured JSON format, with each color entry providing values for all supported formats. Below is an example:

{
  "blue_metal": {
    "hex": "#4A90E2",
    "rgb": "74,144,226",
    "rgba": "74,144,226,1",
    "hsl": "210,73%,58%",
    "hsla": "210,73%,58%,1"
  }
}

API Reference

Kolory exports several modules to access colors in different formats:

| Export | Description | | -------- | ---------------------------------------------- | | kolory | Structured object containing all color formats | | hex | Colors in HEX format (e.g., #4A90E2) | | rgb | Colors in RGB format (e.g., 74,144,226) | | rgba | Colors in RGBA format (e.g., 74,144,226,1) | | hsl | Colors in HSL format (e.g., 210,73%,58%) | | hsla | Colors in HSLA format (e.g., 210,73%,58%,1) | | ansi | ANSI escape codes for CLI styling |

ANSI Escape Codes

Kolory includes robust support for ANSI escape codes, enabling vibrant and expressive CLI output. It supports 4-bit, 8-bit, and 24-bit color modes, with a chainable syntax for easy styling.

ANSI Features

  • Chainable Syntax: Combine styles fluently (e.g., ansi.red.bold.underline('Hello')).
  • Fully Typed: TypeScript support for all ANSI styles.
  • Comprehensive SGR Codes: Includes all Select Graphic Rendition (SGR) codes.
  • Cross-Platform: Works in Node.js, Deno, and ANSI-compatible browser terminals.
  • Auto-Reset: Automatically appends \x1b[0m to reset styles after each print.
  • Raw Output: Use .apply(text) to retrieve styled strings without printing.

ANSI Usage

import { ansi } from 'kolory';

// Basic styling
ansi.bold('Bold text'); // Bold text
ansi.italic.underline('Stylish!'); // Italicized and underlined text
ansi.red.bgWhite.bold('Alert!'); // Red text on white background, bold
console.log(ansi.green.apply('Green text')); // Returns raw styled string

Supported ANSI Styles

| Category | Styles | | --------------- | ------------------------------------------------------------------------------------------------------------------------------ | | Text Styles | bold, dim, italic, underline, blink, inverse, hidden | | Foreground | black, red, green, yellow, blue, magenta, cyan, white | | Bright FG | gray, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite | | Background | bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite | | Bright BG | bgGray, bgBrightRed, bgBrightGreen, bgBrightYellow, bgBrightBlue, bgBrightMagenta, bgBrightCyan, bgBrightWhite | | Reset | .reset (or automatic after every print) |

ANSI Examples

ansi.inverse('Inverted'); // Inverted text
ansi.brightCyan('Bright Cyan Text'); // Bright cyan text
ansi.bgBrightMagenta.white.bold('Highlight this!'); // White bold text on bright magenta background

How ANSI Works

Kolory’s ANSI support uses dynamic proxy chaining to build escape sequences. Each chained property appends an ANSI code, and the final invocation wraps the text with the appropriate codes:

ansi.red.bold('Hello'); // Outputs: \u001b[31m\u001b[1mHello\u001b[0m

[!NOTE] Use .apply(text) to retrieve the raw styled string for further processing without printing to the console.

Contributing

We welcome contributions to make Kolory even better! To contribute:

  1. Add Colors: Add new color entries to kolory.json, following the structure defined in kolory.schema.json.
  2. Supported Formats: Ensure each color includes hex, rgb, rgba, hsl, and hsla values.
  3. Consistency: Maintain consistent naming and formatting across all entries.
  4. Code Quality: Run the formatter (prettier) and linter (eslint) before submitting a pull request.
  5. Submit a PR: Open a pull request with a clear description of your changes.

License

Kolory is licensed under the Apache License 2.0.