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