-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequireNonNull.ts
More file actions
23 lines (21 loc) · 707 Bytes
/
requireNonNull.ts
File metadata and controls
23 lines (21 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { NullPointerException } from "../../exception";
import { isNil } from "./isNil";
/**
* Ensures that the provided object is not `null` or `undefined`.
*
* @template T - The type of the object being checked.
* @param {T | null | undefined} value the object to validate.
* @param {string} [message]
* @returns {T} The same object, guaranteed to be non-null and non-undefined.
* @throws {NullPointerException}
* @see {@link nonNull}
* @see {@link isNull}
* @since 1.0.0
* @version 1.0.0
*/
export function requireNonNull<T>(value?: T | null | undefined, message?: string): T {
if (isNil(value)) {
throw new NullPointerException(message);
}
return value;
}