MilkScript

Automate tasks with MilkScript.

menu

console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.


error(...values)

Outputs an error message to the Execution Log. See console.log for more details.

Parameters

...values

A variable number of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed.

Return value

undefined


info(...values)

Outputs a message to the Execution Log. See console.log for more details.

Parameters

...values

A variable number of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed.

Return value

undefined


log(...values)

Outputs a message to the Execution Log. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.

If the first argument is a JavaScript string containing zero or more substitution strings, then it is used as the primary message and all additional arguments used as substitution values.

The following substitution strings are supported:

  • %s - Outputs a string.
  • %d - Outputs a number.
  • %j - Outputs JSON. Replaced with the string [Circular] if the argument contains circular references.
  • %% - Outputs a single percent sign %. This does not consume an argument.

Parameters

...values

A variable number of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed.

Return value

undefined

Example

// Outputs the number of tasks completed this year.
const now = new Date();
const tasks = rtm.getTasks(`completedAfter:"1 January ${now.getFullYear()}"`);

if (tasks.length === 1) {
    console.log('You have completed 1 task this year.');
} else {
    console.log('You have completed %d tasks this year.', tasks.length);
}

time(label)

Starts a timer that can be used to compute the duration of an operation. Timers are identified by a unique label. Use the same label when calling console.timeEnd to stop the timer and output the elapsed time in suitable time units to the Execution Log.

Parameters

labelOptional

The optional label of the timer to start.

Return value

undefined

Example

// Outputs how long it takes to find all prime numbers in the range from 1 to 750.
function isPrime(n) {
  if (n === 1 || n === 0) {
    return false;
  }

  for (let i = 2; i < n; ++i) {
    if (n % i === 0) {
      return false;
    }
  }

  return true;
}

const primeNumbers = [];

console.time('Elapsed Time');

for (let i = 1; i <= 750; ++i) {
  if (isPrime(i)) {
    primeNumbers.push(i);
  }
}

console.log('Found %d prime numbers.', primeNumbers.length);
console.timeEnd('Elapsed Time');

timeEnd(label)

Stops a timer that was previously started by calling console.time and prints the result to the Execution Log.

Parameters

labelOptional

The optional label of the timer to stop.

Return value

undefined


warn(...values)

Outputs a warning to the Execution Log. See console.log for more details.

Parameters

...values

A variable number of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed.

Return value

undefined