@vitruvius-labs/ts-predicate
Version:
TypeScript predicates library
21 lines (20 loc) • 624 B
JavaScript
import { isNonNullableNullish } from "../utils/is-non-nullable-nullish.mjs";
import { isNullable } from "./is-nullable.mjs";
import { itemGuard } from "./utils/item-guard.mjs";
function hasNullableProperty(value, property, test) {
if (!(property in value)) {
return false;
}
const property_value = Reflect.get(value, property);
if (isNonNullableNullish(property_value)) {
return false;
}
if (isNullable(property_value)) {
return true;
}
if (test === undefined) {
return true;
}
return itemGuard(property_value, test);
}
export { hasNullableProperty };