Functions

Rand(n) ⇒ Uint8Array

Rand returns a random byte slice of length n

Kind: global function
Returns: Uint8Array - - The random byte slice.

ParamTypeDescription
nnumberThe length of the byte slice.

Example

let randbytes = Rand(10); // returns a random byte slice of length 10

RandInt() ⇒ number

RandInt returns a random int

Kind: global function
Returns: number - - The random integer.
Example

let myint = m.RandInt(); // returns a random int

log(msg)

log prints given input to stdout with [JS] prefix for debugging purposes

Kind: global function

ParamTypeDescription
msgstring | ObjectThe message to print.

Example

log("Hello World!");
log({"Hello": "World!"});

getNetworkPort(port, defaultPort) ⇒ string

getNetworkPort registers defaultPort and returns defaultPort if it is a colliding port with other protocols

Kind: global function
Returns: string - - The default port if the given port is colliding, otherwise the given port.

ParamTypeDescription
portstringThe port to check.
defaultPortstringThe default port to return if the given port is colliding.

Example

let port = getNetworkPort(Port, "2843"); // 2843 is default port (even if 80,443 etc is given in Port from input)

isPortOpen(host, port, [timeout]) ⇒ boolean

isPortOpen checks if given port is open on host. timeout is optional and defaults to 5 seconds

Kind: global function
Returns: boolean - - True if the port is open, false otherwise.

ParamTypeDefaultDescription
hoststringThe host to check.
portstringThe port to check.
[timeout]number5The timeout in seconds.

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

ToBytes(…args) ⇒ Uint8Array

ToBytes converts given input to byte slice

Kind: global function
Returns: Uint8Array - - The byte slice.

ParamTypeDescription
…argsanyThe input to convert.

Example

let mybytes = ToBytes("Hello World!"); // returns byte slice of "Hello World!"

ToString(…args) ⇒ string

ToString converts given input to string

Kind: global function
Returns: string - - The string.

ParamTypeDescription
…argsanyThe input to convert.

Example

let mystr = ToString([0x48, 0x65, 0x6c, 0x6c, 0x6f]); // returns "Hello"