Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
guard
Browse files Browse the repository at this point in the history
  • Loading branch information
archywillhe committed Oct 4, 2023
1 parent 13d141d commit dd427cb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/insomnia/src/utils/guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Throw an error if the condition fails
// > Not providing an inline default argument for message as the result is smaller
export function guard(
condition: any,
// Can provide a string, or a function that returns a string for cases where
// the message takes a fair amount of effort to compute
message?: string | (() => string),
): asserts condition {
if (condition) {
return;
}
// Condition not passed

throw new Error(typeof message === 'function' ? message() : message);
}

0 comments on commit dd427cb

Please sign in to comment.