@terron/colors

0.0.1-beta • Public • Published

Color Conversion Library

This library provides classes for converting colors between different formats such as RGB, HSL, and HEX.

Installation

You can install this library via npm:

npm install @terron/colors

Usage

// Import the classes
const { RGB, HEX, HSL } = require('@terron/colors');

// Create instances of color classes
const rgbColor = new RGB(255, 0, 0);
const hslColor = new HSL(0, 100, 50);
const hexColor = new HEX('#FF0000');

// Convert between color formats
const rgbToHsl = rgbColor.toHSL(); // [0, 100, 50]
const hslToRgb = hslColor.toRGB(); // [255, 0, 0]
const hexToRgb = hexColor.toRGB(); // [255, 0, 0]

Documentation

RGB Class

Represents a color in RGB format.

Constructor

Creates an instance of RGB.

new RGB(r, g, b);
  • r (number|Object|Array): The red component, or an object/array containing RGB values, or an array representing RGB values.
  • g (number): The green component.
  • b (number): The blue component.

Static Methods

  • isValid(r, g, b): Checks if provided RGB values are valid.

Instance Methods

  • toHEX(): Converts RGB values to hexadecimal format.
  • toHSL(): Converts RGB values to HSL format.
  • toRGB(): Retrieves the RGB values.

HSL Class

Represents a color in HSL format.

Constructor

Creates an instance of HSL.

new HSL(h, s, l);
  • h (number|Object|Array): The hue component, or an object/array containing HSL values, or an array representing HSL values.
  • s (number): The saturation component.
  • l (number): The lightness component.

Static Methods

  • isValid(h, s, l): Checks if provided HSL values are valid.

Instance Methods

  • toHEX(): Converts HSL values to hexadecimal format.
  • toRGB(): Converts HSL values to RGB format.
  • toHSL(): Retrieves the HSL values.

HEX Class

Represents a color in hexadecimal format.

Constructor

Creates an instance of HEX.

new HEX(hex);
  • hex (string): The hexadecimal color code.

Static Methods

  • isValid(hex): Checks if the provided hexadecimal color code is valid.

Instance Methods

  • toRGB(): Converts the hexadecimal color code to RGB format.
  • toHSL(): Converts the hexadecimal color code to HSL format.
  • toHEX(): Retrieves the hexadecimal color code.

Package Sidebar

Install

npm i @terron/colors

Weekly Downloads

0

Version

0.0.1-beta

License

ISC

Unpacked Size

11.2 kB

Total Files

6

Last publish

Collaborators

  • terron