1.0.4 • Published 2 years ago

css-color-converter-class v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

css-color-converter-class

import { CssColor, fromString, fromHsla, fromRgba } from 'css-color-converter-class'

fromString(value)

Returns instance of CssColor if valid, null if invalid.

fromHsla(hue, saturation, lightness, alpha)

Returns instance of CssColor

fromRgba(red, green, blue, alpha)

Returns instance of CssColor

CssColor

Properties

static

non static

Accessors (Javascript, Typescript)

non static

accessibilitynametypegetsetdescription
publichexStringstring:heavy_check_mark::x:returns "hex" property and applies a "#" if it has non does the same as the method toHexString
publicsaturationStringstring:heavy_check_mark::x:returns "saturation" property as string with "%" at the end
publiclightnessStringstring:heavy_check_mark::x:returns "lightness" property as string with "%" at the end
publicrgbStringstring:heavy_check_mark::x:returns a rgb string 'rgb(100,100,100)' does the same as the method toRgbString
publicrgbaStringstring:heavy_check_mark::x:returns a rgba string 'rgba(100,100,100, 1)' does the same as the method toRgbaString
publichslStringstring:heavy_check_mark::x:returns a hsl string 'hsl(0,50%,100%)' does the same as the method toHslString
publichslaStringstring:heavy_check_mark::x:returns a hsla string 'hsla(0,50%,100%, 1)' does the same as the method toHslaString

Methods

static

accessibilitynameparameterreturnsdescription
publicgetInstanceFromStringvalue: stringinstance of CssColor if valid else nulldoes the same as fromString Supports named colors (only client side), hex, rgb/rgba, hsl/hsla

non static

accessibilitynameparameterreturnsdescription
publicconstructorrgb?: Partial\<RGB> | nullhsl?: Partial\<HSL> | nullalpha = 1hex = ''htmlColorName = ''instance of CssColor/
publicsetHtmlColorNamevalue: stringvoidsets htmlColorName to the new value and re-calculates "hsl-values", "rgb-values" and "alpha" (if valid string)
publicfromHtmlColorName/voidre-calculates "hsl-values", "rgb-values" and "alpha" based on htmlColorName
publicsetHexvalue: stringvoidsets hex to the new value (if it matches hexRegExp) and re-calculates "hsl-values", "rgb-values" and "alpha"
publicfromHex/voidre-calculates "hsl-values", "rgb-values" and "alpha" based on hex
publicsetRedvalue: numbervoidsets red to the new value and re-calculates "hsl-values" and "hex"
publicsetGreenvalue: numbervoidsets green to the new value and re-calculates "hsl-values" and "hex"
publicsetBluevalue: numbervoidsets blue to the new value and re-calculates "hsl-values" and "hex"
publicsetRgbrgb: Partial\<RGB>voidsets the new RGB values and re-calculates "hsl-values" and "hex"
publicsetRgbargba: Partial\<RGBA>voidsets the new RGBA values and re-calculates "hsl-values" and "hex"
publicfromRgb/voidre-calculates "hsl-values" and "hex" based on "rgb-values" and "alpha"
publicfromRgba/voidre-calculates "hsl-values" and "hex" based on "rgb-values" and "alpha"
publicsetHuevalue: numbervoidsets hue to the new value and re-calculates "rgb-values" and "hex"
publicsetSaturationvalue: numbervoidsets saturation to the new value and re-calculates "rgb-values" and "hex"
publicsetLightnessvalue: numbervoidsets lightness to the new value and re-calculates "rgb-values" and "hex"
publicsetHslhsl: Partial\<HSL>voidsets the new HSL values and re-calculates "rgb-values" and "hex"
publicsetHslahsla: Partial\<HSLA>voidsets the new RGBA values and re-calculates "hsl-values" and "hex"
publicfromHsl/voidre-calculates "rgb-values" and "hex" based on "hsl-values" and "alpha"
publicfromHsla/voidre-calculates "rgb-values" and "hex" based on "hsl-values" and "alpha"
publicsetAlphavalue: numbervoidsets alpha to the new value an re-calculates "hex"
publicgetRgb/Required\<RGB>/
publicgetRgba/Required\<RGBA>/
publicgetHsl/Required\<HSL>/
publicgetHsla/Required\<HSLA>/
publictoRgbString/stringdoes the same as accessor rbgString
publictoRgbaString/stringdoes the same as accessor rbgaString
publictoHslString/stringdoes the same as accessor hslString
publictoHslaString/stringdoes the same as accessor hslaString
publicgetStrings/Array\<string> this.rgbString, this.rgbaString, this.hslString, this.hslaString, this.hexString, this.htmlColorName

Helper Classes

class RGB {
  red = 0
  green = 0
  blue = 0
}

class RGBA extends RGB {
  alpha = 1
}

class HSL {
  hue = 0
  saturation = 50
  lightness = 100
}

class HSLA extends HSL {
  alpha = 1
}
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago