UNPKG

@breeffy/invariants

Version:
22 lines 1.3 kB
function assertCondition(condition, message = '', prefix = '') { if (!condition) { throw new Error(`${prefix}${message}`); } } /** * @param condition If it's `falsy` - exception will be thrown, otherwise TypeScript asserts condition. See [Assertion Functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions). * @param message Error message to use if exception will be thrown. Default is `""`. * @param prefix Prefix string to use before error message if exception will be thrown. Default is `"[assert] "`. */ export function assert(condition, message, prefix = '[assert] ') { assertCondition(condition, message, prefix); } /** * @param condition If it's `falsy` - exception will be thrown, otherwise TypeScript asserts condition. See [Assertion Functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions). * @param message Error message to use if exception will be thrown. Default is `""`. * @param prefix Prefix string to use before error message if exception will be thrown. Default is `"[invariant] "`. */ export function invariant(condition, message, prefix = '[invariant] ') { assertCondition(condition, message, prefix); } //# sourceMappingURL=invariants.js.map