Methods
(static) clamp(value, min, max) → {number}
Clamp a value between range: inclusive.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | Number to clamp. |
min |
number | Minimum value inclusive. |
max |
number | Maximum value inclusive. |
Returns:
- Type
- number
(static) createWaiter() → {module:utils~Waiter}
Create a Waiter object. This object allow the program to wait until the application calls its end method.
Returns:
- Type
- module:utils~Waiter
(static) fetchArrayBuffer(url, headers, options) → {Promise}
Call to fetch to get an array buffer from a media file.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | URL | Request | Url to fetch. |
headers |
Object | The Headers to add to the request. |
options |
RequestInit | If null, the content type is derived from the url. See RequestInit. |
Throws:
Returns:
Fulfils to the ArrayBuffer.
- Type
- Promise
(static) fetchJson(url, fallbackResult) → {Promise}
Call to fetch to get json.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | URL | Request | Url to fetch. |
fallbackResult |
Object | Result if error |
Throws:
-
Thrown if error occurs and fallbackResult is undefined. Null is a valid fallbackResult
- Type
- Error
Returns:
Fulfils to Object. On error, fulfils to fallbackResult or throws error.
- Type
- Promise
(static) fetchText(url, fallbackResult) → {Promise}
Call to fetch to get text.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | URL | Request | Url to fetch. |
fallbackResult |
string | Result if error |
Throws:
-
Thrown if error occurs and fallbackResult is undefined. Null is a valid fallbackResult
- Type
- Error
Returns:
Fulfils to text. On error, fulfils to fallbackResult or throws error.
- Type
- Promise
(static) fetchTextOrJson(url, asJson, fallbackResult) → {Promise}
Call to fetch to get text.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | URL | Request | Url to fetch. |
asJson |
boolean | If true pass the result as JSON. |
fallbackResult |
string | Object | Result to return if error. |
Throws:
-
Thrown if error occurs and fallbackResult is undefined. Null is a valid fallbackResult
- Type
- Error
Returns:
Fulfils to text or json. On error, fulfils to fallbackResult. If fallbackResult is undefined, an error is thrown.
- Type
- Promise
(static) getHcjeAssetHref(name) → {string}
Get the name of an asset in the HCJE regardless of where the HCJE has been installed.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | the name of the asset in the HCJE's asset folder. |
Returns:
- Type
- string
(static) getRandomIntExclusive(min, max)
Get random integer in range. If max <= min, returns min.
Parameters:
| Name | Type | Description |
|---|---|---|
min |
number | Minimum value inclusive |
max |
number | Maximum value exclusive |
(static) getRandomIntInclusive(min, max)
Get random integer in range. If max <= min, returns min.
Parameters:
| Name | Type | Description |
|---|---|---|
min |
number | Minimum value inclusive. |
max |
number | Maximum value inclusive. |
(static) getRandomMember(arr) → {*}
Get a random entry from an array or string.
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array.<*> | Array from which to get entry. |
Returns:
Entry; undefined if arr undefined or empty.
- Type
- *
(static) getRandomNumberBetween(min, max) → {number}
Get random number between min (inclusive) and max (exclusive).
Parameters:
| Name | Type | Description |
|---|---|---|
min |
number | Minimum value inclusive. |
max |
number | Maximum value exclusive. |
Returns:
- Type
- number
(static) greatestCommonDivisor(a, b) → {number}
Get greatest common divisor.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
number | First number. |
b |
number | Second number. |
Returns:
- Type
- number
(static) jitter(value, variation) → {number}
Get a random number based on a value and variation. For a value of N and variation of V the result will be a random number between N (1 - V) and N (1 + V).
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | Number to adjust. |
variation |
number | Variation to apply to the value. This is a proportion of the value, not an absolute value. |
Returns:
- Type
- number
(static) lowestCommonMultiple(valueA, valueB) → {number}
Calculate the lowest common multiple of two numbers.
Parameters:
| Name | Type | Description |
|---|---|---|
valueA |
number | First number. |
valueB |
number | Second number. |
Returns:
- Type
- number
(static) lowestCommonMultipleOfArray(values) → {number}
Get lowest common multiple of an array of values.
Parameters:
| Name | Type | Description |
|---|---|---|
values |
Array.<number> | Array of numbers. |
Returns:
- Type
- number
(static) parseInt(str, defaultValueopt)
Safely parse an integer.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
str |
string | String to parse. |
||
defaultValue |
number |
<optional> |
0 | Value to return on failure. Note this should be an integer, but it is not validated. |
(static) rollDice(sidesopt) → {number}
Get dice roll.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sides |
number |
<optional> |
6 | Number of sides on the dice. |
Returns:
- Type
- number
(static) shuffle(arr) → {Array.<*>}
Shuffle array. This uses Sattolo's algorithm to ensure every item is always in a new position. The original array IS modified. See Fisher Yates shuffle and Sattolo cycle
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array.<*> | The array to shuffle. |
Returns:
- Type
- Array.<*>
(static) sleep(ms) → {Promise}
Sleep for time.
Parameters:
| Name | Type | Description |
|---|---|---|
ms |
number | Period to sleep in milliseconds. |
Returns:
- Type
- Promise
(static) tossCoin() → {boolean}
Get coin toss.
Returns:
- Type
- boolean
Type Definitions
Coordinate
Properties:
| Name | Type | Description |
|---|---|---|
x |
number | |
y |
number |
Dimensions
Properties:
| Name | Type | Description |
|---|---|---|
width |
number | |
height |
number |
PositionData
Properties:
| Name | Type | Description |
|---|---|---|
x |
number | x position. |
y |
number | y - position. |
angle |
number | radians. |
RectData
Properties:
| Name | Type | Description |
|---|---|---|
x |
number | left position |
y |
number | top position |
width |
number | |
height |
number |