Skip to main content

Pentaho+ documentation has moved!

The new product documentation portal is here. Check it out now at docs.hitachivantara.com

 

Hitachi Vantara Lumada and Pentaho Documentation

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

Name Description
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

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

Parameters:
Name Default Value Summary
obj : object

The object to clone.

Returns:
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

Parameters:
Name Default Value Summary
langCode : string

Language code to be used.

config : object

Object with the language configuration.

Parameters:
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

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

Returns:
Name Description
string

The formatted date.

Utils.dateParse(date, mask) : Date

Parses a date with a given mask.

Source: dashboard/Utils.js, line 229

Parameters:
Name Default Value Summary
date : string

The date to be parsed.

mask : string

The mask with the format for the date.

Returns:
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

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

Returns:
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

Parameters:
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 and opts.valueAsId is falsy
  • [id, valueAndLabel,..]: when having length two or more and opts.valueAsId is truthy

opts : object

An object with options.

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

Returns:
Name Description
boolean

true if the traversal was complete, false if explicitly stopped by the traversal function.

Utils.equalValues(a, b) : boolean

Determines if two values are considered equal.

Source: dashboard/Utils.js, line 677

Parameters:
Name Default Value Summary
a : object

The first value.

b : object

The second value.

Returns:
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

Parameters:
Name Default Value Summary
input : string

The string to be escaped.

Returns:
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

Parameters:
Name Default Value Summary
o : object

The object to try and evaluate as a function.

Returns:
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

Parameters:
Name Default Value Summary
key : string

The argument name.

Returns:
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

Returns:
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

Parameters:
Name Default Value Summary
url : string

The URL to encode.

Returns:
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

Parameters:
Name Default Value Summary
parameterName : string

The name of the parameter.

Returns:
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

Parameters:
Name Default Value Summary
sURL : string

URL with the query string to be parsed.

Returns:
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

Parameters:
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 (%).

Returns:
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

Parameters:
Name Default Value Summary
value : object

The value.

Returns:
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

Parameters:
Name Default Value Summary
value : any

The value to be tested.

Returns:
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

Parameters:
Name Default Value Summary
value : any

The value to be tested.

Returns:
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

Parameters:
Name Default Value Summary
value : any

The value to be tested.

Returns:
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

Parameters:
Name Default Value Summary
value : object

The value to normalize.

Returns:
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

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

Returns:
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

Parameters:
Name Default Value Summary
obj : object

The object to be converted into an array.

Returns:
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

Parameters:
Name Default Value Summary
value : object

A parameter value, as returned by getParameterValue.

Returns:
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

Parameters:
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

Parameters:
Name Default Value Summary
pArray : Array.<Array.<Object>>

An array of key-value pairs (array) to be converted, e.g.,.

Returns:
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

Parameters:
Name Default Value Summary
html : string

The HTML to be sanitized.

Returns:
Name Description
string

safe HTML based on input.