Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
const isAccessorDescriptor = require('is-accessor-descriptor');
const assert = require('assert');
const obj = {
get foo() {},
bar: { get: function() {} }
};
assert.equal(true, isAccessorDescriptor(obj, 'foo'));
assert.equal(false, isAccessorDescriptor(obj, 'bar'));
// or, if you already have the descriptor you can pass it directly
const foo = Object.getOwnPropertyDescriptor(obj, 'foo');
assert.equal(true, isAccessorDescriptor(foo));
const bar = Object.getOwnPropertyDescriptor(obj, 'bar');
assert.equal(false, isAccessorDescriptor(bar));
You might also be interested in these projects:
Simply clone the repo, npm install
, and run npm test