mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Simplify has and hasIn.
This commit is contained in:
19
hasIn.js
19
hasIn.js
@@ -1,15 +1,12 @@
|
||||
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
|
||||
* @param {string} key The key to check.
|
||||
* @returns {boolean} Returns `true` if `key` exists, else `false`.
|
||||
* @see has, hasPath, hasPathIn
|
||||
* @example
|
||||
*
|
||||
* const object = create({ 'a': create({ 'b': 2 }) })
|
||||
@@ -17,17 +14,11 @@ import hasPath from './.internal/hasPath.js'
|
||||
* 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)
|
||||
function hasIn(object, key) {
|
||||
return object != null && key in Object(object)
|
||||
}
|
||||
|
||||
export default hasIn
|
||||
|
||||
Reference in New Issue
Block a user