Class: Utils

Utils()

General utilities

Constructor

new Utils()

Source:

Methods

(static) compareStringCaseInsensitive(a, b) → {integer}

Compares two strings case-insensitive, including natural ordering for numbers.
Parameters:
Name Type Description
a string
b string
Source:
Returns:
Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
Type
integer

(static) deepClone(x) → {*}

Deep clone for JSON-compatible data.
Parameters:
Name Type Description
x * The data to clone.
Source:
Returns:
- The cloned data.
Type
*

(static) equals(x, y) → {boolean}

Performs a deep comparison between two values to determine if they are equivalent.
Parameters:
Name Type Description
x * The value to compare.
y * The other value to compare.
Source:
Returns:
- Returns true if the values are equivalent, else false.
Type
boolean
Makes link lists from the openEO API more user-friendly. Supports: - Set a reasonable title, if not available. Make title more readable. - Sorting by title (see `sort` parameter) - Removing given relation types (`rel` property, see `ignoreRel` parameter)
Parameters:
Name Type Default Description
linkList array List of links
sort boolean true Enable/Disable sorting by title. Enabled (true) by default.
ignoreRel array A list of rel types to remove. By default, removes the self links (rel type = `self`).
Source:
Returns:
Type
array

(static) hasText(string) → {boolean}

Checks whether a variable is a string and contains at least one character.
Parameters:
Name Type Description
string * A variable to check.
Source:
Returns:
- `true` is the given variable is an string with length > 0, `false` otherwise.
Type
boolean

(static) isNumeric(n) → {boolean}

Checks whether a variable is numeric. Numeric is every string with numeric data or a number, excluding NaN and finite numbers.
Parameters:
Name Type Description
n * A variable to check.
Source:
Returns:
- `true` is the given variable is numeric, `false` otherwise.
Type
boolean

(static) isObject(obj) → {boolean}

Checks whether a variable is a real object or not. This is a more strict version of `typeof x === 'object'` as this example would also succeeds for arrays and `null`. This function only returns `true` for real objects and not for arrays, `null` or any other data types.
Parameters:
Name Type Description
obj * A variable to check.
Source:
Returns:
- `true` is the given variable is an object, `false` otherwise.
Type
boolean

(static) mapObject(obj, func) → {object}

Creates an array of values by running each property of `object` thru function. The function is invoked with three arguments: (value, key, object).
Parameters:
Name Type Description
obj object
func function
Source:
Returns:
Type
object

(static) mapObjectValues(obj, func) → {object}

Creates an object with the same keys as object and values generated by running each own enumerable string keyed property of object thru the function. The function is invoked with three arguments: (value, key, object).
Parameters:
Name Type Description
obj object
func function
Source:
Returns:
Type
object

(static) normalizeUrl(baseUrl, path) → {string}

Normalize a URL (mostly handling leading and trailing slashes).
Parameters:
Name Type Default Description
baseUrl string The URL to normalize
path string null An optional path to add to the URL
Source:
Returns:
Normalized URL.
Type
string

(static) omitFromObject(obj, toOmit) → {object}

This method creates an object composed of the own and inherited enumerable property paths of object that are not omitted. Returns a shallow copy!
Parameters:
Name Type Description
obj object The source object.
toOmit string | array The properties to omit.
Source:
Returns:
Type
object

(static) pickFromObject(obj, toPick) → {object}

Creates an object composed of the picked object properties. Returns a shallow copy!
Parameters:
Name Type Description
obj object The source object.
toPick string | array The properties to pick.
Source:
Returns:
Type
object

(static) prettifyString(strings, arraySep) → {string}

Tries to make a string more readable by capitalizing it. Only applies to words with more than two characters. Supports converting from: - Snake Case (abc_def => Abc Def) - Kebab Case (abc-def => Abc Def) - Camel Case (abcDef => Abc Def) Doesn't capitalize if the words are not in any of the casing formats above.
Parameters:
Name Type Default Description
strings * String(s) to make readable
arraySep string ; String to separate array elements with
Source:
Returns:
Type
string

(static) replacePlaceholders(message, variables)

Replaces placeholders in this format: `{var}`. This can be used for the placeholders/variables in the openEO API's errors.json file.
Parameters:
Name Type Description
message string The string to replace the placeholders in.
variables object A map with the placeholder names as keys and the replacement value as value.
Source:

(static) size(obj) → {integer}

Computes the size of an array (number of array elements) or object (number of key-value-pairs). Returns 0 for all other data types.
Parameters:
Name Type Description
obj *
Source:
Returns:
Type
integer

(static) unique(array, useEquals) → {array}

Creates a duplicate-free version of an array. If useEquals is set to true, uses the `Utils.equals` function for comparison instead of the JS === operator. Thus, if the array contains objects, you likely want to set `useEquals` to `true`.
Parameters:
Name Type Default Description
array array
useEquals boolean false
Source:
Returns:
Type
array