Class: ColorConverter

Oracle® JavaScript Extension Toolkit (JET)
3.2.0

E87541-01

QuickNav

oj. ColorConverter extends oj.Converter

Version:
  • 3.2.0
Since:
  • 0.6
An oj.Color object format converter.

Constructor

new ColorConverter()

Creates a Converter that allows any color format to be obtained from an oj.Color object.
Properties:
Name Type Argument Description
options Object <optional>
an object literal used to provide optional information to initialize the converter.
Properties
Name Type Argument Description
format string <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.
Source:
Example

Create a color converter to convert an rgb specification to hsl format

var cvFactory = oj.Validation.converterFactory(oj.ConverterFactory.CONVERTER_TYPE_COLOR);
var cv        = cv.createConverter({format: "hsl");
var color     = new oj.Color("rgb(30, 87, 236)") ;
var hsl       = cv.format(color);   -->  "hsl(223, 84%, 52%)"

Methods

format(color) → {string|null}

Formats the color using the options provided into a string.
Parameters:
Name Type Description
color oj.Color the oj.Color instance to be formatted to a color specification string
Source:
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.
Source:
Returns:
The expected format of a converted color.
Type
string

getOptions() → {Object}

Returns the options called with converter initialization.
Inherited From:
Source:
Returns:
an object of options.
Type
Object

Init(options)

Initializes the color converter instance with the set options.
Parameters:
Name Type Argument Description
options Object <optional>
an object literal used to provide an optional information to initialize the converter.

Source:

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.
Source:
Throws:
a ConverterError if parsing fails
Type
Error
Returns:
the parsed value as an oj.Color object.
Type
oj.Color

resolvedOptions() → {Object}

Returns an object literal with properties reflecting the color formatting options computed based on the options parameter.
Source:
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
Object