Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

is-descriptor

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Issues
File Explorer

Advanced tools

is-descriptor

Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.

    3.0.0latest

Version published
Maintainers
1
Weekly downloads
44,594,790
decreased by-11.37%

Weekly downloads

Readme

Source

is-descriptor NPM version NPM monthly downloads NPM total downloads Linux Build Status

Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save is-descriptor

Usage

const isDescriptor = require('is-descriptor'); isDescriptor({ value: 'foo' }) //=> true isDescriptor({ get: function() {}, set: function() {} }) //=> true isDescriptor({ get: 'foo', set: function() {} }) //=> false

You may also check for a descriptor by passing an object as the first argument and property name (string) as the second argument.

const obj = {}; obj.foo = null; Object.defineProperty(obj, 'bar', { value: 'xyz' }); Reflect.defineProperty(obj, 'baz', { value: 'xyz' }); isDescriptor(obj, 'foo'); //=> true isDescriptor(obj, 'bar'); //=> true isDescriptor(obj, 'baz'); //=> true

Examples

value type

Returns false when not an object

isDescriptor('a'); //=> false isDescriptor(null); //=> false isDescriptor([]); //=> false

data descriptor

Returns true when the object has valid properties with valid values.

isDescriptor({ value: 'foo' }); //=> true isDescriptor({ value: function() {} }); //=> true

Returns false when the object has invalid properties

isDescriptor({ value: 'foo', bar: 'baz' }); //=> false isDescriptor({ value: 'foo', bar: 'baz' }); //=> false isDescriptor({ value: 'foo', get: function() {} }); //=> false isDescriptor({ get: function() {}, value: function() {} }); //=> false

false when a value is not the correct type

isDescriptor({ value: 'foo', enumerable: 'foo' }); //=> false isDescriptor({ value: 'foo', configurable: 'foo' }); //=> false isDescriptor({ value: 'foo', writable: 'foo' }); //=> false

accessor descriptor

true when the object has valid properties with valid values.

isDescriptor({ get: function() {}, set: function() {} }); //=> true isDescriptor({ get: function() {} }); //=> true isDescriptor({ set: function() {} }); //=> true

false when the object has invalid properties

isDescriptor({ get: function() {}, set: function() {}, bar: 'baz' }); //=> false isDescriptor({ get: function() {}, writable: true }); //=> false isDescriptor({ get: function() {}, value: true }); //=> false

Returns false when an accessor is not a function

isDescriptor({ get: function() {}, set: 'baz' }); //=> false isDescriptor({ get: 'foo', set: function() {} }); //=> false isDescriptor({ get: 'foo', bar: 'baz' }); //=> false isDescriptor({ get: 'foo', set: 'baz' }); //=> false

Returns false when a value is not the correct type

isDescriptor({ get: function() {}, set: function() {}, enumerable: 'foo' }); //=> false isDescriptor({ set: function() {}, configurable: 'foo' }); //=> false isDescriptor({ get: function() {}, configurable: 'foo' }); //=> false

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

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. | homepage
  • is-data-descriptor: Returns true if a value has the characteristics of a valid JavaScript data descriptor. | homepage
  • is-descriptor: Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… more | homepage
  • isobject: Returns true if the value is an object and not an array or null. | homepage

Contributors

CommitsContributor
33jonschlinkert
1doowb
1realityking
1wtgtybhertgeghgtwtg

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on December 13, 2018.

Keywords

FAQs

What is is-descriptor?

Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.

Is is-descriptor popular?

The npm package is-descriptor receives a total of 35,746,064 weekly downloads. As such, is-descriptor popularity was classified as popular.

Is is-descriptor well maintained?

We found that is-descriptor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 14 Dec 2018

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

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc