f208f8a01bef13ba7043d1f3bc875c6ad9c321d9
[platform/framework/web/crosswalk-tizen.git] /
1 var baseGet = require('../internal/baseGet'),
2     baseSlice = require('../internal/baseSlice'),
3     isKey = require('../internal/isKey'),
4     last = require('../array/last'),
5     toPath = require('../internal/toPath');
6
7 /** Used for native method references. */
8 var objectProto = Object.prototype;
9
10 /** Used to check objects for own properties. */
11 var hasOwnProperty = objectProto.hasOwnProperty;
12
13 /**
14  * Checks if `path` is a direct property.
15  *
16  * @static
17  * @memberOf _
18  * @category Object
19  * @param {Object} object The object to query.
20  * @param {Array|string} path The path to check.
21  * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
22  * @example
23  *
24  * var object = { 'a': { 'b': { 'c': 3 } } };
25  *
26  * _.has(object, 'a');
27  * // => true
28  *
29  * _.has(object, 'a.b.c');
30  * // => true
31  *
32  * _.has(object, ['a', 'b', 'c']);
33  * // => true
34  */
35 function has(object, path) {
36   if (object == null) {
37     return false;
38   }
39   var result = hasOwnProperty.call(object, path);
40   if (!result && !isKey(path)) {
41     path = toPath(path);
42     object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
43     path = last(path);
44     result = object != null && hasOwnProperty.call(object, path);
45   }
46   return result;
47 }
48
49 module.exports = has;