mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-20 21:16:38 +00:00
18 lines
365 B
TypeScript
18 lines
365 B
TypeScript
export function assertExists<TType>(
|
|
v: unknown,
|
|
message = `Value does not exist`
|
|
): asserts v is NonNullable<TType> {
|
|
if (typeof v === 'undefined') {
|
|
throw new Error(message)
|
|
}
|
|
}
|
|
|
|
export function assertTruthy<TType>(
|
|
v: unknown,
|
|
message = `Value should be truthy`
|
|
): asserts v is NonNullable<TType> {
|
|
if (!v) {
|
|
throw new Error(message)
|
|
}
|
|
}
|