README.md
1 # is-accessor-descriptor [](https://www.npmjs.com/package/is-accessor-descriptor) [](https://npmjs.org/package/is-accessor-descriptor) [](https://npmjs.org/package/is-accessor-descriptor) [](https://travis-ci.org/jonschlinkert/is-accessor-descriptor) 2 3 > Returns true if a value has the characteristics of a valid JavaScript accessor descriptor. 4 5 Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. 6 7 ## Install 8 9 Install with [npm](https://www.npmjs.com/): 10 11 ```sh 12 $ npm install --save is-accessor-descriptor 13 ``` 14 15 ## Usage 16 17 ```js 18 var isAccessor = require('is-accessor-descriptor'); 19 20 isAccessor({get: function() {}}); 21 //=> true 22 ``` 23 24 You may also pass an object and property name to check if the property is an accessor: 25 26 ```js 27 isAccessor(foo, 'bar'); 28 ``` 29 30 ## Examples 31 32 `false` when not an object 33 34 ```js 35 isAccessor('a') 36 isAccessor(null) 37 isAccessor([]) 38 //=> false 39 ``` 40 41 `true` when the object has valid properties 42 43 and the properties all have the correct JavaScript types: 44 45 ```js 46 isAccessor({get: noop, set: noop}) 47 isAccessor({get: noop}) 48 isAccessor({set: noop}) 49 //=> true 50 ``` 51 52 `false` when the object has invalid properties 53 54 ```js 55 isAccessor({get: noop, set: noop, bar: 'baz'}) 56 isAccessor({get: noop, writable: true}) 57 isAccessor({get: noop, value: true}) 58 //=> false 59 ``` 60 61 `false` when an accessor is not a function 62 63 ```js 64 isAccessor({get: noop, set: 'baz'}) 65 isAccessor({get: 'foo', set: noop}) 66 isAccessor({get: 'foo', bar: 'baz'}) 67 isAccessor({get: 'foo', set: 'baz'}) 68 //=> false 69 ``` 70 71 `false` when a value is not the correct type 72 73 ```js 74 isAccessor({get: noop, set: noop, enumerable: 'foo'}) 75 isAccessor({set: noop, configurable: 'foo'}) 76 isAccessor({get: noop, configurable: 'foo'}) 77 //=> false 78 ``` 79 80 ## About 81 82 <details> 83 <summary><strong>Contributing</strong></summary> 84 85 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 86 87 </details> 88 89 <details> 90 <summary><strong>Running Tests</strong></summary> 91 92 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: 93 94 ```sh 95 $ npm install && npm test 96 ``` 97 98 </details> 99 100 <details> 101 <summary><strong>Building docs</strong></summary> 102 103 _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 104 105 To generate the readme, run the following command: 106 107 ```sh 108 $ npm install -g verbose/verb#dev verb-generate-readme && verb 109 ``` 110 111 </details> 112 113 ### Related projects 114 115 You might also be interested in these projects: 116 117 * [is-accessor-descriptor](https://www.npmjs.com/package/is-accessor-descriptor): Returns true if a value has the characteristics of a valid JavaScript accessor descriptor. | [homepage](https://github.com/jonschlinkert/is-accessor-descriptor "Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.") 118 * [is-data-descriptor](https://www.npmjs.com/package/is-data-descriptor): Returns true if a value has the characteristics of a valid JavaScript data descriptor. | [homepage](https://github.com/jonschlinkert/is-data-descriptor "Returns true if a value has the characteristics of a valid JavaScript data descriptor.") 119 * [is-descriptor](https://www.npmjs.com/package/is-descriptor): Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… [more](https://github.com/jonschlinkert/is-descriptor) | [homepage](https://github.com/jonschlinkert/is-descriptor "Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.") 120 * [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.") 121 * [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.") 122 123 ### Contributors 124 125 | **Commits** | **Contributor** | 126 | --- | --- | 127 | 22 | [jonschlinkert](https://github.com/jonschlinkert) | 128 | 2 | [realityking](https://github.com/realityking) | 129 130 ### Author 131 132 **Jon Schlinkert** 133 134 * [github/jonschlinkert](https://github.com/jonschlinkert) 135 * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) 136 137 ### License 138 139 Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 140 Released under the [MIT License](LICENSE). 141 142 *** 143 144 _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._