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

@mirawision/colorize

v1.4.1

Published

A comprehensive color manipulation library for TypeScript, providing functionalities for color conversion, validation, gradient generation, and various color adjustments.

Downloads

90

Readme

@mirawision/colorize

A comprehensive color manipulation library for TypeScript, @mirawision/colorize offers a wide range of functionalities for working with colors. Easily convert between color formats, validate color strings, generate color gradients, blend colors, and perform various adjustments like brightness, saturation, inversion, and more.

Demo and advanced Documentation can be found here!

Features

Validation & Detection

  • Color Validation: Check if color strings are valid for different formats, ensuring color data integrity.
  • Format Detection: Identify the format of a given color string, providing insights into color data and enhancing format compatibility.

Conversion

  • Color Conversion: Convert colors between different formats, supporting a wide range of color models.
  • Opacity Extraction: Extract the opacity value from a color, useful for understanding and manipulating alpha channels.
  • Color Number Parsing: Parse color components into numeric values, allowing for detailed color manipulations and analyses.

Gradient Generations

  • Stepped Gradient: Create stepped gradients between two colors, perfect for heatmaps and visual effects.
  • Advanced Multi-Stepped Gradient: Generate complex gradients with multiple colors and steps, offering detailed control over color transitions.

Manipulations

  • Brightness Adjustment: Increase or decrease the brightness of a color to fit your design needs.
  • Saturation Adjustment: Modify the saturation of a color, allowing for more vibrant or subdued variations.
  • Hue Adjustment: Change the hue of a color to any specified degree, enabling creative color transformations.
  • Opacity Change: Adjust the opacity of a color, useful for transparency effects and layering.
  • Color Inversion: Invert colors to create striking visual effects or highlight contrasts.
  • Tinting and Shading: Create tints by mixing colors with white and shades by mixing with black, ideal for theme generation and UI design.
  • Sepia Effect: Apply a sepia tone to give colors a warm, vintage feel.
  • Greyscale Application: Apply greyscale, maintaining luminance while removing hue and saturation.
  • Opposite Color: Calculate the complementary color by adjusting the hue by 180 degrees, useful for design contrast and harmony.
  • Random Color Generation: Generate a random color in any specified format (HEX, HEXA, RGB, RGBA, HSL, HSLA, HSV, CMYK).

Analysis

  • Luminance Calculation: Get the luminance of a color, understanding its perceived brightness.
  • Color Lightness Detection: Determine if a color is considered light or dark, aiding in accessibility and readability decisions.
  • Contrast Calculation: Calculate the contrast ratio between two colors, essential for designing accessible and legible interfaces.
  • Color Similarity Calculation: Calculate the similarity percentage between two colors, useful for finding colors that are visually close.

Supported Color Formats:

  • RGB, RGBA
  • HSL, HSLA
  • HEX, HEXA
  • HSV
  • CMYK

Installation

npm install @mirawision/colorize

or

yarn add @mirawision/colorize

Usage

Here's a quick overview of how to use some of the core functionalities of @mirawision/colorize:

Basic Example with the Color Class

import { Color } from '@mirawision/colorize';

// Initialize a Color object with a HEX color
const myColor = new Color('#3498db');

console.log(myColor.get()); // Outputs: '#3498db'
console.log(myColor.rgb()); // Returns color in RGB format: 'rgb(52, 152, 219)'
console.log(myColor.hsl()); // Returns color in HSL format: 'hsl(204, 70%, 53%)'

// Apply some manipulations
console.log(myColor.applyBrightness(20)); // Brightens the color: '#60aef1'
console.log(myColor.applyInvert()); // Inverts the color: '#cb6734'
console.log(myColor.applyGrayscale()); // Applies grayscale effect: '#a1a1a1'

Convert Colors

import { convertColor } from '@mirawision/colorize/convert-color';

const rgb = convertColor('hsl(120, 100%, 50%)', 'rgb');
console.log(rgb); // Output: 'rgb(0, 255, 0)'

Validate HEX Color

import { isValidHEXColor } from '@mirawision/colorize/is-valid-color';

const isValid = isValidHEXColor('#ff0000');
console.log(isValid); // Output: true

Get Color Format

import { getColorFormat } from '@mirawision/colorize/get-color-format';

const format = getColorFormat('rgba(255, 0, 0, 0.5)');
console.log(format); // Output: 'rgba'

Generate Random Color

import { randomColor } from '@mirawision/colorize';

console.log(randomColor()); // Outputs: a random color in HEX format
console.log(randomColor('rgb')); // Outputs: a random color in RGB format
console.log(randomColor('hsl')); // Outputs: a random color in HSL format

Generate Gradient

import { generateSteppedGradient } from '@mirawision/colorize/generate-stepped-gradient';

const gradient = generateSteppedGradient('rgb(255, 0, 0)', 'rgb(0, 0, 255)', 3);
console.log(gradient); // Output: ['rgb(191, 0, 64)', 'rgb(128, 0, 128)', 'rgb(64, 0, 191)']

Adjust Brightness

import { adjustBrightness } from '@mirawision/colorize/adjust-brightness';

const brighter = adjustBrightness('hsl(120, 50%, 50%)', 10);
console.log(brighter); // Output: 'hsl(120, 50%, 60%)'

Contributing

Contributions are always welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License.