Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ColorUtils

Color utilities with support for hex, RBG, arithmetic RBG, HSL, and integer colors

author

osbornb

Hierarchy

  • ColorUtils

Index

Methods

Static expandShorthandHex

  • expandShorthandHex(color: string): string
  • Expand the hex if it is in shorthand

    Parameters

    • color: string
             hex color

    Returns string

    expanded hex color or original value

Static expandShorthandHexSingle

  • expandShorthandHexSingle(color: string): string
  • Expand the hex single if it is in shorthand

    Parameters

    • color: string
             hex single color

    Returns string

    expanded hex color or original value

Static getAlpha

  • getAlpha(color: string | number): string | number
  • Get the alpha color from color integer or Get the hex alpha color from the hex string if it exists

    Parameters

    • color: string | number
             color integer or hex color

    Returns string | number

    alpha color or hex alpha color in format AA or null

Static getBlue

  • getBlue(color: string | number): string | number
  • Get the blue color from color integer or Get the hex blue color from the hex string

    Parameters

    • color: string | number
             color integer or hex color

    Returns string | number

    blue color or hex blue color in format BB

Static getGreen

  • getGreen(color: string | number): string | number
  • Get the green color from color integer or Get the hex green color from the hex string

    Parameters

    • color: string | number
             color integer or hex color

    Returns string | number

    green color or hex green color in format GG

Static getRed

  • getRed(color: string | number): string | number
  • Get the red color from color integer or Get the hex red color from the hex string

    Parameters

    • color: string | number
             color integer or hex color

    Returns string | number

    red color or hex red color in format RR

Static isValidArithmeticRGB

  • isValidArithmeticRGB(color: number): boolean
  • Check if the arithmetic RGB float color is valid, inclusively between 0.0 and 1.0

    Parameters

    • color: number
             decimal color

    Returns boolean

    true if valid

Static isValidHex

  • isValidHex(color: string | null): boolean
  • Check if the hex color value is valid

    Parameters

    • color: string | null
             hex color

    Returns boolean

    true if valid

Static isValidHexSingle

  • isValidHexSingle(color: string | null): boolean
  • Check if the hex single color value is valid

    Parameters

    • color: string | null
             hex single color

    Returns boolean

    true if valid

Static isValidHue

  • isValidHue(hue: number): boolean
  • Check if the HSL hue float value is valid, inclusively between 0.0 and 360.0

    Parameters

    • hue: number
             hue value

    Returns boolean

    true if valid

Static isValidLightness

  • isValidLightness(lightness: number): boolean
  • Check if the HSL lightness float value is valid, inclusively between 0.0 and 1.0

    Parameters

    • lightness: number
             lightness value

    Returns boolean

    true if valid

Static isValidRGB

  • isValidRGB(color: number): boolean
  • Check if the RBG integer color is valid, inclusively between 0 and 255

    Parameters

    • color: number
             decimal color

    Returns boolean

    true if valid

Static isValidSaturation

  • isValidSaturation(saturation: number): boolean
  • Check if the HSL saturation float value is valid, inclusively between 0.0 and 1.0

    Parameters

    • saturation: number
             saturation value

    Returns boolean

    true if valid

Static shorthandHex

  • shorthandHex(color: string): string
  • Shorthand the hex color if possible

    Parameters

    • color: string
             hex color

    Returns string

    shorthand hex color or original value

Static shorthandHexSingle

  • shorthandHexSingle(color: string): string
  • Shorthand the hex single color if possible

    Parameters

    • color: string
             hex single color

    Returns string

    shorthand hex color or original value

Static toArithmeticRGB

  • toArithmeticRGB(color: string | number): number
  • Convert the RGB integer to an arithmetic RBG float or Convert the hex single color to an arithmetic RBG float

    Parameters

    • color: string | number
             integer color inclusively between 0 and 255 or hex single color in format FF or F

    Returns number

    float color inclusively between 0.0 and 1.0

Static toArithmeticRGBFromHSL

  • toArithmeticRGBFromHSL(hue: number, saturation: number, lightness: number): number[]
  • Convert HSL (hue, saturation, and lightness) values to RGB arithmetic values

    Parameters

    • hue: number
             hue value inclusively between 0.0 and 360.0
    • saturation: number
             saturation inclusively between 0.0 and 1.0
    • lightness: number
             lightness inclusively between 0.0 and 1.0

    Returns number[]

    arithmetic RGB array where: 0 = red, 1 = green, 2 = blue

Static toColor

  • toColor(red: string | number, green: string | number, blue: string | number): string | number
  • Convert the RBG values to a color integer or hex color values to a hex color

    Parameters

    • red: string | number
             red integer color inclusively between 0 and 255 or red hex color in format RR or R
    • green: string | number
             green integer color inclusively between 0 and 255 or green hex color in format GG or G
    • blue: string | number
             blue integer color inclusively between 0 and 255 or blue hex color in format BB or B

    Returns string | number

    integer color or hex color in format #RRGGBB

Static toColorShorthand

  • toColorShorthand(red: string, green: string, blue: string): string
  • Convert the hex color values to a hex color, shorthanded when possible

    Parameters

    • red: string
             red hex color in format RR or R
    • green: string
             green hex color in format GG or G
    • blue: string
             blue hex color in format BB or B

    Returns string

    hex color in format #RGB or #RRGGBB

Static toColorShorthandWithAlpha

  • toColorShorthandWithAlpha(red: string, green: string, blue: string, alpha: string): string
  • Convert the hex color values to a hex color, shorthanded when possible

    Parameters

    • red: string
             red hex color in format RR or R
    • green: string
             green hex color in format GG or G
    • blue: string
             blue hex color in format BB or B
    • alpha: string
             alpha hex color in format AA or A, null to not include alpha

    Returns string

    hex color in format #ARGB, #RGB, #AARRGGBB, or #RRGGBB

Static toColorShorthandWithDefaultAlpha

  • toColorShorthandWithDefaultAlpha(red: string, green: string, blue: string): string
  • Convert the hex color values to a hex color including an opaque alpha value of FF or F, shorthanded when possible

    Parameters

    • red: string
             red hex color in format RR or R
    • green: string
             green hex color in format GG or G
    • blue: string
             blue hex color in format BB or B

    Returns string

    hex color in format #ARGB or #AARRGGBB

Static toColorWithAlpha

  • toColorWithAlpha(red: string | number, green: string | number, blue: string | number, alpha: string | number | null): string | number
  • Convert the RBGA values to a color integer or Convert the hex color values to a hex color

    Parameters

    • red: string | number
             red integer color inclusively between 0 and 255 or red hex color in format RR or R
    • green: string | number
             green integer color inclusively between 0 and 255 or  green hex color in format GG or G
    • blue: string | number
             blue integer color inclusively between 0 and 255 or blue hex color in format BB or B or alpha hex color in format AA or A, null to not include alpha
    • alpha: string | number | null
             alpha integer color inclusively between 0 and 255, -1 to not
             include alpha

    Returns string | number

    integer color or hex color in format #AARRGGBB or #RRGGBB

Static toColorWithDefaultAlpha

  • toColorWithDefaultAlpha(red: string | number, green: string | number, blue: string | number): string | number
  • Convert the RBG values to a color integer including an opaque alpha value of 255 or Convert the hex color values to a hex color including an opaque alpha value of FF

    Parameters

    • red: string | number
             red integer color inclusively between 0 and 255 or red hex color in format RR or R
    • green: string | number
             green integer color inclusively between 0 and 255 or green hex color in format GG or G
    • blue: string | number
             blue integer color inclusively between 0 and 255 or blue hex color in format BB or B

    Returns string | number

    integer color or hex color in format #AARRGGBB

Static toHSL

  • toHSL(red: number, green: number, blue: number): number[]
  • Convert red, green, and blue arithmetic values to HSL (hue, saturation, lightness) values

    Parameters

    • red: number
             red color inclusively between 0.0 and 1.0 or between 0 and 255
    • green: number
             green color inclusively between 0.0 and 1.0 or between 0 and 255
    • blue: number
             blue color inclusively between 0.0 and 1.0 or between 0 and 255

    Returns number[]

    HSL array where: 0 = hue, 1 = saturation, 2 = lightness

Static toHex

  • toHex(color: number): string
  • Convert the RGB integer to a hex single color

    Parameters

    • color: number
             integer color inclusively between 0 and 255 or float color inclusively between 0.0 and 1.0

    Returns string

    hex single color in format FF

Static toRGB

  • toRGB(color: string | number): number
  • Convert the arithmetic RGB float to a RBG integer or Convert the hex single color to a RBG integer

    Parameters

    • color: string | number
             float color inclusively between 0.0 and 1.0 or hex single color in format FF or F

    Returns number

    integer color inclusively between 0 and 255

Static toRGBFromHSL

  • toRGBFromHSL(hue: number, saturation: number, lightness: number): number[]
  • Convert HSL (hue, saturation, and lightness) values to RGB integer values

    Parameters

    • hue: number
             hue value inclusively between 0.0 and 360.0
    • saturation: number
             saturation inclusively between 0.0 and 1.0
    • lightness: number
             lightness inclusively between 0.0 and 1.0

    Returns number[]

    RGB integer array where: 0 = red, 1 = green, 2 = blue

Static validateArithmeticRGB

  • validateArithmeticRGB(color: number): void
  • Validate the arithmetic RGB float color is inclusively between 0.0 and 1.0

    Parameters

    • color: number
             decimal color

    Returns void

Static validateHex

  • validateHex(color: string): void
  • Validate the hex color value

    Parameters

    • color: string
             hex color

    Returns void

Static validateHexSingle

  • validateHexSingle(color: string): void
  • Validate the hex single color value

    Parameters

    • color: string
             hex single color

    Returns void

Static validateHue

  • validateHue(hue: number): void
  • Validate the HSL hue float value is inclusively between 0.0 and 360.0

    Parameters

    • hue: number
             hue value

    Returns void

Static validateLightness

  • validateLightness(lightness: number): void
  • Validate the HSL lightness float value is inclusively between 0.0 and 1.0

    Parameters

    • lightness: number
             lightness value

    Returns void

Static validateRGB

  • validateRGB(color: number): void
  • Validate the RBG integer color is inclusively between 0 and 255

    Parameters

    • color: number
             decimal color

    Returns void

Static validateSaturation

  • validateSaturation(saturation: number): void
  • Validate the HSL saturation float value is inclusively between 0.0 and 1.0

    Parameters

    • saturation: number
             saturation value

    Returns void

Generated using TypeDoc