2.1.3 • Published 6 months ago

is-data-descriptor v2.1.3

Weekly downloads
36,754,588
License
MIT
Repository
github
Last release
6 months ago

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

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

is-descriptorarchetype-librarycomponennenttvuedragdropuploadimagespopsmart-common-authreact-native-bluetooth2killi8n-react-native-fast-imagern-send-smsspecify-importsbabel-specify-imports@icanpm/api-mastergew-nodejs-api-client@arisageha/react-lazyload@arisageha/react-lazyload-fix@cashremit/cr-streamline-iconsreact-native-template-rfbasecloud-archive-s3airscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxf@phil8795/pecuniarius-apideneme323112@texttree/demo-bsa-reference-rcl@fundefund/funde_ck@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjamesreact-native-covid-sdkgql_din_modbitgetreact-native-thanh-toast-library@thanhnguyen14797/react-native-thanh-toast-library@l1nyanm1ng/react-picture-viewercthpb-plugin-socialreact-native-printer-brothersrn-pdf-reader-offlinereact-native-shekhar-bridge-testwilscanner@commutatus/cm-page-builder-test@oiti/documentoscopy-react-nativejs4cytoscape@mink-opn/build-tokensquoc-testreact-native-slider-kf@infinitebrahmanuniverse/nolb-is-d@saaspe/componentsplginexpand-react-bridge@everything-registry/sub-chunk-1932ond@anonybit-modules/videoreconstructiondate-library-aademo-test-scrn@donapot/mylibtestdfeuk-frontenddfeuk-frontend-manual@devorso/dcountdowndemo-component-skyflyer86design-system-fitbank-450digital-keyboard-demos@deep27/supersetpluginchart-helloworlddataormfenglin-uploaderfahad-redux-axios-midlewarefastlion-picture-viewerfn-lib-examplefmslflowable-bpmn-modelerfrdrk-js-semaphoreforminput-ui-libfork-react-ffmpegdiscordjs-con-selfdk_2018_1_1discord.js-bycones-react-bridgeex-ikon-components-libraryevanutils@hazyflame/vue-jitsi-meet@hbglobal/react-native-actions-shortcuts@hawkingnetwork/react-native-tab-view@harsha-jalan/ckeditor5-custom-build@headgum/tko-mapping@glyw/react-native-tabbed-section-list@gzup/react-image-file-resizer@geeky-apo/react-native-advanced-clipboard@hproinformatica/functions@hemith/react-native-tnkhot-zone-vueiex-sdkjamuskaliminstall-is@humanity.cash/typesdskcorenew@chakra-swap/corecr7-exeffect-protoeditorjs-alerticonseasyplayer-my
1.0.1

6 months ago

2.1.2

6 months ago

2.1.3

6 months ago

0.1.5

6 months ago

2.1.1

12 months ago

2.1.0

12 months ago

2.0.0

5 years ago

1.0.0

6 years ago

0.1.4

8 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago