@spa-tools/utilities
ColorObject
The ColorObject
class represents a single color and exposes conversion methods.
Usage
import { ColorObject } from '@spa-tools/utilities';
const color = new ColorObject('#ff0000');
console.log(color.toRgba());
// --> 'rgb(255, 0, 0, 1)'
console.log(color.toHsla());
// --> 'hsla(0, 100%, 50%, 1)'
color.blue = 255;
color.alpha = 0.5;
console.log(color.toHex());
// --> '#ff00ff'
console.log(color.toRgba());
// --> 'rgba(255, 0, 255, 0.5)'
Constructor
Name | Type | Required? | Default | Description |
---|---|---|---|---|
red | number | yes | 0 | Red color value |
green | number | yes | 0 | Green color value |
blue | number | yes | 0 | Blue color value |
alpha | number | no | 1 | Alpha color value |
Properties
Name | Type | Readonly? | Description |
---|---|---|---|
red | number | no | Red color value |
green | number | no | Green color value |
blue | number | no | Blue color value |
alpha | number | no | Alpha color value |
Methods
Name | Return type | Description |
---|---|---|
toHex | string | Returns the color in hexadecimal format |
toRgba | string | Returns the color in rgba format |
toHsla | string | Returns the color in hsla format |