Skip to content

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

License

Notifications You must be signed in to change notification settings

doowb/is-descriptor

 
 

Repository files navigation

is-descriptor NPM version

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

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  
  •  

Packages

No packages published

Languages

  • JavaScript 100.0%