Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
Install with npm
$ npm i is-descriptor --save
var isDescriptor = require('is-descriptor');
isDescriptor({value: 'foo'})
//=> true
isDescriptor({get: function(){}, set: function(){}})
//=> false
isDescriptor({get: 'foo', set: function(){}})
//=> false
false
when not an object
isDescriptor('a'))
//=> false
isDescriptor(null))
//=> false
isDescriptor([]))
//=> false
true
when the object has valid properties with valid values.
isDescriptor({value: 'foo'}))
//=> true
isDescriptor({value: noop}))
//=> true
false
when the object has invalid properties
isDescriptor({value: 'foo', bar: 'baz'}))
//=> false
isDescriptor({value: 'foo', bar: 'baz'}))
//=> false
isDescriptor({value: 'foo', get: noop}))
//=> false
isDescriptor({get: noop, value: noop}))
//=> 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
true
when the object has valid properties with valid values.
isDescriptor({get: noop, set: noop}))
//=> true
isDescriptor({get: noop}))
//=> true
isDescriptor({set: noop}))
//=> true
false
when the object has invalid properties
isDescriptor({get: noop, set: noop, bar: 'baz'}))
//=> false
isDescriptor({get: noop, writable: true}))
//=> false
isDescriptor({get: noop, value: true}))
//=> false
false
when an accessor is not a function
isDescriptor({get: noop, set: 'baz'}))
//=> false
isDescriptor({get: 'foo', set: noop}))
//=> false
isDescriptor({get: 'foo', bar: 'baz'}))
//=> false
isDescriptor({get: 'foo', set: 'baz'}))
//=> false
false
when a value is not the correct type
isDescriptor({get: noop, set: noop, enumerable: 'foo'}))
//=> false
isDescriptor({set: noop, configurable: 'foo'}))
//=> false
isDescriptor({get: noop, configurable: 'foo'}))
//=> false
- is-accessor-descriptor: Returns true if a value is a valid JavaScript accessor descriptor. | homepage
- is-data-descriptor: Returns true if a value appears to be a valid JavaScript data descriptor. | homepage
- isobject: Returns true if the value is an object and not an array or null. | homepage
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on August 31, 2015.