Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

is-data-descriptor

inspect-js107.8mMIT2.1.3TypeScript support: definitely-typed

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

accessor, check, data, descriptor, get, getter, is, keys, object, properties, property, set, setter, type, valid, value

readme

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.

Examples

true when the descriptor has valid properties with valid values. false when not an object or when the object has invalid properties.

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

assert.equal(true, isDataDesc({ value: 'foo' }));
assert.equal(true, isDataDesc({ value: function () {} }));
assert.equal(true, isDataDesc({ value: true }));

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

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

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

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');
  • 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

Tests

Simply clone the repo, npm install, and run npm test

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v2.1.3 - 2023-10-26

Commits

  • Merge tag v0.1.5, v1.0.1 c64e97f
  • [eslint] actually use eslint dce7eae
  • [eslint] actually use eslint 65fed07
  • [meta] update package.json etc from main 1ebc548
  • [readme] clean up readme, remove verb 10ad663
  • [meta] clean up package.json 7f76a01
  • [readme] remove verb 8178901
  • [meta] update .gitignore a2ca593
  • [Tests] switch to tape 70540e5
  • [Tests] switch to tape 95ff316
  • [readme] update from main bb8bcf2
  • [Tests] migrate from travis to github actions eee138d
  • [Tests] migrate from travis to github actions a46e5a4
  • [readme] use evalmd 7648a08
  • [Tests] move into a test dir f0f3521
  • [Fix] properly return false for an accessor descriptor 2c213cd
  • [Fix] correctly return false for something with get or set 16bcab0
  • [Performance] move data object to module level 37688a1
  • [Fix] allow any non-primitive; arrays and functions are objects too f01936a
  • [Refactor] use hasown 060ed0a
  • [Fix] allow any non-primitive; arrays and functions are objects too 197c77a
  • [Fix] accept a symbol in the two-arg form 78b6215
  • Only apps should have lockfiles bbf6d2e
  • Only apps should have lockfiles 20aa6e5
  • [Fix] use correct logic for two-arg form 1f77993
  • [Robustness] switch to hasown aa48e2f
  • [Fix] properly guard for-in loop 014971e
  • [Robustness] use a null object just in case ab05aad

v2.1.2 - 2023-10-25

Commits

  • [Refactor] use hasown 77ad812
  • [Dev Deps] update @ljharb/eslint-config, aud, tape 88f2cb7

v2.1.1 - 2023-04-27

Commits

  • [Fix] when an object/key pair is provided, check arguments.length instead of key truthiness 72692d3
  • [readme] remove empty section 72ec85b

v2.1.0 - 2023-04-27

Commits

  • [eslint] cleanup c18a236
  • [Tests] travis -> Github Actions; add safe-publish-latest, npmignore, auto-changelog, evalmd, aud 5758410
  • [readme] clean up docs, URLs, package.json, etc 28f61dd
  • [Docs] remove verb e20d28c
  • [Tests] convert from mocha to tape 666c175
  • [New] increase support from node 6 down to node 0.4 aa43b69
  • [Tests] add coverage 8f094f6
  • [meta] switch from files field to npmignore; add exports 2769e1d
  • [Deps] remove unused kind-of bc87bcd

v2.0.0 - 2018-12-13

Commits

v1.0.1 - 2023-10-26

Commits

  • [eslint] actually use eslint 65fed07
  • [readme] clean up readme, remove verb 10ad663
  • [meta] clean up package.json 7f76a01
  • [meta] update .gitignore a2ca593
  • [Tests] switch to tape 70540e5
  • [Tests] migrate from travis to github actions eee138d
  • [Fix] properly return false for an accessor descriptor 2c213cd
  • [Performance] move data object to module level 37688a1
  • [Fix] allow any non-primitive; arrays and functions are objects too 197c77a
  • Only apps should have lockfiles 20aa6e5
  • [Robustness] switch to hasown aa48e2f
  • [Fix] properly guard for-in loop 014971e
  • [Robustness] use a null object just in case ab05aad

v1.0.0 - 2017-11-01

Merged

  • Update kind-of to version 6.0 #1
  • Pin mocha to version 3 to support Node 0.12 #2

Commits

v0.1.5 - 2023-10-26

Commits

  • [eslint] actually use eslint dce7eae
  • [meta] update package.json etc from main 1ebc548
  • [readme] remove verb 8178901
  • [Tests] switch to tape 95ff316
  • [readme] update from main bb8bcf2
  • [Tests] migrate from travis to github actions a46e5a4
  • [readme] use evalmd 7648a08
  • [Tests] move into a test dir f0f3521
  • [Fix] correctly return false for something with get or set 16bcab0
  • [Fix] allow any non-primitive; arrays and functions are objects too f01936a
  • [Refactor] use hasown 060ed0a
  • [Fix] accept a symbol in the two-arg form 78b6215
  • Only apps should have lockfiles bbf6d2e
  • [Fix] use correct logic for two-arg form 1f77993

v0.1.4 - 2015-12-28

Fixed

Commits

v0.1.3 - 2015-10-04

Commits

v0.1.2 - 2015-10-04

Commits

v0.1.1 - 2015-08-31

Commits