⁘ utils

UTILS

UTILS is a wrapper class that contains a bunch of utilitary static methods. These include type-checking, object manipulation, etc.

go to → Members

Members

staticunsafeUID :string

Compute an 'unsafe' UID. While unsafe, it'll still do a decent job of being unique over the course of a session, but is based on Math.random() so limited and possibly redundant

Methods

staticAppend(p_base, p_source) → {object}

Appends the value of an Object into another. First-level properties only, no overwriting.

Parameters:
Name Type Description
p_base object

The base object to append into

p_source object

The reference object to fetch values from

staticArrayDiff(p_oldArray, p_newArray, p_out, p_in)

Creates a diff of two array, and 'old' one and a 'new' one, and outputs the result into two array (out & in) that must be provided.

Parameters:
Name Type Description
p_oldArray array

The old array to compare p_newArray against

p_newArray array

The new array to compare p_oldArray against

p_out array

Empty Array, will be filled with the items that are present in p_oldArray, but not in p_newArray

p_in array

Empty Array, will be filled with the items that are not in p_oldArray, but present in p_newArray

staticArrayDiffCallbacks(p_oldArray, p_newArray, p_outCallback, p_inCallback)

Creates a diff of two array, and 'old' one and a 'new' one, and call functions for each item that has been either added or removed

Parameters:
Name Type Description
p_oldArray array

The old array to compare p_newArray against

p_newArray array

The new array to compare p_oldArray against

p_outCallback array

Will be called each time an item is present in p_oldArray, but not in p_newArray

p_inCallback array

Will be called each time an item is not in p_oldArray, but present in p_newArray

staticCamelSplit(p_string) → {string}

Split a 'CamelCase' string into a 'Camel Case' one

Parameters:
Name Type Description
p_string string

The string to split

staticClear(p_obj, p_returnNewEmpty) → {object}

Deletes all properties on an a given object. First-level properties only.

Parameters:
Name Type Default Description
p_obj object

The object to be emptied

p_returnNewEmpty boolean false

Wether to return a new empty object or not

staticClone(p_base) → {object}

Clone an Object.

Parameters:
Name Type Description
p_base object

The base object to clone

staticCloneArray(p_base) → {array}

Clone an Array. Recursive.

Parameters:
Name Type Description
p_base array

The base object to clone

staticDateDiff(p_a, p_b)

A - B

Parameters:
Name Type Description
p_a *
p_b *

staticDeepClear(p_obj, p_returnNewEmpty) → {object}

Deletes all properties on an a given object, and clears any value that is an object or an array itself. Recursive.

Parameters:
Name Type Default Description
p_obj object

The object to be emptied

p_returnNewEmpty boolean false

Wether to return a new empty object or not

staticDeepClearArray(p_arr)

Empty an array and clears any value that is an object or an array itself. Recursive.

Parameters:
Name Type Description
p_arr array

The object to be emptied

staticDefault(…args) → {*}

Returns the first non-void value

Parameters:
Name Type Attributes Description
args * <repeatable>

A list of values to test

staticEnsure(p_obj, p_key, p_value)

Ensure a value is set on a object.

Parameters:
Name Type Description
p_obj object

The target object

p_key string

The property's name

p_value *

The default value to set the property to if it does not exists

staticEnsureMultiple(p_obj, p_kvp)

Ensure a value is set on a object.

Parameters:
Name Type Description
p_obj object

The target object

p_kvp object

The property's name

staticFixSlash(p_string) → {string}

Replaces \ with /

Parameters:
Name Type Description
p_string string

The string to sanitize

staticGet(p_obj, p_key, p_fallback) → {*}

Attempts to get the property value on a given object.

Parameters:
Name Type Default Description
p_obj object

The object to extract the property value from

p_key string

The property's name

p_fallback * null

The fallback value that will be returned if the property cannot be found, or if its value is 'void'

staticInheritanceDistance(p_from, p_to) → {number}

Checks the 'inheritance distance' between two Classe or Instances thereof. p_to should be a 'distant child' of p_from, not the other way around.

Parameters:
Name Type Description
p_from Object | class

The base Class or Instance

p_to Object | class

The target Class or Instance

staticisArray(p_value) → {boolean}

