Registry / testing / is-data-descriptor

is-data-descriptor

JSON →
library2.1.3jsnpmunverified

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.

npm install is-data-descriptor
INSTALL
IMPORT
SIG · IS-DATA-DESCRIPTOR
I
is-data-descriptor
testingjavascriptv2.1.3
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.

isDataDescriptor
import isDataDescriptor from 'is-data-descriptor';
import { isDataDescriptor } from 'is-data-descriptor';
The package exports a single function as its default. For ESM, use a default import.
isDataDescriptor
const isDataDescriptor = require('is-data-descriptor');
const { isDataDescriptor } = require('is-data-descriptor');
For CommonJS, the module exports the function directly, so do not destructure.
isDataDescriptor
import * as isDataDescriptorModule from 'is-data-descriptor'; const isDataDescriptor = isDataDescriptorModule.default;
When using TypeScript or environments where default interop is explicit, accessing the default export might require an intermediate variable or specific tsconfig settings.

This quickstart demonstrates how to use `is-data-descriptor` to check various objects for valid data descriptor characteristics, including both valid and invalid examples.

import assert from 'assert'; import isDataDescriptor from 'is-data-descriptor'; function validateDescriptors() { // Valid data descriptors assert.equal(isDataDescriptor({ value: 'foo' }), true, 'Basic value descriptor'); assert.equal(isDataDescriptor({ value: function () {} }), true, 'Function value descriptor'); assert.equal(isDataDescriptor({ value: true, enumerable: true, configurable: false, writable: true }), true, 'Full data descriptor'); // Invalid inputs or non-data descriptors assert.equal(isDataDescriptor('a'), false, 'Primitive string is not a descriptor'); assert.equal(isDataDescriptor(null), false, 'Null is not a descriptor'); assert.equal(isDataDescriptor([]), false, 'Array is not a descriptor'); assert.equal(isDataDescriptor({ get: function() {} }), false, 'Accessor descriptor is not a data descriptor'); assert.equal(isDataDescriptor({ value: 'foo', get: function() {} }), false, 'Mixed descriptor is invalid'); assert.equal(isDataDescriptor({ value: 'foo', bar: 'baz' }), false, 'Extra invalid property makes it invalid'); console.log('All data descriptor validations passed!'); } validateDescriptors();
Debug
Known issues
gotchaThe `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.
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.
affects: >=1.0.0
gotchaA 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`.
fix
Always include `value` or `writable` in your data descriptor objects, even if their values are `undefined` or `false`, respectively.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: isDataDescriptor is not a function
Attempting to destructure the imported module in CommonJS, or incorrectly importing the default export in ESM.
fix
For CommonJS: `const isDataDescriptor = require('is-data-descriptor');`. For ESM: `import isDataDescriptor from 'is-data-descriptor';`.
ReferenceError: require is not defined
Using `require()` syntax in an ECMAScript Module (ESM) context (e.g., a file with `"type": "module"` in `package.json` or a `.mjs` file).
fix
Use the ESM import syntax: `import isDataDescriptor from 'is-data-descriptor';`.
Upgrade
Version history
2.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

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