isKey.cjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. // @ts-nocheck
  7. const isSymbol_js_1 = __importDefault(require("./isSymbol.cjs"));
  8. /** Used to match property names within property paths. */
  9. const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
  10. const reIsPlainProp = /^\w*$/;
  11. /**
  12. * Checks if `value` is a property name and not a property path.
  13. *
  14. * @private
  15. * @param {*} value The value to check.
  16. * @param {Object} [object] The object to query keys on.
  17. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  18. */
  19. function isKey(value, object) {
  20. if (Array.isArray(value)) {
  21. return false;
  22. }
  23. const type = typeof value;
  24. if (type === "number" ||
  25. type === "boolean" ||
  26. value == null ||
  27. (0, isSymbol_js_1.default)(value)) {
  28. return true;
  29. }
  30. return (reIsPlainProp.test(value) ||
  31. !reIsDeepProp.test(value) ||
  32. (object != null && value in Object(object)));
  33. }
  34. exports.default = isKey;