index.js 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*!
  2. * is-data-descriptor <https://github.com/jonschlinkert/is-data-descriptor>
  3. *
  4. * Copyright (c) 2015-2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var typeOf = require('kind-of');
  9. module.exports = function isDataDescriptor(obj, prop) {
  10. // data descriptor properties
  11. var data = {
  12. configurable: 'boolean',
  13. enumerable: 'boolean',
  14. writable: 'boolean'
  15. };
  16. if (typeOf(obj) !== 'object') {
  17. return false;
  18. }
  19. if (typeof prop === 'string') {
  20. var val = Object.getOwnPropertyDescriptor(obj, prop);
  21. return typeof val !== 'undefined';
  22. }
  23. if (!('value' in obj) && !('writable' in obj)) {
  24. return false;
  25. }
  26. for (var key in obj) {
  27. if (key === 'value') continue;
  28. if (!data.hasOwnProperty(key)) {
  29. continue;
  30. }
  31. if (typeOf(obj[key]) === data[key]) {
  32. continue;
  33. }
  34. if (typeof obj[key] !== 'undefined') {
  35. return false;
  36. }
  37. }
  38. return true;
  39. };