acebase/src/assert.ts
2022-12-05 13:06:08 +01:00

10 lines
298 B
TypeScript

/**
* Replacement for console.assert, throws an error if condition is not met.
* @param condition 'truthy' condition
* @param error
*/
export function assert(condition: any, error?: string) {
if (!condition) {
throw new Error(`Assertion failed: ${error ?? 'check your code'}`);
}
}