Big news!Introducing Socket AI - ChatGPT-Powered Threat Analysis.Learn more
Socket
Socket

is-data-descriptor

Package Overview
Dependencies
0
Maintainers
2
Versions
9
Issues
File Explorer

Advanced tools

is-data-descriptor

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

    2.1.1latest
    GitHub
    npm

Version published
Maintainers
2
Weekly downloads
49,198,884
increased by6.09%

Weekly downloads

Changelog

Source

v2.1.1 - 2023-04-27

Commits

Readme

Source

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: function() { return 'baz'; } }); console.log(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
  • is-object: Returns true if the value is an object and not an array or null.

Tests

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

Keywords

FAQs

Last updated on 27 Apr 2023

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
Socket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc