Methods
Rand(n) → {Uint8Array}
Rand returns a random byte slice of length n
Parameters:
Name | Type | Description |
---|---|---|
n | number | The length of the byte slice. |
Returns:
- The random byte slice.
- Type:
- Uint8Array
Example
let randbytes = Rand(10); // returns a random byte slice of length 10
RandInt() → {number}
RandInt returns a random int
Returns:
- The random integer.
- Type:
- number
Example
let myint = m.RandInt(); // returns a random int
ToBytes(…args) → {Uint8Array}
ToBytes converts given input to byte slice
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args | any | <repeatable> | The input to convert. |
Returns:
- The byte slice.
- Type:
- Uint8Array
Example
let mybytes = ToBytes("Hello World!"); // returns byte slice of "Hello World!"
ToString(…args) → {string}
ToString converts given input to string
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args | any | <repeatable> | The input to convert. |
Returns:
- The string.
- Type:
- string
Example
let mystr = ToString([0x48, 0x65, 0x6c, 0x6c, 0x6f]); // returns "Hello"
getNetworkPort(port, defaultPort) → {string}
getNetworkPort registers defaultPort and returns defaultPort if it is a colliding port with other protocols
Parameters:
Name | Type | Description |
---|---|---|
port | string | The port to check. |
defaultPort | string | The default port to return if the given port is colliding. |
Returns:
- The default port if the given port is colliding, otherwise the given port.
- Type:
- string
Example
let port = getNetworkPort(Port, "2843"); // 2843 is default port (even if 80,443 etc is given in Port from input)
isPortOpen(host, port, timeoutopt) → {boolean}
isPortOpen checks if given port is open on host. timeout is optional and defaults to 5 seconds
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
host | string | The host to check. | ||
port | string | The port to check. | ||
timeout | number | <optional> | 5 | The timeout in seconds. |
Returns:
- True if the port is open, false otherwise.
- Type:
- boolean
Example
let open = isPortOpen("localhost", "80"); // returns true if port 80 is open on localhost
let open = isPortOpen("localhost", "80", 10); // returns true if port 80 is open on localhost within 10 seconds
log(msg)
log prints given input to stdout with [JS] prefix for debugging purposes
Parameters:
Name | Type | Description |
---|---|---|
msg | string | | The message to print. |
Example
log("Hello World!");
log({"Hello": "World!"});