mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-04-01 02:27:56 +03:00
Add conditional paremeters
This commit is contained in:
@@ -48,4 +48,13 @@ export function safeGet<V>(obj: Partial<Record<string, V>>, key: string, errorMe
|
||||
const value = obj[key];
|
||||
if (value === undefined) throw new Error(`Key '${key.toString()}' not found in object. Available keys: ${Object.keys(obj).join(', ')}.${errorMessage ? ` ${errorMessage}` : ''}`);
|
||||
return value;
|
||||
}
|
||||
|
||||
const prefix = 'Requirement not met';
|
||||
|
||||
export default function must(condition: unknown, message?: string | (() => string)): asserts condition {
|
||||
if (condition) return;
|
||||
const provided = typeof message === 'function' ? message() : message;
|
||||
const value = provided ? `${prefix}: ${provided}` : prefix;
|
||||
throw new Error(value);
|
||||
}
|
||||
Reference in New Issue
Block a user