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

@colormate/core

v0.5.1-beta-1

Published

A modular and efficient color management library for JavaScript and TypeScript applications.

Downloads

188

Readme

@colormate/core

npm version license issues

A modular and efficient color utility library for TypeScript and JavaScript applications
@colormate/core provides fast and flexible color conversions, validation, adjustments, and color generation utilities, with an optimized, memoized architecture to boost performance.


Table of Contents


Installation

To get started with @colormate/core, simply install it via npm:

npm install @colormate/core

Features

  • Color Conversions: Convert between HEX, RGB, HSL, and CMYK formats.
  • Color Validation: Validate HEX, RGB, HSL, and CMYK formats.
  • Brightness Adjustments: Adjust the brightness of RGB colors by a given percentage.
  • Complementary Color Generation: Generate complementary colors from HEX input.
  • Memoization: Optimized conversion classes with built-in caching to prevent redundant calculations.
  • Modular Structure: Organized for scalability and ease of maintenance.

Getting Started

Examples

1. Color Conversions

Convert between color formats, such as HEX to RGB, RGB to HSL, etc.

import { HexToRgb, RgbToHex, RgbToHsl, RgbToCmyk, CmykToRgb } from "@colormate/core";

// Convert HEX to RGB
const rgbColor = HexToRgb.convertHexToRgb("#FF5733"); // { r: 255, g: 87, b: 51 }

// Convert RGB to HEX
const hexColor = RgbToHex.convertRgbToHex({ r: 255, g: 87, b: 51 }); // #FF5733

2. Color Validation

Validate different color formats to ensure they follow proper specifications.

import { ColorValidator } from "@colormate/core";

const isValidHex = ColorValidator.isValidHex("#FF5733"); // true
const isValidRgb = ColorValidator.isValidRgb({ r: 255, g: 87, b: 51 }); // true

3. Brightness Adjustments

Adjust brightness by a percentage for RGB colors.

import { BrightnessAdjuster } from "@colormate/core";

const brighterColor = BrightnessAdjuster.adjust({ r: 100, g: 100, b: 100 }, 20); // Increase brightness by 20%

4. Complementary Color Generation

Generate the complementary color for any given HEX color.

import { ColorComplementary } from "@colormate/core";

const complementaryColor = ColorComplementary.getComplementary("#FF5733"); // The complementary HEX color

API Reference

Color Converters

  • HexToRgb.convertHexToRgb(hex: string): Rgb
    Convert HEX to RGB.

    • hex: string – HEX color value.
    • Returns: Rgb – Object with r, g, and b properties.
  • RgbToHex.convertRgbToHex(rgb: Rgb): string
    Convert RGB to HEX.

    • rgb: Rgb – Object with r, g, and b properties.
    • Returns: string – HEX color value.

Color Validation

  • ColorValidator.isValidHex(hex: string): boolean
    Checks if a HEX color is valid.

    • hex: string – HEX color value.
    • Returns: boolean – True if valid, false otherwise.
  • ColorValidator.isValidRgb(rgb: Rgb): boolean
    Checks if an RGB color is valid.

    • rgb: Rgb – Object with r, g, and b properties.
    • Returns: boolean – True if valid, false otherwise.

Brightness Adjustments

  • BrightnessAdjuster.adjust(rgb: Rgb, percent: number): Rgb
    Adjusts brightness by a percentage.

    • rgb: Rgb – Object with r, g, and b properties.
    • percent: number – Percentage by which to adjust brightness.
    • Returns: Rgb – Adjusted RGB color.

Complementary Colors

  • ColorComplementary.getComplementary(hex: string): string
    Generates the complementary color for a given HEX value.

    • hex: string – HEX color value.
    • Returns: string – Complementary HEX color.

Contributing

We welcome contributions to improve @colormate/core! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or fix.
  3. Submit a pull request with a detailed description.

Ensure that your code follows existing conventions and includes tests for any new functionality.


License

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