ut2
Version:
一个现代 JavaScript 实用工具库。[点击查看在线文档]。
22 lines (19 loc) • 533 B
JavaScript
import isNil from '../isNil.js';
import toPath from '../toPath.js';
function hasPath(object, key, hasFunc) {
var paths = toPath(key, object);
var length = paths.length;
var index = 0;
var result = true;
while (!isNil(object) && index < length) {
var key_1 = paths[index];
result = hasFunc(object, key_1);
if (!result) {
break;
}
object = object[key_1];
index++;
}
return !!index && index === length && result;
}
export { hasPath as default };