Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / isKey.js
1 var isArray = require('../lang/isArray'),
2     toObject = require('./toObject');
3
4 /** Used to match property names within property paths. */
5 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
6     reIsPlainProp = /^\w*$/;
7
8 /**
9  * Checks if `value` is a property name and not a property path.
10  *
11  * @private
12  * @param {*} value The value to check.
13  * @param {Object} [object] The object to query keys on.
14  * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
15  */
16 function isKey(value, object) {
17   var type = typeof value;
18   if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
19     return true;
20   }
21   if (isArray(value)) {
22     return false;
23   }
24   var result = !reIsDeepProp.test(value);
25   return result || (object != null && value in toObject(object));
26 }
27
28 module.exports = isKey;