Final Class: ColorConverter

Oracle® JavaScript Extension Toolkit (JET)
17.1.0

G12196-01

Since:
  • 0.6.0
Module:
  • ojconverter-color

QuickNav

Description

An Color object format converter.


Usage

Signature:

final class ColorConverter implements Converter<oj.Color>

Typescript Import Format
//This class is exported directly as module. To import it
import ColorConverter= require("ojs/ojconverter-color");

For additional information visit:


Final classes in JET

Classes in JET are generally final and do not support subclassing. At the moment, final is not enforced. However, this will likely change in an upcoming JET release.


Constructor

new ColorConverter(options)

Creates a Converter that allows any color format to be obtained from an Color object.
Parameters:
Name Type Argument Description
options oj.ColorConverter.ConverterOptions <optional>
an object literal used to provide optional information to initialize the converter.

Methods

format(color) : {string|null}

Formats the color using the options provided into a string.
Parameters:
Name Type Description
color oj.Color the Color instance to be formatted to a color specification string
Throws:
a ConverterError if formatting fails, or the color option is invalid.
Type
Error
Returns:

the color value formatted to the color specification defined in the options.

Type
string | null

getHint : {string}

Returns a hint that describes the color converter format.
Returns:

The expected format of a converted color.

Type
string

getOptions : {oj.ColorConverter.ConverterOptions}

Returns the options called with converter initialization.
Returns:

an object of options.

Type
oj.ColorConverter.ConverterOptions

parse(value) : {oj.Color}

Parses a CSS3 color specification string and returns an oj.Color object.
(Note that the "format" option used to create the Converter is not used by this method, since the oj.Color object created is color agnostic.)
Parameters:
Name Type Description
value string The color specification string to parse.
Throws:
a ConverterError if parsing fails
Type
Error
Returns:

the parsed value as an Color object.

Type
oj.Color

resolvedOptions : {oj.ColorConverter.ConverterOptions}

Returns an object literal with properties reflecting the color formatting options computed based on the options parameter.
Returns:

An object literal containing the resolved values for the following options.

  • format: A string value with the format of the color specification. for formatting.

Type
oj.ColorConverter.ConverterOptions

Type Definitions

ConverterOptions

Properties:
Name Type Argument Description
format 'rgb' | 'hsl' | 'hsv' | 'hex' | 'hex3' <optional>
sets the format of the converted color specification. Allowed values are "rgb" (the default, if omitted), "hsl", "hsv" "hex", and "hex3". "hex" returns six hex digits ('#rrggbb'), and "hex3" returns three hex digits if possible ('#rgb') or six hex digits if the value cannot be converted to three.