Assert

assert

function
assert()

Option name Type Description
condition Boolean
  • Result of the evaluated condition
errorMessage String
  • Message explainig the error in case it is thrown
return

void

Throws an error if the boolean passed to it evaluates to false.
To be used like this:

        assert(myDate !== undefined, "Date cannot be undefined.");
function assert(condition, errorMessage) {
  const error = processCondition(condition, errorMessage);
  if (typeof error === 'string') {
    throw new Error(error);
  }
}

warn

method
assert.warn()

Option name Type Description
condition Boolean
  • Result of the evaluated condition
errorMessage String
  • Message explainig the error in case it is thrown
return

void

Logs a warning if the boolean passed to it evaluates to false.
To be used like this:

        assert.warn(myDate !== undefined, "No date provided.");
assert.warn = function warn(condition, errorMessage) {
  const error = processCondition(condition, errorMessage);
  if (typeof error === 'string') {
    console.warn(error);
  }
};

export default assert;