Utils
cdf.dashboard. Utils
Static
A collection of utility functions.
AMD Module
require(["cdf/dashboard/Utils"], function(Utils) { /* code goes here */ });
**Source:**dashboard/Utils.js, line 24
Methods
Utils.addArgs(url)Deprecated
Adds the URL parameters to a local object.
Utils.clone(obj) : object
Deprecated
Deep clones an object.
Utils.configLanguage(langCode, config)
Configure a language.
Utils.dateFormat(date, mask, langCode) : string
Formats a date.
Utils.dateParse(date, mask) : Date
Parses a date with a given mask.
Utils.doCsvQuoting(value, separator, alwaysEscape) : string
Quote CSV values in a way that is compatible with CSVTokenizer.
Utils.eachValuesArray(values, opts, f, x) : boolean
Traverses each value, label, and id triple of a values array.
Utils.equalValues(a, b) : boolean
Determines if two values are considered equal.
Utils.escapeHtml(input) : string
Escapes a string as an HTML safe string.
Utils.ev(o) : object
Evaluates the argument.
Utils.getArgValue(key) : object
| undefined
Deprecated
Gets an argument value that was previously set by calling addArgs
.
Utils.getLocationSearchString() : string
Returns the query string part of the URL.
Utils.getPathParameter(url) : string
| undefined
Gets the path from the URL.
Utils.getQueryParameter(parameterName) : string
Returns the value of a query string parameter.
Utils.getURLParameters(sURL) : Array.<
Array.<String
>>
Gets the parameters from a URL.
Utils.hsvToRgb(h, s, v) : string
Converts an HSV to an RGB color value.
Utils.isArray(value) : boolean
Determines if a value is considered an array.
Utils.isFunction(value) : boolean
Determines if a value is considered a function.
Utils.isNumber(value) : boolean
Determines if a value is considered a number.
Utils.isString(value) : boolean
Determines if a value is considered a string.
Utils.normalizeValue(value) : object
Normalizes a value.
Utils.numberFormat(value, mask, langCode) : string
Formats a number.
Utils.objectToPropertiesArray(obj) : Array.<
Array.<Object
>>
| undefined
Converts an object to an array.
Utils.parseMultipleValues(value) : array
| object
Given a parameter value obtains an equivalent values array.
Utils.post(url, obj)
Performs a post to the server.
Utils.propertiesArrayToObject(pArray) : object
| undefined
Converts an array to an object.
Utils.sanitizeHtml(html) : string
Sanitizes input HTML.
Methods Details
Utils.addArgs(url)Deprecated
Adds the URL parameters to a local args
object.
**Source:**dashboard/Utils.js, line 469
url : string
The URL from which to extract the parameters.
Name
Default Value
Summary
url : string
The URL from which to extract the parameters.
Utils.clone(obj) : object
Deprecated
Deep clones an object. This method is deprecated, use jQuery.extend.
**Source:**dashboard/Utils.js, line 431
obj : object
The object to clone.
object
The cloned object.
Name
Default Value
Summary
obj : object
The object to clone.
Name
Description
object
The cloned object.
Utils.configLanguage(langCode, config)
Configure a new or existing language by specifying the language code and a configuration object.
**Source:**dashboard/Utils.js, line 179
Name
Default Value
Summary
langCode : string
Language code to be used.
config : object
Object with the language configuration.
number : object
Number format language configuration.
dateLocale : object
Date format language configuration.
Name
Default Value
Summary
number : object
Number format language configuration.
dateLocale : object
Date format language configuration.
Name
Default Value
Summary
langCode : string
Language code to be used.
config : object
Object with the language configuration.
number : object
Number format language configuration.
dateLocale : object
Date format language configuration.
Name
Default Value
Summary
number : object
Number format language configuration.
dateLocale : object
Date format language configuration.
Utils.dateFormat(date, mask, langCode) : string
Formats a date with a given mask using the dashboard language, the one that the user specified if it exists, or the default language 'en-US'.
**Source:**dashboard/Utils.js, line 201
date : Date
Date object to be formatted.
mask : string
Mask with format for the date.
langCode : string
Language to use in format.
string
The formatted date.
Name
Default Value
Summary
date : Date
Date object to be formatted.
mask : string
Mask with format for the date.
langCode : string
Language to use in format.
Name
Description
string
The formatted date.
Utils.dateParse(date, mask) : Date
Parses a date with a given mask.
**Source:**dashboard/Utils.js, line 229
date : string
The date to be parsed.
mask : string
The mask with the format for the date.
Date
The parsed date as a Date object.
Name
Default Value
Summary
date : string
The date to be parsed.
mask : string
The mask with the format for the date.
Name
Description
Date
The parsed date as a Date object.
Utils.doCsvQuoting(value, separator, alwaysEscape) : string
Quote CSV values in a way that is compatible with CSVTokenizer.
**Source:**dashboard/Utils.js, line 363
value : string
Value quote.
separator : string
Separator to use when quoting.
alwaysEscape : boolean
Flag that indicates if the value should always be escaped or just when needed.
string
| null
The escaped value or null
.
Name
Default Value
Summary
value : string
Value quote.
separator : string
Separator to use when quoting.
alwaysEscape : boolean
Flag that indicates if the value should always be escaped or just when needed.
Name
Description
string
| null
The escaped value or null
.
Utils.eachValuesArray(values, opts, f, x) : boolean
Traverses each value, label and id triple of a values array.
**Source:**dashboard/Utils.js, line 535
Name
Default Value
Summary
values : Array.<
Array.<string
>>
The values array - an array of arrays.
Each second-level array is a value specification and contains a value and, optionally, a label and an id. It may have the following forms:
[valueAndLabel]
: when having length one[value, label,...]
: when having length two or more andopts.valueAsId
is falsy[id, valueAndLabel,..]
: when having length two or more andopts.valueAsId
is truthy
opts : object
An object with options.
valueAsId : boolean
Optional
false
Indicates if the first element of the value specification array is the id, instead of the value.
Name
Default Value
Summary
valueAsId : boolean
Optional
false
Indicates if the first element of the value specification array is the id, instead of the value.
f : function
The traversal function that is to be called with each value-label-id triple and with the JS context x
. The function is called with arguments: value
, label
, id
, and index
.
When the function returns the value false
, traversal is stopped, and false
is returned.
x : object
The JS context object on which f
is to be called.
|Name|Description| |----|-----------| |`boolean`|`true` if the traversal was complete, `false` if explicitly stopped by the traversal function.|
Name
Default Value
Summary
values : Array.<
Array.<string
>>
The values array - an array of arrays.
Each second-level array is a value specification and contains a value and, optionally, a label and an id. It may have the following forms:
[valueAndLabel]
: when having length one[value, label,...]
: when having length two or more andopts.valueAsId
is falsy[id, valueAndLabel,..]
: when having length two or more andopts.valueAsId
is truthy
opts : object
An object with options.
valueAsId : boolean
Optional
false
Indicates if the first element of the value specification array is the id, instead of the value.
Name
Default Value
Summary
valueAsId : boolean
Optional
false
Indicates if the first element of the value specification array is the id, instead of the value.
f : function
The traversal function that is to be called with each value-label-id triple and with the JS context x
. The function is called with arguments: value
, label
, id
, and index
.
When the function returns the value false
, traversal is stopped, and false
is returned.
x : object
The JS context object on which f
is to be called.
Utils.equalValues(a, b) : boolean
Determines if two values are considered equal.
**Source:**dashboard/Utils.js, line 677
a : object
The first value.
b : object
The second value.
boolean
true
if equal, false
otherwise.
Name
Default Value
Summary
a : object
The first value.
b : object
The second value.
Name
Description
boolean
true
if equal, false
otherwise.
Utils.escapeHtml(input) : string
Escapes a string as an HTML safe string. It assumes that, if there is an escaped char in the input, then the input is fully escaped.
**Source:**dashboard/Utils.js, line 62
input : string
The string to be escaped.
string
The escaped string or an empty string if it receives anything other than a string.
Name
Default Value
Summary
input : string
The string to be escaped.
Name
Description
string
The escaped string or an empty string if it receives anything other than a string.
Utils.ev(o) : object
Evaluates the argument. If it is a function, calls the function, otherwise returns the argument.
**Source:**dashboard/Utils.js, line 391
o : object
The object to try and evaluate as a function.
object
The value of o
if it isn't a function. Otherwise, the result of invoking o
.
Name
Default Value
Summary
o : object
The object to try and evaluate as a function.
Name
Description
object
The value of o
if it isn't a function. Otherwise, the result of invoking o
.
Utils.getArgValue(key) : object
| undefined
Deprecated
Gets an argument value that was previously set by calling addArgs
. This is deprecated, so use getQueryParameter
or dashboard.context.params
.
**Source:**dashboard/Utils.js, line 489
key : string
The argument name.
object
| undefined
The argument value or undefined
.
Name
Default Value
Summary
key : string
The argument name.
Name
Description
object
| undefined
The argument value or undefined
.
Utils.getLocationSearchString() : string
Returns the query string part of the URL.
**Source:**dashboard/Utils.js, line 121
string
The query string.
Name
Description
string
The query string.
Utils.getPathParameter(url) : string
| undefined
Given a URL containing an encoded Pentaho path, e.g. :home:admin:Test.wcdf
, returns the encoded path.
**Source:**dashboard/Utils.js, line 102
url : string
The URL to encode.
string
| undefined
The encoded URL or undefined
if not available.
Name
Default Value
Summary
url : string
The URL to encode.
Name
Description
string
| undefined
The encoded URL or undefined
if not available.
Utils.getQueryParameter(parameterName) : string
Returns the value of a query string parameter.
**Source:**dashboard/Utils.js, line 133
parameterName : string
The name of the parameter.
string
The value of the query parameter or an empty string.
Name
Default Value
Summary
parameterName : string
The name of the parameter.
Name
Description
string
The value of the query parameter or an empty string.
Utils.getURLParameters(sURL) : Array.<
Array.<String
>>
Gets the parameters from a URL. CDF URL parameters are defined as those that are present in the query string with names starting with the string param
. So, for a query string like ?paramfoo=bar
, you would get a parameter foo
with value bar
.
**Source:**dashboard/Utils.js, line 310
sURL : string
URL with the query string to be parsed.
Array.<
Array.<String
>>
Array with the parsed parameters. Each element is an array with two positions, the first being the parameter name and the second the value. For example, ``.
Name
Default Value
Summary
sURL : string
URL with the query string to be parsed.
Name
Description
Array.<
Array.<String
>>
Array with the parsed parameters. Each element is an array with two positions, the first being the parameter name and the second the value. For example, ``.
Utils.hsvToRgb(h, s, v) : string
Converts an HSV to an RGB color value. Based on the algorithm described at http://en.wikipedia.org/wiki/HSL_and_HSV.
**Source:**dashboard/Utils.js, line 706
h : number
Hue as a value between 0 - 360 (degrees).
s : number
Saturation as a value between 0 - 100 (%).
v : number
Value as a value between 0 - 100 (%).
string
A RGB color string (e.g. "rgb(1,2,3)").
Name
Default Value
Summary
h : number
Hue as a value between 0 - 360 (degrees).
s : number
Saturation as a value between 0 - 100 (%).
v : number
Value as a value between 0 - 100 (%).
Name
Description
string
A RGB color string (e.g. "rgb(1,2,3)").
Utils.isArray(value) : boolean
Determines if a value is considered an array.
Returns true
if value is an array, or an array-like object (object containing the methods join
and length
).
**Source:**dashboard/Utils.js, line 619
value : object
The value.
boolean
true
if it is an array or an array-like object, false
otherwise.
Name
Default Value
Summary
value : object
The value.
Name
Description
boolean
true
if it is an array or an array-like object, false
otherwise.
Utils.isFunction(value) : boolean
Determines if a value is considered a function.
**Source:**dashboard/Utils.js, line 635
value : any
The value to be tested.
boolean
true
if is a function; false
otherwise.
Name
Default Value
Summary
value : any
The value to be tested.
Name
Description
boolean
true
if is a function; false
otherwise.
Utils.isNumber(value) : boolean
Determines if a value is considered a number.
**Source:**dashboard/Utils.js, line 663
value : any
The value to be tested.
boolean
true
if is a string; false
otherwise.
Name
Default Value
Summary
value : any
The value to be tested.
Name
Description
boolean
true
if is a string; false
otherwise.
Utils.isString(value) : boolean
Determines if a value is considered a string.
**Source:**dashboard/Utils.js, line 649
value : any
The value to be tested.
boolean
true
if is a string; false
otherwise.
Name
Default Value
Summary
value : any
The value to be tested.
Name
Description
boolean
true
if is a string; false
otherwise.
Utils.normalizeValue(value) : object
Normalizes a value so that undefined
, empty string, and empty array are all translated to null
.
**Source:**dashboard/Utils.js, line 601
value : object
The value to normalize.
object
| null
The normalized value or null
.
Name
Default Value
Summary
value : object
The value to normalize.
Name
Description
object
| null
The normalized value or null
.
Utils.numberFormat(value, mask, langCode) : string
Formats a number with a given mask using the dashboard language, the one that the user specified if it exists, or the default language 'en-US'.
**Source:**dashboard/Utils.js, line 153
value : number
Number value to be formatted.
mask : string
Mask with format for the value.
langCode : string
Language to use in format.
string
The formatted number.
Name
Default Value
Summary
value : number
Number value to be formatted.
mask : string
Mask with format for the value.
langCode : string
Language to use in format.
Name
Description
string
The formatted number.
Utils.objectToPropertiesArray(obj) : Array.<
Array.<Object
>>
| undefined
Converts an object to an array.
**Source:**dashboard/Utils.js, line 293
obj : object
The object to be converted into an array.
Array.<
Array.<Object
>>
| undefined
An array of key-value pairs (array) or undefined
if the argument is not an object, e. g., ``.
Name
Default Value
Summary
obj : object
The object to be converted into an array.
Name
Description
Array.<
Array.<Object
>>
| undefined
An array of key-value pairs (array) or undefined
if the argument is not an object, e. g., ``.
Utils.parseMultipleValues(value) : array
| object
Given a parameter value obtains an equivalent values array.
The parameter value may encode multiple values in a string format.
A nully (i.e. null
or undefined
) input value or an empty string results in null
, so the result of this method is normalized.
A string value may contain multiple values separated by the character |
.
An array or array-like object is returned without modification.
Any other value type returns null
.
**Source:**dashboard/Utils.js, line 581
value : object
A parameter value, as returned by getParameterValue
.
array
| object
An array, an array-like object, or null
.
Name
Default Value
Summary
value : object
A parameter value, as returned by getParameterValue
.
Name
Description
array
| object
An array, an array-like object, or null
.
Utils.post(url, obj)
Performs a post to the server.
**Source:**dashboard/Utils.js, line 403
url : string
The URL where to post.
obj : object
Parameter object.
Name
Default Value
Summary
url : string
The URL where to post.
obj : object
Parameter object.
Utils.propertiesArrayToObject(pArray) : object
| undefined
Converts an array to an object.
**Source:**dashboard/Utils.js, line 278
pArray : Array.<
Array.<Object
>>
An array of key-value pairs (array) to be converted, e.g.,``.
object
| undefined
/p
Name
Default Value
Summary
pArray : Array.<
Array.<Object
>>
An array of key-value pairs (array) to be converted, e.g.,``.
Name
Description
object
| undefined
/p
Utils.sanitizeHtml(html) : string
Uses https://code.google.com/archive/p/google-caja/source. Strips unsafe tags and attributes from html.
**Source:**dashboard/Utils.js, line 86
html : string
The HTML to be sanitized.
string
safe HTML based on input.
Name
Default Value
Summary
html : string
The HTML to be sanitized.
Name
Description
string
safe HTML based on input.
Last updated
Was this helpful?