Created
June 25, 2018 00:32
-
-
Save blaswan/6b11a5ac0dca81485b8587e978bc88a4 to your computer and use it in GitHub Desktop.
Revisions
-
blaswan created this gist
Jun 25, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ export const assert = (condition: boolean, messageOrError?: string | Error) => { if (!condition) { if (typeof messageOrError === "string" || typeof messageOrError === "undefined") { const message = messageOrError || "Assertion failed"; if (typeof Error !== "undefined") { throw new Error(message); } } else { throw messageOrError; } } }; // pass specific error // assert(url, new ValidationError("Required value missing: url")); // or pass only message // assert(url, "Required value missing: url");