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'})
isDescriptor({get: function(){}, set: function(){}})
isDescriptor({get: 'foo', set: function(){}})
Examples
value type
false
when not an object
isDescriptor('a'))
isDescriptor(null))
isDescriptor([]))
data descriptor
true
when the object has valid properties with valid values.
isDescriptor({value: 'foo'}))
isDescriptor({value: noop}))
false
when the object has invalid properties
isDescriptor({value: 'foo', bar: 'baz'}))
isDescriptor({value: 'foo', bar: 'baz'}))
isDescriptor({value: 'foo', get: noop}))
isDescriptor({get: noop, value: noop}))
false
when a value is not the correct type
isDescriptor({value: 'foo', enumerable: 'foo'}))
isDescriptor({value: 'foo', configurable: 'foo'}))
isDescriptor({value: 'foo', writable: 'foo'}))
accessor descriptor
true
when the object has valid properties with valid values.
isDescriptor({get: noop, set: noop}))
isDescriptor({get: noop}))
isDescriptor({set: noop}))
false
when the object has invalid properties
isDescriptor({get: noop, set: noop, bar: 'baz'}))
isDescriptor({get: noop, writable: true}))
isDescriptor({get: noop, value: true}))
false
when an accessor is not a function
isDescriptor({get: noop, set: 'baz'}))
isDescriptor({get: 'foo', set: noop}))
isDescriptor({get: 'foo', bar: 'baz'}))
isDescriptor({get: 'foo', set: 'baz'}))
false
when a value is not the correct type
isDescriptor({get: noop, set: noop, enumerable: 'foo'}))
isDescriptor({set: noop, configurable: 'foo'}))
isDescriptor({get: noop, configurable: 'foo'}))
Related projects
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 October 04, 2015.