FORGE. Utils

Global utilities.
Source:

Methods

(static) arrayByDifference(array, elements) → {Array}

Get an array by difference with another array
Parameters:
Name Type Description
array Array input array to be filtered
elements Array elements to be excluded in result array
Source:
Returns:
difference array (array - elements)
Type
Array

(static) arrayKeys(array) → {IteratorIterable|Object}

Polyfill of Array.prototype.keys in ES5.
Parameters:
Name Type Description
array Array | TypedArray Array to iterate.
Source:
Returns:
Iterator
Type
IteratorIterable | Object

(static) arrayUnique(array) → {Array}

Get an array of unique elements from a given array
Parameters:
Name Type Description
array Array input array to be filtered
Source:
Returns:
array of unique elements
Type
Array

(static) clone(obj) → {*}

Clone an object deeply, without keeping a single reference.
Parameters:
Name Type Description
obj * any object to clone
Source:
Returns:
the cloned object
Type
*

(static) compareObjects(objectA, objectB) → {boolean}

Compare two objects
Parameters:
Name Type Description
objectA * The first object to compare
objectB * The second object to compare
Source:
Returns:
Returns true if the two objects are the same
Type
boolean

(static) countProperties(object) → {number}

Count object properties
Parameters:
Name Type Description
object *
Source:
Returns:
Returns the count of the object's properties
Type
number

(static) endsWith(str, suffix) → {boolean}

endsWith ES6 implementation
Parameters:
Name Type Description
str string
suffix string
Source:
Returns:
Ends with suffix?
Type
boolean

(static) extendMultipleObjects(…obj) → {Object}

Extend multiple object you pass in arguments, the last overrides the first and so on ...
Parameters:
Name Type Attributes Description
obj Object <repeatable>
the objects to merge
Source:
Returns:
return the merged objects.
Type
Object

(static) extendSimpleObject(from, to, recursiveopt) → {Object}

TODO. Use for config extend / override.
Parameters:
Name Type Attributes Description
from Object
to Object
recursive boolean <optional>
Source:
Returns:
Type
Object

(static) formatTime(time, format) → {string}

Format a timestamp according to a format (eg: H:M:S)
H = hours two digits.
h = hours no 0 fill.
M = minutes two digits.
m = minutes no 0 fill.
S = seconds two digits.
s = seconds no 0 fill.
Parameters:
Name Type Description
time number Timestamp in seconds.
format string The out format for time (default "H:M:S").
Source:
Returns:
Returns the formated time string.
Type
string

(static) getObjectProperty(object, property, defaultReturnValueopt) → {*}

Get an objet property by its string path in pointed syntax.
Parameters:
Name Type Attributes Description
object Object The main object that handle the property you want to check.
property string Path to the property you want to get (example : "image.url" on a button skin state)
defaultReturnValue * <optional>
The default return value if not found, if not specified the default is undefined
Source:
Returns:
Returns the property if found, if not found returns your defaultReturnValue or undefined.
Type
*

(static) isArrayOf(array, className) → {boolean}

Know if array is an array full of object of a single ForgeJS className or classic JS types like string, number ...
Parameters:
Name Type Description
array * The array to test.
className string The className to test if this array is exclusvie to this className.
Source:
Returns:
Returns true if the array is full of object with the className in params.
Type
boolean

(static) isDisplayObject(object) → {boolean}

Is the object a display object? Check the className.
Parameters:
Name Type Description
object Object The object to verify.
Source:
Returns:
Returns true if the object is a display object.
Type
boolean

(static) isTypeOf(object, className) → {boolean}

Is the className of the object can be verified?
Parameters:
Name Type Description
object * The object to verify.
className string | Array.<string> The className to search for, it can be a string or an array of string if you accept multiple types.
Source:
Returns:
Returns true if the className of the object can be verified.
Type
boolean

(static) isTypeOfRecursive(object, path, className) → {boolean}

Check the className of an object based on it's path (pointed syntax in string)
Very usefull if you have to check a deep property without the knowing if all the parent chain is defined.
Parameters:
Name Type Description
object Object The main object that handle the property you want to check.
path string Path to the target you want to check (example : "image.url" on a button skin state)
className string The className you want to check for
Source:
Returns:
Returns true if object is of the asked className, false if not or if it's not found.
Type
boolean

(static) leftFill(string, fillCharacter, length) → {string}

Fill a string from the left
Parameters:
Name Type Description
string string String to fill.
fillCharacter string | number Char or string to fill with.
length number The length for the output string.
Source:
Returns:
The filled string.
Type
string

(static) makePromise() → {Promise}

Make a new promise Returned promise has accessors on resolve and reject to call them out of definition scope
Source:
Returns:
extended promise
Type
Promise

(static) parseSizeString(value) → {Object}

Convert a string value into a size object.
Parameters:
Name Type Description
value string The string value to convert.
Source:
Returns:
A size object with value and unit.
Type
Object

(static) parseTime(seconds) → {Object}

Parse seconds value in hours, minutes and seconds components.
Parameters:
Name Type Description
seconds number Seconds to parse.
Source:
Returns:
Parsed values in an object.
Type
Object

(static) randomize(array) → {Array.<*>}

Randomize the content of an array. Uses the Durstenfeld version of the Fisher-Yates algorithm. https://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm
Parameters:
Name Type Description
array Array.<*> The array to randomize
Source:
Returns:
The randomized array
Type
Array.<*>

(static) removeItemFromArrayAtIndex(array, idx) → {Object}

Remove and return item from an array at given index
Parameters:
Name Type Description
array Array input array
idx number item index
Source:
Returns:
removed array item or null if index was out of bounds
Type
Object

(static) sortArrayByProperty(array, property) → {Array}

Sort an array by property.
Parameters:
Name Type Description
array Array The array to test.
property string The property to sort.
Source:
Returns:
Returns the sorted array.
Type
Array

FORGE. Utils

Methods