mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
34 lines
753 B
JavaScript
34 lines
753 B
JavaScript
import baseHasIn from './.internal/baseHasIn.js'
|
|
import hasPath from './.internal/hasPath.js'
|
|
|
|
/**
|
|
* Checks if `path` is a direct or inherited property of `object`.
|
|
*
|
|
* @since 4.0.0
|
|
* @category Object
|
|
* @param {Object} object The object to query.
|
|
* @param {Array|string} path The path to check.
|
|
* @returns {boolean} Returns `true` if `path` exists, else `false`.
|
|
* @see has, get, set, unset
|
|
* @example
|
|
*
|
|
* const object = create({ 'a': create({ 'b': 2 }) })
|
|
*
|
|
* hasIn(object, 'a')
|
|
* // => true
|
|
*
|
|
* hasIn(object, 'a.b')
|
|
* // => true
|
|
*
|
|
* hasIn(object, ['a', 'b'])
|
|
* // => true
|
|
*
|
|
* hasIn(object, 'b')
|
|
* // => false
|
|
*/
|
|
function hasIn(object, path) {
|
|
return object != null && hasPath(object, path, baseHasIn)
|
|
}
|
|
|
|
export default hasIn
|