-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequireNonEmptyString.ts
More file actions
20 lines (18 loc) · 714 Bytes
/
requireNonEmptyString.ts
File metadata and controls
20 lines (18 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { EmptyStringException } from "../../exception";
import { isEmpty, isString } from "../base";
/**
* Validates that the provided value is a non-empty string.
*
* @param {string | null | undefined} value - The string value to validate. Can be `null` or `undefined`.
* @param {string} [message] - Optional. A custom error message if the validation fails.
* @returns {string} The validated non-empty string.
* @throws {@link EmptyStringException}
* @since 1.0.0
* @version 1.0.0
*/
export function requireNonEmptyString(value: string | null | undefined, message?: string): string {
if (!isString(value) || isEmpty(value)) {
throw new EmptyStringException(message);
}
return value;
}