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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pigment-ts

v0.2.7

Published

🎨 A lightweight utility for color manipulation and conversion.

Downloads

149

Readme

🎨 PigmentTS

npm npm

A lightweight JavaScript/TypeScript utility for seamless color manipulation and conversion. Tailwind CSS support is built-in.

Visit the playground to try out the library.

Supported Formats - HEX, RGB, HSL, RGBA, HSLA, Tailwind CSS


✨ Features

  • Color Conversion: Convert colors between all the supported formats.
  • Brightness Control: Lighten or darken a color by a specified percentage.
  • Random Color Generation: Generate random colors in of the supported format.
  • Opacity Control: Set the opacity of color in any format.
  • Blend Colors: Blend two colors in any format together in a specified ratio.

More features coming soon!


🔮 What's New in v0.2

  • Support for HSLA and RGBA formats
  • New utility functions for opacity control and color blending
  • Optimized codebase for better performance and reduced bundle size

🚀 Getting Started

Installation: Install PigmentTS via npm

npm install pigment-ts

Usage

Import all the function you need

import { convertColor, lightenColor, toTailwind } from "pigment-ts";

// Convert HEX to RGB
const rgb = convertColor("#ff5733", "rgb");
console.log(rgb); // 'rgb(255, 87, 51)'

// Lighten a color by 20%
const lighter = lightenColor("#ff5733", 20);
console.log(lighter); // '#FF8A66'

// Get Tailwind CSS class
const twClass = toTailwind("#ef4343");
console.log(twClass); // 'red-500'

Use all functions via default import

import PigmentTS from "pigment-ts";

const randomHex = PigmentTS.randomColor("hex");
console.log(randomHex); // '#A1B2C3'

📚 API Reference

convertColor

Converts a color from one format to another.

convertColor(color: string, format: "hex" | "rgb" | "hsl" | "tw" | "rgba" | "hsla", prefix?: string): string
convertColor("#ff5733", "rgb"); // 'rgb(255, 87, 51)'
convertColor("rgb(255, 87, 51)", "hex"); // '#FF5733'
convertColor("#7f1d1d", "tw"); // 'red-900'
convertColor("#7f1d1d", "tw", "bg"); // 'bg-red-900'

lightenColor

Lightens a color by a specified percentage.

lightenColor(color: string, percent: number): string
lightenColor("#ff5733", 20); // '#FF8A66'

darkenColor

Darkens a color by a specified percentage.

darkenColor(color: string, percent: number): string
darkenColor("#ff5733", 20); // '#CC2400'

randomColor

Generates a random color in the specified format.

randomColor(format: "hex" | "rgb" | "hsl" | "tw" | "rgba" | "hsla", prefix?: string): string
randomColor("hex"); // '#A1B2C3'
randomColor("rgb"); // 'rgb(161, 178, 195)'
randomColor("hsl"); // 'hsl(210, 26%, 70%)'
randomColor("tw", "bg"); // 'bg-blue-300'

toTailwind

Converts a color to a Tailwind CSS class.

toTailwind(color: string, prefix?: string): string
toTailwind("#ef4343"); // 'red-500'
toTailwind("#ef4343", "border"); // 'border-red-500'

setOpacity

Sets the opacity of a color in any format.

setOpacity(color: string, amount: number, to: "rgba" | "hsla"): string
setOpacity("#ff5733", 0.5, "rgba"); // 'rgba(255, 88, 51, 0.5)'
setOpacity("rgb(200, 100, 150)", 0.3, "hsla"); // hsla(330, 48%, 59%, 0.3)

blendColors

Blends two colors together to create a new color.

blendColors(color1: string, color2: string, ratio: number): string
blendColors("#ff5733", "#333333", 0.5); // '#994533'
blendColors("rgb(255, 87, 51)", "hsl(101, 100%, 60%)", 0.2); // 'rgb(227, 121, 51)'

Note: It returns the color in the format of the first color provided. The prefix for Tailwind color will be taken from the first color.


🗺 Roadmap

See the ROADMAP file for a list of features that are planned for future releases.


📝 License

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


🤝 Contribution

See the CONTRIBUTING file for more information on how to contribute to this project.


Support me by giving a ⭐ if you find this project useful!