Table of Contents

Util

Overview

Util a utility class that collects various utility functions.

Methods

assert(conditions, msg, error)

Type:Undefined Static

Raises an exception If the specified condition is not met.

Parameters

ParameterTypeDescription
conditions
Required
ExpressionThe expression that determines whether to raise an exception. If the result is false, an exception is raised.
msg
Required
StringThe message to show.
error
Default:Error
ErrorThe exception to be raised.

Return Value

Undefined.


concatPath(paths)

Type:String Static

The strings in the array passed are concatenated using “/” as the delimiter to create a path. The paths are concatenated so that only one “/” appears between each word, taking into account whether each element begins or ends with a “/”.

Parameters

ParameterTypeDescription
paths
Required
Array of StringThe array of paths.

Return Value

The concatenated path string.


deepClone(target)

Type:* Static

Deep clones the value passed in the argument.

Parameters

ParameterTypeDescription
target
Required
*The value to be cloned.

Return Value

The cloned value.


deepMerge(obj1, obj2)

Type:Object Static

Deep merges argument obj2 into obj1. The obj1 will be overwritten.

Parameters

ParameterTypeDescription
obj1
Required
ObjectThe objects to be merged.
obj2
Required
ObjectThe object to merge.

Return Value

The obj1 after merged.


getClassNameFromTagName(tagName)

Type:String Static

Generates a class name from the HTML tag name given in the argument. The class name is created by concatenating the tag name with the first letter of the word before and after the hyphen capitalized and the hyphen removed.

Parameters

ParameterTypeDescription
tagName
Required
StringThe tag Name.

Return Value

The generated class name.


getObject(target, options)

Type:Object Static

Converts a value to an object. If the value passed is an object, it is returned as is.

Parameters

ParameterTypeDescription
target
Required
StringThe value to convert.
optionsObjectThe options. Has the following keys:
“format”StringIf “js” is specified, target is assumed to be a Javascript object. If not specified, JSON is assumed.
“bindTo”StringIf the format is “js”, specify the object to be bound. This value can be referenced by “this” inside the object.

Return Value

The converted object.


getTagNameFromClassName(className)

Type:String Static

Generates a tag name from the class name given in the argument. The tag name will be the class name with a hyphen between the first and second words which start with an uppercase letter, and then all lowered.

Parameters

ParameterTypeDescription
className
Required
StringThe class Name to convert.

Return Value

The converted tag Name.


randomWait(max, fixed)

Type:Undefined Asynchronous Static

Returns a promise that will be resolved after a random time.

Parameters

ParameterTypeDescription
maxNumberMaximum time until being resolved in milliseconds.
fixedBooleanIf true, resolves after the time specified by the max parameter instead of a random time.

Return Value

Undefined.


safeEval(code, parameters)

Type:* Static

Executes the text of the Javascript code given and returns the result. The code will be executed in strict mode.

Parameters

ParameterTypeDescription
code
Required
StringThe javascript code to be executed.
parametersObjectThe parameters object that is bound to the code. It can be accessed within the code with “this”.

Return Value

The return value of the executed code.


safeGet(store, key, defaultValue)

Type:* Static

Returns the value specified by the key parameter from the given object. Returns the default value if the key doesn't exist. The value will be deep copied if the value is an array or object.

You can use a period-separated string to specify a hierarchy.

Parameters

ParameterTypeDescription
store
Required
ObjectThe object from which to retrieve.
key
Required
StringThe key to be retrieved.
defaultValue*The default value to be returned when the key doesn't exist.

Return Value

The value specified by the key. When the key is not found, returns the default value, or Undefined if the default value is missing.


safeHas(store, key)

Type:Boolean Static

Returns whether the specified key exists in the object.

You can use a period-separated string to specify a hierarchy.

Parameters

ParameterTypeDescription
store
Required
ObjectThe object to check.
key
Required
StringThe key to check.

Return Value

True if the key exists, false if it doesn't exist.


safeMerge(store, key, value)

Type:Object Static

Merges the value into the object given at the position specified by the key. The actual merging is done by Util.deepMerge(). The store parameter will be be overwritten.

You can use a period-separated string to specify a hierarchy.

Parameters

ParameterTypeDescription
store
Required
ObjectThe object to be merged.
key
Required
StringThe key to be merged.
value
Required
*The value to merge.

Return Value

Returns the store given in the argument after merged.


safeSet(store, key, value)

Type:Object Static

Sets the value to an item in the object specified by the key parameter. If the key does not exist, it will be automatically created. If the item already exists in the store, the value will be overwritten by the new value.

You can use a period-separated string to specify a hierarchy.

Parameters

ParameterTypeDescription
store
Required
ObjectThe object to set the value.
key
Required
StringThe key to set the value.
value
Required
*The value to set.

Return Value

Returns the store given in the argument after set.


safeRemove(store, key)

Type:Object Static

Removes the item that has the specified key.

You can use a period-separated string to specify a hierarchy.

Parameters

ParameterTypeDescription
store
Required
ObjectThe object to be removed.
key
Required
StringThe key to remove.

Return Value

Returns the store given in the argument after removal.


scopedSelectorAll(rootNode, query, options)

Type:NodeList Static

Returns HTML elements matching the query under the node specified. If there is another unit under the node, it does not search within that unit by default.

Parameters

ParameterTypeDescription
rootNodeHTMLElementThe starting node of the search.
queryStringThe search query. The same format as document.querySelector().
optionsObjectThe options. Has the following keys:
“penetrate”BooleanIf True, the inner HTML of another unit is also searched.

Return Value

A list of HTML elements found.


warn(conditions, msg, level)

Type:Undefined Static

The warning message is displayed on the console if the specified condition is not met.

Parameters

ParameterTypeDescription
conditions
Required
ExpressionThe expression that determines whether to show a warning. If the result is false, the warning message is displayed.
msg
Required
StringThe message to be displayed.
level
Default:warn
StringThe message level.

Return Value

Undefined.