import { isNonEmptyString } from './typeguards' ; export class Asserts { static isPresent < T > ( v , msgOrErrorFactory ? ) { if ( v === null || v == undefined ) { throw Asserts . createException ( msgOrErrorFactory , 'Value is null or undefined.' ) ; } } static safeInteger ( v , msgOrErrorFactory ? ) { if ( typeof v !== 'number' || ! Number . isSafeInteger ( v ) ) { throw Asserts . createException ( msgOrErrorFactory , 'Value is not a safe integer' ) ; } } static nonEmptyString ( v , msgOrErrorFactory ? , /** auto-trim, default true */ trim ? ) { if ( ! isNonEmptyString ( v , trim ?? true ) ) { throw Asserts . createException ( msgOrErrorFactory ) ; } } static never ( v , msg ? ) { throw new Error ( msg ?? 'Unexpected value' ) ; } private static createException ( msgOrErrorFactory ? , fallbackMsg ? ) { if ( typeof msgOrErrorFactory === 'string' || msgOrErrorFactory === undefined ) { throw new Error ( msgOrErrorFactory ?? fallbackMsg ?? 'Assertion did not pass.' ) ; } throw msgOrErrorFactory ( ) ; } }