1.0.3 • Published 7 months ago

ignix-colors v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Color Manipulation Package

A JavaScript package for manipulating colors in various formats, including hexadecimal, RGB, and HSL. This package provides a Color class that allows you to create, modify, and convert colors easily.

Installation

You can install this package using npm:

npm install ignix-colors

Usage

Import the Color class and any necessary functions from the package:

const Color = require("ignix-colors"); // Color Class
const {hsl, hsla, rgb, rgba} = require("ignix-colors"); // Formatter functions

Creating a Color

You can create a Color object by providing a color in various formats:

// Default Color is White
const color = new Color();
// Create a Color object from a hexadecimal color code
const color = new Color("#FF007F");
// Create a Color object from an RGB color object
const color = new Color({ r: 255, g: 0, b: 127 });
// Create a Color object from an HSL color object
const color = new Color({ h: 320, s: 50, l: 70 });
// Create a Color object from an HSL color
const color = new Color("hsl(350, 100%, 60%)");
// Create a Color object from an RGB color
const color = new Color("rgb(255, 50, 85)");

Manipulating Colors

You can manipulate colors using the following methods:

Darken a Color

const darkerColor = color.darken(10); // Darken the color by 10%

Lighten a Color

const lighterColor = color.lighten(20); // Lighten the color by 20%

Set Brightness

const adjustedColor = color.setBrightness(60); // Set the brightness to 60%

Adjust Hue

const hueAdjustedColor = color.adjustHue(30); // Adjust the hue by 30 degrees

Set Hue

const hueSetColor = color.setHue(180); // Set the hue to 180 degrees

Using Formatters

All the functions in the Color class return an object containing the rgb and hsl values of the given color. You can use the colors in object form, if your code supports it. But, in case, you need the color in rgb or hsl format, you can use the formatters.

Getting HSL color

const hslColor = hsl(color.setHue(180)) // returns the color in hsl(h, s%, l%) format

If you need a color with transparency, then use the 'a' channel

const hslColorTransparent = hsla(color.setHue(180), 0.5) // returns the color in hsla(h, s%, l%, a) format

Example

const { Color } = require("ignix-colors");

// Create a Color object
const color = new Color("#FF007F");

// Darken the color
const darkerColor = color.darken(10);

console.log("Original Color:", color);
console.log("Darker Color:", darkerColor);
1.0.3

7 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago