console¶
Provides basic console output, unit testing and time measuring functionality.
Module: none (built-in)
assert()¶
Lets the execution continue if the condition results in boolean true
. Stops execution and throws a runtime error if the condition results in boolean false
.
Signature:
assert( condition: boolean ): void
Parameters:
- condition:
boolean
Variable or an expression resulting in a boolean value.
Example:
let var1 = 3;
let var2 = 4;
console.assert(var1 < var2);
//continues execution
console.assert(var1 > var2);
//throws "Error: Assertion failed: console.assert", stops execution
count()¶
Counts up an internal counter on every function call and returns the counter value. Counters can be named through the name
function parameter. count()
also prints the counter name and the counter value to the console, unless disableOutput
is set to true
.
Signature:
count( name?: string, disableOutput?: boolean ): number
Parameters:
-
name:
string
, optionalCan serve as an identifier for differentiating between multiple counters.
-
disableOutput:
boolean
, optionalDisables the console output.
Return type: number
Example:
console.count();
console.count();
console.count("counterName");
//prints out:
//default: 1
//default: 2
//counterName: 1
countReset()¶
Resets a counter used previously with count()
.
Signature:
countReset( name?: string ): void
Parameters:
- name:
string
, optionalCan serve as an identifier for differentiating between multiple counters.
Example:
console.count();
console.count();
console.count('test');
console.countReset();
console.count();
//prints out:
//default: 1
//default: 2
//test: 1
//default: 1
debug()¶
Prints out a message to the console if MinLogLevel ≤1 is set in infinity.ini
Signature:
debug( msg: any ): void
Parameters:
- msg:
any
Data to print out.
Example:
console.debug("Process finished");
error()¶
Prints out a message to the console if MinLogLevel ≤3 is set in infinity.ini
Signature:
error( msg: any ): void
Parameters:
- msg:
any
Data to print out.
Example:
console.error("Process failed");
info()¶
Prints out a message to the console if MinLogLevel ≤1 is set in infinity.ini.
Signature:
info( msg: any ): void
Parameters:
- msg:
any
Data to print out.
Example:
console.info("Process running");
log()¶
Prints out a message to the console if MinLogLevel 0 is set in infinity.ini
Signature:
log( msg: any ): void
Parameters:
- msg:
any
Data to print out.
Example:
console.log("Process started");
readLn()¶
Halts the script execution and awaits user input. Returns the user input after the enter
button is pressed.
Signature:
readLn(): string;
Example:
let input = console.readLn();
table()¶
Prints out an ASCII-formatted table containing the passed data to the console.
Signature:
table( data: Array<any> ): void
Parameters:
- data:
Array<any>
Data to format. Every 1st-level array value adds a line. Values in multidimensional arrays add corresponding columns.
Example:
console.table(["Data1", ["Data2", "Data3"], "Data4"]);
//prints out:
// | (index) | 0 | 1 |
// +---------+-------+-------+
// | 0 | Data1 |
// | 1 | Data2 | Data3 |
// | 2 | Data4 |
time()¶
Starts a timer, measuring execution time since the function call. Timers can be named through the name
function parameter. See timeEnd()
for further information.
Signature:
time( name?: string ): void
Parameters:
- name:
string
, optionalCan serve as an identifier for differentiating between multiple timers.
Example:
console.time();
infinity.sleep(500);
console.timeEnd();
//default: 0,50797710s
timeSince()¶
Returns the measured time in nanoseconds since the call of time()
. timeSince()
also prints the timer name and the measured time to the console, unless disableOutput
is set to true
.
Signature:
timeSince( name?: string, disableOutput?: boolean ): number
Parameters:
-
name:
string
, optionalCan serve as an identifier for differentiating between multiple timers.
-
disableOutput:
boolean
, optionalDisables the console output.
Return type: number
Example:
console.time();
infinity.sleep(500);
console.timeSince();
//default: 0,50797710s
timeEnd()¶
Terminates the time measuring for the corresponding timer and returns the measured time in nanoseconds since the call of time()
. timeEnd()
also prints the timer name and the measured time to the console, unless disableOutput
is set to true
.
Signature:
timeEnd( name?: string, disableOutput?: boolean ): number
Parameters:
-
name:
string
, optionalCan serve as an identifier for differentiating between multiple timers.
-
disableOutput:
boolean
, optionalDisables the console output.
Return type: number
Example:
console.time();
infinity.sleep(500);
console.timeEnd();
//default: 0,50797710s
warn()¶
Prints out a message to the console if MinLogLevel ≤2 is set in infinity.ini
Signature:
warn( msg: any ): void
Parameters:
- msg:
any
Data to print out.
Example:
console.warn("Process ending");
write()¶
Writes the given string to the console.
Signature:
write(output: string): void;
Parameters:
- output:
string
The string to be written to the console.
Example:
console.write('Test');
console.write('Test');
//TestTest
writeLn()¶
Writes the given string to the console and starts a new line.
Signature:
writeLn(output: string): void;
Parameters:
- output:
string
The string to be written to the console.
Example:
console.writeLn('Test');
console.writeLn('Test');
//Test
//Test