@onesy/utils
Version:
19 lines (16 loc) • 589 B
JavaScript
import is from './is';
import castParam from './castParam';
export const hasObjectPropertyValue = (object, keys) => {
if (!object || !keys) return false;
if (is('string', keys)) {
const keys_ = keys.split('.').filter(Boolean).map(key => castParam(key));
return hasObjectPropertyValue(object, keys_);
}
if (is('array', keys)) {
const key = keys[0];
if (keys.length === 1) return object.hasOwnProperty(key);
if (object.hasOwnProperty(key)) return hasObjectPropertyValue(object[key], keys.slice(1));
}
return false;
};
export default hasObjectPropertyValue;