Source: assert.js

  1. "use strict";
  2. let loggingFunction = console.error.bind(console);
  3. /**
  4. * If `truthy` is a truthy, returns that truthy without doing anything else. If it is
  5. * a falsy, returns it and displays the assertion message.
  6. *
  7. * @function assert
  8. *
  9. * @param truthy {Truthy|Falsy} The truthy to test.
  10. * @param message {String} The message to display with console.error() when `truthy` is a falsy.
  11. *
  12. * @return {Any} Returns truthy.
  13. */
  14. module.exports = (truthy, message) => {
  15. if (!truthy) {
  16. loggingFunction(message);
  17. }
  18. return truthy;
  19. };
  20. module.exports.setErrorLoggingFunction = λ => {
  21. loggingFunction = λ;
  22. };
  23. module.exports.getErrorLoggingFunction = () => {
  24. return loggingFunction;
  25. };