@vitruvius-labs/ts-predicate
Version:
TypeScript predicates library
17 lines (16 loc) • 492 B
JavaScript
import { isNullish } from "../extended/nullish/predicate/type-guard/is-nullish.mjs";
import { itemGuard } from "./utils/item-guard.mjs";
function hasProperty(value, property, test) {
if (!(property in value)) {
return false;
}
const property_value = Reflect.get(value, property);
if (isNullish(property_value)) {
return false;
}
if (test === undefined) {
return true;
}
return itemGuard(property_value, test);
}
export { hasProperty };