Нет описания

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. * is-data-descriptor <https://github.com/jonschlinkert/is-data-descriptor>
  3. *
  4. * Copyright (c) 2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. var typeOf = require('kind-of');
  9. // data descriptor properties
  10. var data = {
  11. configurable: 'boolean',
  12. enumerable: 'boolean',
  13. writable: 'boolean'
  14. };
  15. function isDataDescriptor(obj, prop) {
  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. }
  40. /**
  41. * Expose `isDataDescriptor`
  42. */
  43. module.exports = isDataDescriptor;