Source: assert.js

  1. /**
  2. * @file Assert functions.
  3. * @version March 26, 2017
  4. *
  5. * @author Olivier Pirson --- http://www.opimedia.be/
  6. * @license GPLv3 --- Copyright (C) 2017 Olivier Pirson
  7. */
  8. /**
  9. * Returns true iff assertions are enabled
  10. * iff window.ASSERT_ENABLED is defined.
  11. *
  12. * @returns {boolean}
  13. */
  14. function isAssert() {
  15. "use strict";
  16. return (window.ASSERT_ENABLED !== undefined);
  17. }
  18. /**
  19. * Assertion function.
  20. *
  21. * If its first parameter is true
  22. * then does nothing,
  23. * else prints to the console next parameters.
  24. *
  25. * If !isAssert()
  26. * then always does nothing.
  27. */
  28. let assert = function () {};
  29. if (isAssert()) {
  30. console.log("Assertions enabled!");
  31. assert = console.assert; // https://developer.mozilla.org/en-US/docs/Web/API/Console/assert
  32. }