assert.js 464 B

1234567891011121314151617
  1. /**
  2. * @fileoverview Assertion utilities.
  3. * @author Nicholas C. Zakas
  4. */
  5. /**
  6. * Throws an error if the given condition is not truthy.
  7. * @param {boolean} condition The condition to check.
  8. * @param {string} message The message to include with the error.
  9. * @returns {void}
  10. * @throws {Error} When the condition is not truthy.
  11. */
  12. export function assert(condition, message = "Assertion failed.") {
  13. if (!condition) {
  14. throw new Error(message);
  15. }
  16. }