2.5.66 • Published 1 year ago

@zitterorg/itaque-ab v2.5.66

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@zitterorg/itaque-ab 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('@zitterorg/itaque-ab');
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');

Related 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

Tests

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

2.5.66

1 year ago

2.5.65

1 year ago

2.5.63

1 year ago

2.5.64

1 year ago

2.5.62

1 year ago

2.5.61

1 year ago

1.5.61

1 year ago

1.5.60

1 year ago

1.5.58

1 year ago

1.5.57

1 year ago

1.5.59

1 year ago

1.5.54

1 year ago

1.5.53

1 year ago

1.5.56

1 year ago

1.5.55

1 year ago

1.3.21

1 year ago

1.5.47

1 year ago

1.3.24

1 year ago

1.3.25

1 year ago

1.5.49

1 year ago

1.3.22

1 year ago

1.5.48

1 year ago

1.3.23

1 year ago

1.4.39

1 year ago

1.3.28

1 year ago

1.4.38

1 year ago

1.3.29

1 year ago

1.2.17

1 year ago

1.3.26

1 year ago

1.3.27

1 year ago

1.2.18

1 year ago

1.2.19

1 year ago

1.5.50

1 year ago

1.5.52

1 year ago

1.4.40

1 year ago

1.5.51

1 year ago

1.4.42

1 year ago

1.3.31

1 year ago

1.4.41

1 year ago

1.3.32

1 year ago

1.2.20

1 year ago

1.4.44

1 year ago

1.4.43

1 year ago

1.3.30

1 year ago

1.4.46

1 year ago

1.3.35

1 year ago

1.4.45

1 year ago

1.3.36

1 year ago

1.3.33

1 year ago

1.2.21

1 year ago

1.4.47

1 year ago

1.3.34

1 year ago

1.3.37

1 year ago

1.3.38

1 year ago

1.2.16

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago