/ cloudformation-templates / node_modules / class-utils / node_modules / is-data-descriptor / index.js
index.js
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 8 'use strict'; 9 10 var typeOf = require('kind-of'); 11 12 // data descriptor properties 13 var data = { 14 configurable: 'boolean', 15 enumerable: 'boolean', 16 writable: 'boolean' 17 }; 18 19 function isDataDescriptor(obj, prop) { 20 if (typeOf(obj) !== 'object') { 21 return false; 22 } 23 24 if (typeof prop === 'string') { 25 var val = Object.getOwnPropertyDescriptor(obj, prop); 26 return typeof val !== 'undefined'; 27 } 28 29 if (!('value' in obj) && !('writable' in obj)) { 30 return false; 31 } 32 33 for (var key in obj) { 34 if (key === 'value') continue; 35 36 if (!data.hasOwnProperty(key)) { 37 continue; 38 } 39 40 if (typeOf(obj[key]) === data[key]) { 41 continue; 42 } 43 44 if (typeof obj[key] !== 'undefined') { 45 return false; 46 } 47 } 48 return true; 49 } 50 51 /** 52 * Expose `isDataDescriptor` 53 */ 54 55 module.exports = isDataDescriptor;