is-data-descriptor (1.0.1)

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

Installation

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

About this package

is-data-descriptor Version Badge

github actions coverage License Downloads

npm badge

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

Install

Install with npm:

$ npm install --save is-data-descriptor

Usage

var isDataDesc = require('is-data-descriptor');
var assert = require('assert');

Examples

true when the descriptor has valid properties with valid values.

// `value` can be anything
assert.equal(isDataDesc({ value: 'foo' }), true);
assert.equal(isDataDesc({ value: function () {} }), true);
assert.equal(isDataDesc({ value: true }), true);

false when not an object

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

false when the object has invalid properties

assert.equal(isDataDesc({ value: 'foo', enumerable: 'baz' }), false);
assert.equal(isDataDesc({ value: 'foo', configurable: 'baz' }), false);
assert.equal(isDataDesc({ value: 'foo', get() {} }), false);
assert.equal(isDataDesc({ get() {}, value: 'foo' }), false);

false when a value is not the correct type

assert.equal(isDataDesc({ value: 'foo', enumerable: 'foo' }), false);
assert.equal(isDataDesc({ value: 'foo', configurable: 'foo' }), false);
assert.equal(isDataDesc({ value: 'foo', writable: 'foo' }), false);

Valid properties

The only valid data descriptor properties are the following:

  • configurable (required)
  • enumerable (required)
  • value (optional)
  • writable (optional)

To be a valid data descriptor, either value or writable must be defined.

Invalid properties

A descriptor may have additional invalid properties (an error will not be thrown).

var foo = {};

Object.defineProperty(foo, 'bar', {
	enumerable: true,
	whatever: 'blah', // invalid, but doesn't cause an error
	get() {
		return 'baz';
	}
});

assert.equal(foo.bar, 'baz');

You might also be interested in these projects:

  • is-accessor-descriptor: Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
  • is-descriptor: Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… more

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

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