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