is-accessor-descriptor (1.0.1)

Published 2026-02-24 13:58:15 +00:00 by atheaadmin

Installation

registry=
npm install is-accessor-descriptor@1.0.1
"is-accessor-descriptor": "1.0.1"

About this package

is-accessor-descriptor Version Badge

github actions coverage License Downloads

npm badge

Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.

Examples

var isAccessor = require('is-accessor-descriptor');
var assert = require('assert');

assert.equal(isAccessor({ get: function() {} }), true);

You may also pass an object and property name to check if the property is an accessor:

assert.equal(isAccessor({ bar: {} }, 'bar'), true);

Examples

false when not an object

assert.equal(isAccessor('a'), false);
assert.equal(isAccessor(null), false);

true when the object has valid properties

and the properties all have the correct JavaScript types:

assert.equal(isAccessor({ get() {}, set() {} }), true);
assert.equal(isAccessor({ get() {} }), true);
assert.equal(isAccessor({ set() {} }), true);

false when the object has invalid properties

assert.equal(isAccessor({ get() {}, set() {}, enumerable: 'baz' }), false);
assert.equal(isAccessor({ get() {}, writable: true }), false);
assert.equal(isAccessor({ get() {}, value: true }), false);

false when an accessor is not a function

isAccessor({ get() {}, set: 'baz' });
isAccessor({ get: 'foo', set() {} });
isAccessor({ get: 'foo', bar: 'baz' });
isAccessor({ get: 'foo', set: 'baz' });
//=> false

false when a value is not the correct type

isAccessor({ get() {}, set() {}, enumerable: 'foo' });
isAccessor({ set() {}, configurable: 'foo' });
isAccessor({ get() {}, configurable: 'foo' });
//=> false

You might also be interested in these projects:

  • is-data-descriptor: Returns true if a value has the characteristics of a valid JavaScript data descriptor.
  • is-descriptor: Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… more
  • is-object: Returns true if the value is an object and not an array or null.

Tests

Simply clone the repo, npm install, and run npm test

Dependencies

Dependencies

ID Version
hasown ^2.0.0

Development Dependencies

ID Version
@ljharb/eslint-config ^21.1.0
aud ^2.0.3
auto-changelog ^2.4.0
eslint =8.8.0
evalmd ^0.0.19
in-publish ^2.0.1
npmignore ^0.3.0
nyc ^10.3.2
safe-publish-latest ^2.0.0
tape ^5.7.2

Keywords

descriptor get getter is keys object properties property set setter type valid value
Details
npm
2026-02-24 13:58:15 +00:00
0
Jon Schlinkert
MIT
latest
6.9 KiB
Assets (1)
Versions (1) View all
1.0.1 2026-02-24