Package Exports
- is-descriptor
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-descriptor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
is-descriptor 
Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
Install
Install with npm
$ npm i is-descriptor --save
Usage
var isDescriptor = require('is-descriptor');
isDescriptor({value: 'foo'})
//=> true
isDescriptor({get: function(){}, set: function(){}})
//=> false
isDescriptor({get: 'foo', set: function(){}})
//=> false
Examples
value type
false
when not an object
isDescriptor('a'))
//=> false
isDescriptor(null))
//=> false
isDescriptor([]))
//=> false
data descriptor
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
accessor descriptor
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
Related projects
- 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
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on August 31, 2015.