export function assert(b, msg = 'Assertion failed') {
    if (!b) {
        throw new Error(typeof msg === 'string' ? msg : msg());
    }
}
export function assertString(v) {
    assertType(v, 'string');
}
export function assertNumber(v) {
    assertType(v, 'number');
}
export function assertBoolean(v) {
    assertType(v, 'boolean');
}
function assertType(v, t) {
    if (typeof v !== t) {
        throwInvalidType(v, t);
    }
}
export function assertObject(v) {
    if (v === null) {
        throwInvalidType(v, 'object');
    }
    assertType(v, 'object');
}
export function assertArray(v) {
    if (!Array.isArray(v)) {
        throwInvalidType(v, 'array');
    }
}
export function invalidType(v, t) {
    let s = 'Invalid type: ';
    if (v === null || v === undefined) {
        s += v;
    }
    else {
        s += `${typeof v} \`${v}\``;
    }
    return s + `, expected ${t}`;
}
export function throwInvalidType(v, t) {
    throw new Error(invalidType(v, t));
}
export function assertNotNull(v) {
    if (v === null) {
        throw new Error('Expected non-null value');
    }
}
export function assertUndefined(v, msg = 'Expected undefined value') {
    if (v !== undefined) {
        throw new Error(msg);
    }
}
export function assertNotUndefined(v, msg = 'Expected non undefined value') {
    if (v === undefined) {
        throw new Error(msg);
    }
}
export function assertInstanceof(v, t) {
    if (!(v instanceof t)) {
        throw new Error(`Expected instanceof ${t.name}`);
    }
}
export function assertUint8Array(v) {
    assertInstanceof(v, Uint8Array);
}
export function unreachable(_) {
    throw new Error('Unreachable');
}
export function notImplemented() {
    throw new Error('Not implemented');
}
//# sourceMappingURL=asserts.js.map