Created
May 22, 2024 01:18
-
-
Save roine/0a5829cc4ff58fcfb259dd1ab63d02cc to your computer and use it in GitHub Desktop.
Custom version of invariant, removes the invariant frame from the call stack
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 characters
function invariant(condition, message, a, b, c, d, e, f) { | |
if (!condition) { | |
var error; | |
var args = [a, b, c, d, e, f]; | |
var argIndex = 0; | |
error = new Error( | |
message.replace(/%s/g, function () { | |
return args[argIndex++]; | |
}) | |
); | |
error.name = "Invariant Violation"; | |
// remove this frame from the stack | |
var arr = error.stack.split("\n"); | |
error.stack = [arr[0]].concat(arr.slice(2)).join("\n"); | |
throw error; | |
} | |
return condition; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment