Option name | Type | Description |
---|---|---|
condition | Boolean |
|
errorMessage | String |
|
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);
}
}
Option name | Type | Description |
---|---|---|
condition | Boolean |
|
errorMessage | String |
|
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;