Ad documentation for enforce
This commit is contained in:
parent
2b3dd9b859
commit
22923855f9
1 changed files with 8 additions and 0 deletions
|
@ -4,6 +4,14 @@
|
|||
|
||||
import { getGameSafe } from "./helpers";
|
||||
|
||||
/**
|
||||
* Tests if the given `value` is truthy.
|
||||
*
|
||||
* If it is not truthy, an {@link Error} is thrown, which depends on the given `message` parameter:
|
||||
* - If `message` is a string`, it is used to construct a new {@link Error} which then is thrown.
|
||||
* - If `message` is an instance of {@link Error}, it is thrown.
|
||||
* - If `message` is `undefined`, an {@link Error} with a default message is thrown.
|
||||
*/
|
||||
export function enforce(value: unknown, message?: string | Error): asserts value {
|
||||
if (!value) {
|
||||
if (!message) {
|
||||
|
|
Loading…
Reference in a new issue