{"id":11099,"library":"is-data-descriptor","title":"JavaScript Data Descriptor Validator","description":"The `is-data-descriptor` package is a focused utility designed to accurately determine if a given JavaScript value conforms to the characteristics of a valid data property descriptor, as defined by the ECMAScript specification. Currently stable at version 2.1.3, it is part of the `inspect-js` family of descriptor validation libraries. Unlike `is-descriptor`, which checks for any valid descriptor type, this package specifically targets data descriptors, verifying the presence and correct types of properties like `value`, `writable`, `enumerable`, and `configurable`, while ensuring the absence of accessor properties (`get`, `set`). Its release cadence is typically slow, reflecting its stable and specific functionality. A key characteristic is that it will not throw an error for extraneous, invalid properties present on the descriptor object, which might differ from strict validation expectations in some scenarios. It is primarily used in Node.js environments and build processes where strict object property definition validation is required.","status":"active","version":"2.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/inspect-js/is-data-descriptor","tags":["javascript","accessor","check","data","descriptor","get","getter","is","keys"],"install":[{"cmd":"npm install is-data-descriptor","lang":"bash","label":"npm"},{"cmd":"yarn add is-data-descriptor","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-data-descriptor","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single function as its default. For ESM, use a default import.","wrong":"import { isDataDescriptor } from 'is-data-descriptor';","symbol":"isDataDescriptor","correct":"import isDataDescriptor from 'is-data-descriptor';"},{"note":"For CommonJS, the module exports the function directly, so do not destructure.","wrong":"const { isDataDescriptor } = require('is-data-descriptor');","symbol":"isDataDescriptor","correct":"const isDataDescriptor = require('is-data-descriptor');"},{"note":"When using TypeScript or environments where default interop is explicit, accessing the default export might require an intermediate variable or specific tsconfig settings.","symbol":"isDataDescriptor","correct":"import * as isDataDescriptorModule from 'is-data-descriptor';\nconst isDataDescriptor = isDataDescriptorModule.default;"}],"quickstart":{"code":"import assert from 'assert';\nimport isDataDescriptor from 'is-data-descriptor';\n\nfunction validateDescriptors() {\n  // Valid data descriptors\n  assert.equal(isDataDescriptor({ value: 'foo' }), true, 'Basic value descriptor');\n  assert.equal(isDataDescriptor({ value: function () {} }), true, 'Function value descriptor');\n  assert.equal(isDataDescriptor({ value: true, enumerable: true, configurable: false, writable: true }), true, 'Full data descriptor');\n\n  // Invalid inputs or non-data descriptors\n  assert.equal(isDataDescriptor('a'), false, 'Primitive string is not a descriptor');\n  assert.equal(isDataDescriptor(null), false, 'Null is not a descriptor');\n  assert.equal(isDataDescriptor([]), false, 'Array is not a descriptor');\n  assert.equal(isDataDescriptor({ get: function() {} }), false, 'Accessor descriptor is not a data descriptor');\n  assert.equal(isDataDescriptor({ value: 'foo', get: function() {} }), false, 'Mixed descriptor is invalid');\n  assert.equal(isDataDescriptor({ value: 'foo', bar: 'baz' }), false, 'Extra invalid property makes it invalid');\n\n  console.log('All data descriptor validations passed!');\n}\n\nvalidateDescriptors();","lang":"javascript","description":"This quickstart demonstrates how to use `is-data-descriptor` to check various objects for valid data descriptor characteristics, including both valid and invalid examples."},"warnings":[{"fix":"Ensure descriptor objects contain *only* valid data descriptor properties. If you need to validate any type of descriptor (data or accessor), consider using `is-descriptor` instead.","message":"The `is-data-descriptor` utility will return `false` if the descriptor object contains any properties that are not part of the standard data descriptor keys (`value`, `writable`, `enumerable`, `configurable`). This includes common typos or properties associated with accessor descriptors (`get`, `set`). It does not throw an error but quietly indicates invalidity.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always include `value` or `writable` in your data descriptor objects, even if their values are `undefined` or `false`, respectively.","message":"A descriptor object must define either `value` or `writable` (or both) to be considered a valid data descriptor by this utility. A descriptor with only `enumerable` and/or `configurable` set will return `false`.","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":"For CommonJS: `const isDataDescriptor = require('is-data-descriptor');`. For ESM: `import isDataDescriptor from 'is-data-descriptor';`.","cause":"Attempting to destructure the imported module in CommonJS, or incorrectly importing the default export in ESM.","error":"TypeError: isDataDescriptor is not a function"},{"fix":"Use the ESM import syntax: `import isDataDescriptor from 'is-data-descriptor';`.","cause":"Using `require()` syntax in an ECMAScript Module (ESM) context (e.g., a file with `\"type\": \"module\"` in `package.json` or a `.mjs` file).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}