2 * is-accessor-descriptor <https://github.com/jonschlinkert/is-accessor-descriptor>
4 * Copyright (c) 2015-2017, Jon Schlinkert.
5 * Released under the MIT License.
10 var typeOf = require('kind-of');
12 // accessor descriptor properties
16 configurable: 'boolean',
20 function isAccessorDescriptor(obj, prop) {
21 if (typeof prop === 'string') {
22 var val = Object.getOwnPropertyDescriptor(obj, prop);
23 return typeof val !== 'undefined';
26 if (typeOf(obj) !== 'object') {
30 if (has(obj, 'value') || has(obj, 'writable')) {
34 if (!has(obj, 'get') || typeof obj.get !== 'function') {
38 // tldr: it's valid to have "set" be undefined
39 // "set" might be undefined if `Object.getOwnPropertyDescriptor`
40 // was used to get the value, and only `get` was defined by the user
41 if (has(obj, 'set') && typeof obj[key] !== 'function' && typeof obj[key] !== 'undefined') {
45 for (var key in obj) {
46 if (!accessor.hasOwnProperty(key)) {
50 if (typeOf(obj[key]) === accessor[key]) {
54 if (typeof obj[key] !== 'undefined') {
61 function has(obj, key) {
62 return {}.hasOwnProperty.call(obj, key);
66 * Expose `isAccessorDescriptor`
69 module.exports = isAccessorDescriptor;