Determine if a value is an Array

Parameters:
Name Type Description
p_value *

The value to test

staticisArrayBuffer(val) → {boolean}

Determine if a value is an ArrayBuffer

Parameters:
Name Type Description
val object

The value to test

staticisBool(p_value) → {boolean}

Determine if a value is a Boolean

Parameters:
Name Type Description
p_value *

The value to test

staticisEmpty(p_value) → {boolean}

Determine if an object is empty

Parameters:
Name Type Description
p_value *

The value to test

staticisFunc(p_value) → {boolean}

Determine if a value is a Function

Parameters:
Name Type Description
p_value *

The value to test

staticisInstanceOf(p_source, p_target) → {boolean}

Determine if a (source) Class or Instance of a constructor is an instance of another (target) Class or Instance of a given Class. *

Parameters:
Name Type Description
p_source Object | function

The value to test

p_target Object | function

The value to test against

staticisNot(p_value, …args) → {boolean}

Checks whether a value is not equal to any of the provided ones

Parameters:
Name Type Attributes Description
p_value *

The value to test

args * <repeatable>

The values to test against

staticisNumber(p_value) → {boolean}

Determine if a value is a Number

Parameters:
Name Type Description
p_value *

The value to test

staticisObject(p_value) → {boolean}

Determine if a value is an Object

Parameters:
Name Type Description
p_value *

The value to test

staticisSame(p_source, p_other) → {boolean}

Checks whether two objects contains exactly the same values

Parameters:
Name Type Description
p_source object

The object to test

p_other object

The object to test against

staticisSameArray(p_source, p_other) → {boolean}

Checks whether two arrays contains exactly the same values at the same index

Parameters:
Name Type Description
p_source array

The array to test

p_other array

The array to test against

staticisString(p_value) → {boolean}

Determine if a value is a string

Parameters:
Name Type Description
p_value *

The value to test

staticisSymbol(p_value) → {boolean}

Determine if a value is an Object

Parameters:
Name Type Description
p_value *

The value to test

staticisUndefined(p_value) → {boolean}

Determine if a value is undefined

Parameters:
Name Type Description
p_value *

The value to test

staticisVoid(p_value) → {boolean}

Determine if a value is either undefined or null

Parameters:
Name Type Description
p_value *

The value to test

staticJoin(p_array, p_joinStr, p_fromIndex, p_toIndex) → {string}

Join the content of an array from/to specific indices

Parameters:
Name Type Default Description
p_array array

The array to join

p_joinStr string

string to join with

p_fromIndex number 0

Start join index

p_toIndex number

End join index

staticMerge(p_base, p_source, p_skipExisting) → {object}

Merges the value of an Object into another. Recursive, overwrites (unless p_skipExisting === true)

Parameters:
Name Type Default Description
p_base object

The base object to append into

p_source object

The reference object to fetch values from

p_skipExisting object false

Whether or not to overwrite on existing values

staticMergeArray(p_base, p_source) → {array}

Add missing content from p_source into p_base (no duplicates)

Parameters:
Name Type Description
p_base array
p_source array

staticPad(p_num, p_size)

Pad a number with leading 0's

Parameters:
Name Type Default Description
p_num number
p_size number 2

staticParsePath(p_stringPath)

Breaks down a path into an object to the following format : { path:[catalog, catalog, ...], item:tailName, ext:extention, }

Parameters:
Name Type Description
p_stringPath string

staticSetMissing(p_base, p_source, p_mergeArrays)

Copy values from p_source currently missing in p_base. Merge object properties

Parameters:
Name Type Default Description
p_base *
p_source *
p_mergeArrays * false

if true, will unshift array values from source into base when the two values are arrays.

staticSetOverwrite(p_base, p_source)

Set values from p_source to p_base, overriding existing values. Merge objects properties.

Parameters:
Name Type Description
p_base *
p_source *

staticREGEXStartWithNumber(p_str) → {boolean}

Checks whether a string starts with a digit.

Parameters:
Name Type Description
p_str string

String to test

staticREGEXValidIdentifier(p_str) → {boolean}

Checks whether a string is a valid identifier.

Parameters:
Name Type Description
p_str string

String to test