mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-26 15:47:40 +03:00
merged with main
This commit is contained in:
18
src/utils/invariant.ts
Normal file
18
src/utils/invariant.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export function invariant<T = unknown>(
|
||||
condition: T,
|
||||
errorMessage?: ((condition: T) => string) | string,
|
||||
): asserts condition {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof errorMessage === 'undefined') {
|
||||
throw new Error('Invariant failed');
|
||||
}
|
||||
|
||||
if (typeof errorMessage === 'string') {
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
throw new Error(errorMessage(condition));
|
||||
}
|
||||
Reference in New Issue
Block a user