Registry / serialization / is-accessor-descriptor

is-accessor-descriptor

JSON →
library3.0.5jsnpmunverified

The `is-accessor-descriptor` package provides a focused utility function to determine if a given JavaScript value, or a property on an object, represents a valid accessor property descriptor. It specifically checks for the presence of `get` and/or `set` properties and ensures they are functions, while rejecting `value` or `writable` properties which characterize data descriptors. Currently at version 3.0.5, this package is part of a family of descriptor-checking utilities under the `inspect-js` scope, emphasizing foundational JavaScript introspection. Its release cadence is stable and infrequent, reflecting its role as a fundamental helper. It differentiates itself by its precise focus, allowing developers to isolate and validate accessor descriptors without conflating them with other descriptor types, making it a reliable tool for metaprogramming and object property manipulation.

npm install is-accessor-descriptor
INSTALL
IMPORT
SIG · IS-ACCESSOR-DESCRI
I
is-accessor-descriptor
serializationjavascriptv3.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isAccessorDescriptor
const isAccessorDescriptor = require('is-accessor-descriptor');
import { isAccessorDescriptor } from 'is-accessor-descriptor';
This package is primarily a CommonJS module. While modern Node.js and bundlers can typically import CJS modules using `import`, it is exported as a default. Attempting a named import (`import { isAccessorDescriptor }`) will result in `undefined` because no named exports are explicitly defined.
isAccessorDescriptor (ESM Interop)
import isAccessorDescriptor from 'is-accessor-descriptor';
import { isAccessorDescriptor } from 'is-accessor-descriptor';
In an ES Module (ESM) environment (e.g., a file with `"type": "module"` in `package.json` or `.mjs` extension), this is the correct way to import the default CommonJS export. Node.js's CJS-ESM interop will treat the `module.exports` as the default import. Named imports will generally fail.

This example demonstrates how to use `is-accessor-descriptor` to verify if an object's property (by passing the object and key) or a pre-obtained descriptor object is a valid JavaScript accessor descriptor.

const isAccessorDescriptor = require('is-accessor-descriptor'); const assert = require('assert'); const obj = { // An accessor property get foo() { return 'bar'; }, // A data property containing an object with a 'get' key, not an accessor descriptor bar: { get: function() { return 'baz'; } } }; // Check a property by its descriptor on an object assert.equal(true, isAccessorDescriptor(obj, 'foo'), 'obj.foo should be an accessor descriptor'); assert.equal(false, isAccessorDescriptor(obj, 'bar'), 'obj.bar should NOT be an accessor descriptor'); // Alternatively, if you already have the descriptor object const fooDescriptor = Object.getOwnPropertyDescriptor(obj, 'foo'); assert.equal(true, isAccessorDescriptor(fooDescriptor), 'fooDescriptor should be an accessor descriptor'); const barDescriptor = Object.getOwnPropertyDescriptor(obj, 'bar'); assert.equal(false, isAccessorDescriptor(barDescriptor), 'barDescriptor should NOT be an accessor descriptor'); console.log('All assertions passed: is-accessor-descriptor works as expected!');
Debug
Known issues
gotchaThis package is implemented as a CommonJS module. When consuming it in an ES Module (ESM) environment, it must be imported as a default export using `import isAccessorDescriptor from 'is-accessor-descriptor';`. Attempting to use named imports (e.g., `import { isAccessorDescriptor } from 'is-accessor-descriptor';`) will typically result in `isAccessorDescriptor` being `undefined` or a runtime error in strict ESM contexts.
fix
Ensure your import statement correctly handles the CJS default export: `import isAccessorDescriptor from 'is-accessor-descriptor';` for ESM, or `const isAccessorDescriptor = require('is-accessor-descriptor');` for CJS.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: isAccessorDescriptor is not a function
This error most commonly occurs when attempting to call `isAccessorDescriptor` after incorrectly importing it as a named export in an ES Module environment (e.g., `import { isAccessorDescriptor } from 'is-accessor-descriptor';`). Since the package provides a default CJS export, the named import fails to resolve the function.
fix
Adjust your import statement to `import isAccessorDescriptor from 'is-accessor-descriptor';` if in ESM, or `const isAccessorDescriptor = require('is-accessor-descriptor');` if in CJS.
ReferenceError: require is not defined
This error indicates that you are attempting to use the CommonJS `require()` function within an ES Module file. ES Modules do not inherently expose `require`.
fix
If your file is an ES Module (e.g., `.mjs` or `"type": "module"` in `package.json`), you must use the ESM import syntax: `import isAccessorDescriptor from 'is-accessor-descriptor';`.
Upgrade
Version history
3.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
is-accessor-descriptor — npm install is-accessor-descriptor · libregistry