new Utils()
- Source:
- src/utils/Utils.js line 11
Classes
Methods
-
<static> extend(deep, target)
-
This is a slightly modified version of http://api.jquery.com/jQuery.extend/
Parameters:
Name Type Description deepboolean Perform a deep copy?
targetobject The target object to copy to.
- Source:
- src/utils/Utils.js line 259
Returns:
The extended object.
- Type
- object
-
<static> getProperty(obj, prop)
-
Gets an object's property by string.
Parameters:
Name Type Description objobject The object to traverse.
propstring The property whose value will be returned.
- Source:
- src/utils/Utils.js line 27
Returns:
- The value of the property or
undefinedif the property isn't found.
- Type
- any
-
<static> isPlainObject(obj)
-
This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].
Parameters:
Name Type Description objobject The object to inspect.
- Source:
- src/utils/Utils.js line 223
Returns:
- true if the object is plain, otherwise false.
- Type
- boolean
-
<static> mixin(from, to)
-
Mixes the source object into the destination object, returning the newly modified destination object. Based on original code by @mudcube
Parameters:
Name Type Description fromobject The object to copy (the source object).
toobject The object to copy to (the destination object).
- Source:
- src/utils/Utils.js line 391
Returns:
The modified destination object.
- Type
- object
-
<static> mixinPrototype(target, mixin [, replace])
-
Mixes in an existing mixin object with the target.
Values in the mixin that have either
getorsetfunctions are created as properties viadefinePropertyexcept if they also define aclonemethod - if a clone method is defined that is called instead and the result is assigned directly.Parameters:
Name Type Argument Default Description targetobject The target object to receive the new functions.
mixinobject The object to copy the functions from.
replaceboolean <optional>
false If the target object already has a matching function should it be overwritten or not?
- Source:
- src/utils/Utils.js line 339
-
<static> pad(str [, len] [, pad] [, dir])
-
Takes the given string and pads it out, to the length required, using the character specified. For example if you need a string to be 6 characters long, you can call:
pad('bob', 6, '-', 2)This would return:
bob---as it has padded it out to 6 characters, using the-on the right.You can also use it to pad numbers (they are always returned as strings):
pad(512, 6, '0', 1)Would return:
000512with the string padded to the left.If you don't specify a direction it'll pad to both sides:
pad('c64', 7, '*')Would return:
**c64**Parameters:
Name Type Argument Default Description strstring The target string.
toString()will be called on the string, which means you can also pass in common data types like numbers.leninteger <optional>
0 The number of characters to be added.
padstring <optional>
" " The string to pad it out with (defaults to a space).
dirinteger <optional>
3 The direction dir = 1 (left), 2 (right), 3 (both).
- Source:
- src/utils/Utils.js line 162
Returns:
The padded string.
- Type
- string
-
<static> parseDimension(size, dimension)
-
Get a unit dimension from a string.
Parameters:
Name Type Description sizestring | number The size to parse.
dimensionnumber The window dimension to check.
- Source:
- src/utils/Utils.js line 119
Returns:
The parsed dimension.
- Type
- number
-
<static> reverseString(string)
-
Takes the given string and reverses it, returning the reversed string. For example if given the string
Atari 520STit would returnTS025 iratA.Parameters:
Name Type Description stringstring The string to be reversed.
- Source:
- src/utils/Utils.js line 13
Returns:
The reversed string.
- Type
- string
-
<static> setProperty(obj, prop)
-
Sets an objects property by string.
Parameters:
Name Type Description objobject The object to traverse
propstring The property whose value will be changed
- Source:
- src/utils/Utils.js line 61
Returns:
The object on which the property was set.
- Type
- object
-
chanceRoll(chance)
-
Generate a random bool result based on the chance value.
Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed.
Parameters:
Name Type Description chancenumber The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%).
- Source:
- src/utils/Utils.js line 92
Returns:
True if the roll passed, or false otherwise.
- Type
- boolean
-
randomChoice(choice1, choice2)
-
Choose between one of two values randomly.
Parameters:
Name Type Description choice1any choice2any - Source:
- src/utils/Utils.js line 107
Returns:
The randomly selected choice
- Type
- any