mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Bump to v3.7.0.
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
import baseGet from '../internal/baseGet';
|
||||
import baseSlice from '../internal/baseSlice';
|
||||
import isKey from '../internal/isKey';
|
||||
import last from '../array/last';
|
||||
import toPath from '../internal/toPath';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
@@ -5,24 +11,39 @@ var objectProto = Object.prototype;
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Checks if `key` exists as a direct property of `object` instead of an
|
||||
* inherited property.
|
||||
* Checks if `path` is a direct property.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Object
|
||||
* @param {Object} object The object to inspect.
|
||||
* @param {string} key The key to check.
|
||||
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
|
||||
* @param {Object} object The object to query.
|
||||
* @param {Array|string} path The path to check.
|
||||
* @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'a': 1, 'b': 2, 'c': 3 };
|
||||
* var object = { 'a': { 'b': { 'c': 3 } } };
|
||||
*
|
||||
* _.has(object, 'b');
|
||||
* _.has(object, 'a');
|
||||
* // => true
|
||||
*
|
||||
* _.has(object, 'a.b.c');
|
||||
* // => true
|
||||
*
|
||||
* _.has(object, ['a', 'b', 'c']);
|
||||
* // => true
|
||||
*/
|
||||
function has(object, key) {
|
||||
return object ? hasOwnProperty.call(object, key) : false;
|
||||
function has(object, path) {
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
var result = hasOwnProperty.call(object, path);
|
||||
if (!result && !isKey(path)) {
|
||||
path = toPath(path);
|
||||
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
||||
path = last(path);
|
||||
result = object != null && hasOwnProperty.call(object, path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default has;
|
||||
|
||||
Reference in New Issue
Block a user