UNPKG

@soil/arch

Version:

Architectural constructs for web applications.

50 lines 1.85 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Specialized type of error to easily identify exceptions originated in * `assert()` expressions. */ var AssertionError = /** @class */ (function (_super) { __extends(AssertionError, _super); function AssertionError() { return _super !== null && _super.apply(this, arguments) || this; } return AssertionError; }(Error)); /** * Ensure that a given condition is true, adding basic support for design-by- * contract programming. * * When providing a function as opposed to a boolean as the first argument, the * source code of the function will be included as part of the error message in * case of failure, providing immediate feedback to help determine the reason * why the assertion did not hold true. */ export function assert(assertion, message) { if (message === void 0) { message = ''; } var assertionIsFunction = typeof assertion === 'function'; var ok = assertionIsFunction ? assertion() : assertion; if (!ok) { if (assertionIsFunction) { if (message) { message += ' // '; } message += 'Assertion was: ' + assertion.toString(); } throw new AssertionError(message); } } //# sourceMappingURL=assert.js.map