{"id":12740,"library":"is-accessor-descriptor","title":"JavaScript Accessor Descriptor Checker","description":"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.","status":"active","version":"3.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/inspect-js/is-accessor-descriptor","tags":["javascript","accessor","check","data","descriptor","get","getter","is","keys"],"install":[{"cmd":"npm install is-accessor-descriptor","lang":"bash","label":"npm"},{"cmd":"yarn add is-accessor-descriptor","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-accessor-descriptor","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { isAccessorDescriptor } from 'is-accessor-descriptor';","symbol":"isAccessorDescriptor","correct":"const isAccessorDescriptor = require('is-accessor-descriptor');"},{"note":"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.","wrong":"import { isAccessorDescriptor } from 'is-accessor-descriptor';","symbol":"isAccessorDescriptor (ESM Interop)","correct":"import isAccessorDescriptor from 'is-accessor-descriptor';"}],"quickstart":{"code":"const isAccessorDescriptor = require('is-accessor-descriptor');\nconst assert = require('assert');\n\nconst obj = {\n\t// An accessor property\n\tget foo() { return 'bar'; },\n\t// A data property containing an object with a 'get' key, not an accessor descriptor\n\tbar: { get: function() { return 'baz'; } }\n};\n\n// Check a property by its descriptor on an object\nassert.equal(true, isAccessorDescriptor(obj, 'foo'), 'obj.foo should be an accessor descriptor');\nassert.equal(false, isAccessorDescriptor(obj, 'bar'), 'obj.bar should NOT be an accessor descriptor');\n\n// Alternatively, if you already have the descriptor object\nconst fooDescriptor = Object.getOwnPropertyDescriptor(obj, 'foo');\nassert.equal(true, isAccessorDescriptor(fooDescriptor), 'fooDescriptor should be an accessor descriptor');\n\nconst barDescriptor = Object.getOwnPropertyDescriptor(obj, 'bar');\nassert.equal(false, isAccessorDescriptor(barDescriptor), 'barDescriptor should NOT be an accessor descriptor');\n\nconsole.log('All assertions passed: is-accessor-descriptor works as expected!');","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"TypeError: isAccessorDescriptor is not a function"},{"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';`.","cause":"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`.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}