Methods

Rand(n) → {Uint8Array}

Rand returns a random byte slice of length n
Parameters:
NameTypeDescription
nnumberThe 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:
NameTypeAttributesDescription
argsany<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:
NameTypeAttributesDescription
argsany<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:
NameTypeDescription
portstringThe port to check.
defaultPortstringThe 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:
NameTypeAttributesDefaultDescription
hoststringThe host to check.
portstringThe port to check.
timeoutnumber<optional>
5The 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:
NameTypeDescription
msgstring | ObjectThe message to print.
Example
log("Hello World!");
log({"Hello": "World!"});