@itwin/core-bentley
Version:
Bentley JavaScript core components
37 lines • 1.59 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/**
* Expects that a value is defined (not undefined).
* @note Almost always, places that use this function should in the future be cleaned up to properly
* handle undefined values instead of throwing an error.
* @param value The value to check.
* @param message Optional error message to be used in thrown Error.
* @returns The original value if it is defined.
* @throws Error if the value is undefined.
* @internal
*/
export function expectDefined(value, message) {
if (value === undefined) {
throw new Error(message ?? "Expected value to be defined, but it was undefined.");
}
return value;
}
/**
* Expects that a value is not null.
* @note Almost always, places that use this function should in the future be cleaned up to properly
* handle null values instead of throwing an error.
* @param value The value to check.
* @param message Optional error message to be used in thrown Error.
* @returns The original value if it is not null.
* @throws Error if the value is null.
* @internal
*/
export function expectNotNull(value, message) {
if (value === null) {
throw new Error(message ?? "Expected value to be not null, but it was null.");
}
return value;
}
//# sourceMappingURL=Expect.js.map