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