A collection of useful util functions.
Namespaces
Methods
-
staticGoBrain.Utils.all(arr, func, callback)
GoBrain.Core/src/utils.js, line 220Applies a function to each item in an array and only calls the callback if all of them succeeds.
-
Applies a function to each item in an array and only calls the callback if all of them succeeds.
Name Type Description arrArray.<*> Array of items to operate against.
funcfunction Function to be applied to each item in the array.
callbackfunction Callback to be executed once all operations have succeeded.
Throws:
-
staticGoBrain.Utils.argumentNames(func){Array.<String>}
GoBrain.Core/src/utils.js, line 250Parses argument names for a function.
-
Parses argument names for a function.
Name Type Description funcfunction Throws:
-
If argument is not a function.
Returns:
Type Description Array.<String> A list of argument names for the given function. -
-
staticGoBrain.Utils.array(array){*|null}
GoBrain.Core/src/utils.js, line 648Get first item from array, or null.
-
Get first item from array, or null.
Name Type Description arrayArray.<*> Returns:
Type Description * | null The first item in the array, or null. -
staticGoBrain.Utils.async(functions, callback)
GoBrain.Core/src/utils.js, line 273Executes any number of asynchronous operations and invokes a callback once all of them are completed.
-
Executes any number of asynchronous operations and invokes a callback once all of them are completed.
Name Type Description functionsfunction repeatable Any number of asynchronous functions to be executed.
callbackfunction Callback to be executed once all asynchronous operations have been completed.
Throws:
-
staticGoBrain.Utils.callEndpoint(endpoint, method, data, headers, timeoutInMS, onSuccess, onError, onTimeout, withCredentials)
GoBrain.Core/src/utils.js, line 302Makes a function or HTTP call to an endpoint.
-
Makes a function or HTTP call to an endpoint.
Name Type Default Description endpointString | function Endpoint to call.
methodString GET optional HTTP method to use.
dataString {} optional Data to send.
headersObject.<String, String> { 'Content-Type': 'application/json' } optional Headers to send.
timeoutInMSNumber {} optional Timeout in milliseconds.
onSuccessfunction optional Successful callback.
onErrorfunction optional Failure callback.
onTimeoutfunction optional Timeout callback.
withCredentialsBoolean optional Set the XHR property withCredentials.
-
staticGoBrain.Utils.cancelFrame(id)
GoBrain.Core/src/utils.js, line 9Cancels the scheduled execution of a function at the next available animation frame.
-
Cancels the scheduled execution of a function at the next available animation frame.
Name Type Description idNumber The cancellable animation frame id.
-
staticGoBrain.Utils.createFunctionFromLambda(lambda){function}
GoBrain.Core/src/utils.js, line 465Constructs a new function from a C# style lambda expression string.
-
Constructs a new function from a C# style lambda expression string.
Name Type Description lambdaString Lambda expression to create function from.
Returns:
Type Description function -
staticGoBrain.Utils.createOrReplaceScript(script, src){HTMLElement}
GoBrain.Core/src/utils.js, line 508If a script already exists with the same source then replaces that one, otherwise adds the new one.
-
If a script already exists with the same source then replaces that one, otherwise adds the new one.
Name Type Description scriptHTMLElement Script element.
srcString The source of the script.
Returns:
Type Description HTMLElement The script element. -
staticGoBrain.Utils.defer(func)
GoBrain.Core/src/utils.js, line 530Defers execution of a function.
-
Defers execution of a function.
Name Type Description funcfunction Throws:
-
If argument is not a function.
-
-
staticGoBrain.Utils.endsWith(str, suffix){Boolean}
GoBrain.Core/src/utils.js, line 558Checks if a string ends with another string.
-
Checks if a string ends with another string.
Name Type Description strString The string to search in.
suffixString The suffix string to check for.
Returns:
Type Description Boolean Whether the string ends with the suffix. -
staticGoBrain.Utils.enumerate(obj, func){*}
GoBrain.Core/src/utils.js, line 574Enumerates an object and applies a Function to each key value pair.
-
Enumerates an object and applies a Function to each key value pair.
Name Type Description objObject funcfunction Returns:
Type Description * Whatever is returned from the Function given as an argument. -
staticGoBrain.Utils.exists(args){Boolean}
GoBrain.Core/src/utils.js, line 599Checks if all given arguments are defined.
-
Checks if all given arguments are defined.
Name Type Description args* repeatable Returns:
Type Description Boolean Whether all the args exist. -
staticGoBrain.Utils.extend(args){Object}
GoBrain.Core/src/utils.js, line 614Deep copy from right to left.
-
Deep copy from right to left.
Name Type Description argsObject repeatable Returns:
Type Description Object The extended base object. -
staticGoBrain.Utils.guid(format){String}
GoBrain.Core/src/utils.js, line 663Generates a GUID.
-
Generates a GUID.
Name Type Default Description formatString xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx optional Returns:
Type Description String The generated GUID. -
staticGoBrain.Utils.inherits(child, parent){function}
GoBrain.Core/src/utils.js, line 678Sets up child to inherit from parent.
-
Sets up child to inherit from parent.
Name Type Description childfunction parentfunction Returns:
Type Description function -
staticGoBrain.Utils.isArray(arg){Boolean}
GoBrain.Core/src/utils.js, line 712Checks if arg is an Array.
-
Checks if arg is an Array.
Name Type Description arg* Returns:
Type Description Boolean Whether arg is an array. -
staticGoBrain.Utils.isEmpty(arg){Boolean}
GoBrain.Core/src/utils.js, line 723Checks if arg is empty.
-
Checks if arg is empty.
Name Type Description arg* Returns:
Type Description Boolean -
staticGoBrain.Utils.isFunction(arg){Boolean}
GoBrain.Core/src/utils.js, line 741Checks if arg is a Function.
-
Checks if arg is a Function.
Name Type Description arg* Returns:
Type Description Boolean Whether arg is a function. -
staticGoBrain.Utils.isObject(arg){Boolean}
GoBrain.Core/src/utils.js, line 752Checks if arg is an Object.
-
Checks if arg is an Object.
Name Type Description arg* Returns:
Type Description Boolean Whether arg is an object. -
staticGoBrain.Utils.loadScript(url, callback, track){HTMLElement}
GoBrain.Core/src/utils.js, line 763Loads a script and calls callback when script is loaded.
-
Loads a script and calls callback when script is loaded.
Name Type Default Description urlString callbackfunction optional trackBoolean true optional Whether or not to track script for later removal.
Returns:
Type Description HTMLElement The script element. If script is being tracked and has already been requested then null will be returned. -
staticGoBrain.Utils.loadScriptArray(scriptArray, callback, baseUrl)
GoBrain.Core/src/utils.js, line 834Loads an array of scripts and calls callback once all scripts are loaded.
-
Loads an array of scripts and calls callback once all scripts are loaded.
Name Type Description scriptArrayArray.<String> Array of scripts to load.
callbackoptional Callback to be called once all scripts are loaded.
baseUrlString optional Base url to use for all scripts.
-
staticGoBrain.Utils.loadStyle(url, callback){HTMLElement}
GoBrain.Core/src/utils.js, line 856Loads a css and calls callback when css is loaded.
-
Loads a css and calls callback when css is loaded.
Name Type Description urlString callbackfunction optional Returns:
Type Description HTMLElement The style element. -
staticGoBrain.Utils.normalize(str){String|null}
GoBrain.Core/src/utils.js, line 904Normalizes a String.
-
Normalizes a String.
Name Type Description strString Returns:
Type Description String | null The normalized string. -
staticGoBrain.Utils.notNullOrEmpty(str){Boolean}
GoBrain.Core/src/utils.js, line 919Checks that a String is not undefined, not null and not empty.
-
Checks that a String is not undefined, not null and not empty.
Name Type Description strString Returns:
Type Description Boolean Whether arg is not null or empty. -
staticGoBrain.Utils.once(func){function}
GoBrain.Core/src/utils.js, line 930Returns a wrapper Function around func that ensures func is only called once, no matter how many times the wrapper Function is called.
-
Returns a wrapper Function around func that ensures func is only called once, no matter how many times the wrapper Function is called.
Name Type Description funcfunction Returns:
Type Description function The wrapper function. -
staticGoBrain.Utils.padLeft(str, length, char){String}
GoBrain.Core/src/utils.js, line 944Pads a string from the left.
-
Pads a string from the left.
Name Type Description strString String to be padded.
lengthNumber Desired length of string.
charString Character to use for padding.
Returns:
Type Description String The padded string. -
staticGoBrain.Utils.requestFrame(func){Number}
GoBrain.Core/src/utils.js, line 22Requests that a function will be executed at the next available animation frame.
-
Requests that a function will be executed at the next available animation frame.
Name Type Description funcfunction Returns:
Type Description Number A cancellable animation frame id. -
staticGoBrain.Utils.resolveUrl(args){String}
GoBrain.Core/src/utils.js, line 965Resolves a url given parts of it.
-
Resolves a url given parts of it.
Name Type Description argsString repeatable Parts of url.
Returns:
Type Description String The resolved url. -
staticGoBrain.Utils.seq(arr, func, callback)
GoBrain.Core/src/utils.js, line 1003Applies a function to each item in an array sequentially/synchronously and invokes the callback once all of them are completed.
-
Applies a function to each item in an array sequentially/synchronously and invokes the callback once all of them are completed.
Name Type Description arrArray.<*> Array of items to operate against.
funcfunction Function to be applied to each item in the array.
callbackfunction Callback to be executed once all operations have been completed.
Throws:
-
staticGoBrain.Utils.setQueryStringParameter(url, key, value){String}
GoBrain.Core/src/utils.js, line 1037Adds or updates a query string parameter in a URL.
-
Adds or updates a query string parameter in a URL.
Name Type Description urlString URL to set query string parameter in.
keyString The query string parameter key.
valueString The query string parameter value.
Returns:
Type Description String The updated URL. -
staticGoBrain.Utils.stringFormat(pattern, args){String}
GoBrain.Core/src/utils.js, line 1052Uses replacement tokens to format a string.
-
Uses replacement tokens to format a string. The replacement tokens can be either named or positional.
Name Type Description patternString Pattern containing replacement tokens.
argsObject | * Values to replace replacement tokens in pattern with. Can be an object containing all values or any number of value arguments if using positional replacement.
Returns:
Type Description String The formatted string. -
staticGoBrain.Utils.values(obj){Array.<*>}
GoBrain.Core/src/utils.js, line 1100Gets all the values of an object.
-
Gets all the values of an object.
Name Type Description objObject The object to get the values from.
Returns:
Type Description Array.<*> The object's values.