Class: ColorConverter

Oracle® JavaScript Extension Toolkit (JET)
6.0.0

E94715-01

QuickNav

ColorConverter extends oj.Converter

Version:
  • 6.0.0
Since:
  • 0.6
Module:
  • ojvalidation-base
An oj.Color object format converter.

Constructor

new ColorConverter(options)

Creates a Converter that allows any color format to be obtained from an oj.Color object.
Parameters:
Name Type Argument Description
options oj.ColorConverter.ConverterOptions <optional>
an object literal used to provide optional information to initialize the converter.
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
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() → {Object}

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

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 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.
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

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.