@vitruvius-labs/ts-predicate
Version:
TypeScript predicates library
15 lines (14 loc) • 638 B
JavaScript
import { isDefined } from "../type-guard/is-defined.mjs";
import { assertNullableProperty } from "./assert-nullable-property.mjs";
import { itemAssertion } from "./utils/item-assertion.mjs";
import { ValidationError } from "./utils/validation-error.mjs";
function assertProperty(value, property, test) {
assertNullableProperty(value, property);
if (!isDefined(value[property])) {
throw new ValidationError(`The property "${property.toString()}" must not have a nullish value (undefined, null, or NaN).`);
}
if (test !== undefined) {
itemAssertion(value[property], test);
}
}
export { assertProperty };