@vitruvius-labs/ts-predicate
Version:
TypeScript predicates library
16 lines (15 loc) • 762 B
JavaScript
import { assertNullishProperty } from "../extended/nullish/predicate/type-assertion/assert-nullish-property.mjs";
import { isNullish } from "../extended/nullish/predicate/type-guard/is-nullish.mjs";
import { itemAssertion } from "./utils/item-assertion.mjs";
import { ValidationError } from "./utils/validation-error.mjs";
function assertProperty(value, property, test) {
assertNullishProperty(value, property);
const scoped_value = Reflect.get(value, property);
if (isNullish(scoped_value)) {
throw new ValidationError(`The property "${property.toString()}" must not have a nullish value (undefined, null, NaN, or NoValue).`);
}
if (test !== undefined) {
itemAssertion(scoped_value, test);
}
}
export { assertProperty };