object/hasPath.jsjavascript
import { toPath } from '../_internal/path'

/**
 * 判断对象是否包含完整的自有属性路径。
 * @function hasPath
 * @memberof module:object
 * @param {Object} object 要检查的对象
 * @param {string|number|Array<string|number>} path 属性路径
 * @returns {boolean} 路径完整存在时为 true
 * @throws {TypeError} path 类型不正确时抛出
 */
function hasPath(object, path) {
  const parts = toPath(path)
  let current = object
  for (const part of parts) {
    if (current === null || current === undefined || !Object.prototype.hasOwnProperty.call(Object(current), part)) return false
    current = current[part]
  }
  return true
}

export default hasPath