[e29cc2e] | 1 | # is-accessor-descriptor [![NPM version](https://img.shields.io/npm/v/is-accessor-descriptor.svg)](https://www.npmjs.com/package/is-accessor-descriptor) [![Build Status](https://img.shields.io/travis/jonschlinkert/is-accessor-descriptor.svg)](https://travis-ci.org/jonschlinkert/is-accessor-descriptor)
|
---|
[6a3a178] | 2 |
|
---|
| 3 | > Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
|
---|
| 4 |
|
---|
[e29cc2e] | 5 | - [Install](#install)
|
---|
| 6 | - [Usage](#usage)
|
---|
| 7 | - [Examples](#examples)
|
---|
| 8 | - [API](#api)
|
---|
| 9 | - [Related projects](#related-projects)
|
---|
| 10 | - [Running tests](#running-tests)
|
---|
| 11 | - [Contributing](#contributing)
|
---|
| 12 | - [Author](#author)
|
---|
| 13 | - [License](#license)
|
---|
| 14 |
|
---|
| 15 | _(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
|
---|
[6a3a178] | 16 |
|
---|
| 17 | ## Install
|
---|
| 18 |
|
---|
| 19 | Install with [npm](https://www.npmjs.com/):
|
---|
| 20 |
|
---|
| 21 | ```sh
|
---|
[e29cc2e] | 22 | $ npm i is-accessor-descriptor --save
|
---|
[6a3a178] | 23 | ```
|
---|
| 24 |
|
---|
| 25 | ## Usage
|
---|
| 26 |
|
---|
| 27 | ```js
|
---|
| 28 | var isAccessor = require('is-accessor-descriptor');
|
---|
| 29 |
|
---|
| 30 | isAccessor({get: function() {}});
|
---|
| 31 | //=> true
|
---|
| 32 | ```
|
---|
| 33 |
|
---|
| 34 | You may also pass an object and property name to check if the property is an accessor:
|
---|
| 35 |
|
---|
| 36 | ```js
|
---|
| 37 | isAccessor(foo, 'bar');
|
---|
| 38 | ```
|
---|
| 39 |
|
---|
| 40 | ## Examples
|
---|
| 41 |
|
---|
| 42 | `false` when not an object
|
---|
| 43 |
|
---|
| 44 | ```js
|
---|
| 45 | isAccessor('a')
|
---|
| 46 | isAccessor(null)
|
---|
| 47 | isAccessor([])
|
---|
| 48 | //=> false
|
---|
| 49 | ```
|
---|
| 50 |
|
---|
| 51 | `true` when the object has valid properties
|
---|
| 52 |
|
---|
| 53 | and the properties all have the correct JavaScript types:
|
---|
| 54 |
|
---|
| 55 | ```js
|
---|
| 56 | isAccessor({get: noop, set: noop})
|
---|
| 57 | isAccessor({get: noop})
|
---|
| 58 | isAccessor({set: noop})
|
---|
| 59 | //=> true
|
---|
| 60 | ```
|
---|
| 61 |
|
---|
| 62 | `false` when the object has invalid properties
|
---|
| 63 |
|
---|
| 64 | ```js
|
---|
| 65 | isAccessor({get: noop, set: noop, bar: 'baz'})
|
---|
| 66 | isAccessor({get: noop, writable: true})
|
---|
| 67 | isAccessor({get: noop, value: true})
|
---|
| 68 | //=> false
|
---|
| 69 | ```
|
---|
| 70 |
|
---|
| 71 | `false` when an accessor is not a function
|
---|
| 72 |
|
---|
| 73 | ```js
|
---|
| 74 | isAccessor({get: noop, set: 'baz'})
|
---|
| 75 | isAccessor({get: 'foo', set: noop})
|
---|
| 76 | isAccessor({get: 'foo', bar: 'baz'})
|
---|
| 77 | isAccessor({get: 'foo', set: 'baz'})
|
---|
| 78 | //=> false
|
---|
| 79 | ```
|
---|
| 80 |
|
---|
| 81 | `false` when a value is not the correct type
|
---|
| 82 |
|
---|
| 83 | ```js
|
---|
| 84 | isAccessor({get: noop, set: noop, enumerable: 'foo'})
|
---|
| 85 | isAccessor({set: noop, configurable: 'foo'})
|
---|
| 86 | isAccessor({get: noop, configurable: 'foo'})
|
---|
| 87 | //=> false
|
---|
| 88 | ```
|
---|
| 89 |
|
---|
[e29cc2e] | 90 | ## Related projects
|
---|
[6a3a178] | 91 |
|
---|
[e29cc2e] | 92 | * [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)
|
---|
| 93 | * [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)
|
---|
| 94 | * [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://www.npmjs.com/package/is-descriptor) | [homepage](https://github.com/jonschlinkert/is-descriptor)
|
---|
| 95 | * [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)
|
---|
[6a3a178] | 96 |
|
---|
[e29cc2e] | 97 | ## Running tests
|
---|
[6a3a178] | 98 |
|
---|
[e29cc2e] | 99 | Install dev dependencies:
|
---|
[6a3a178] | 100 |
|
---|
| 101 | ```sh
|
---|
[e29cc2e] | 102 | $ npm i -d && npm test
|
---|
[6a3a178] | 103 | ```
|
---|
| 104 |
|
---|
[e29cc2e] | 105 | ## Contributing
|
---|
[6a3a178] | 106 |
|
---|
[e29cc2e] | 107 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-accessor-descriptor/issues/new).
|
---|
[6a3a178] | 108 |
|
---|
[e29cc2e] | 109 | ## Author
|
---|
[6a3a178] | 110 |
|
---|
| 111 | **Jon Schlinkert**
|
---|
| 112 |
|
---|
| 113 | * [github/jonschlinkert](https://github.com/jonschlinkert)
|
---|
[e29cc2e] | 114 | * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
|
---|
[6a3a178] | 115 |
|
---|
[e29cc2e] | 116 | ## License
|
---|
[6a3a178] | 117 |
|
---|
[e29cc2e] | 118 | Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
|
---|
| 119 | Released under the MIT license.
|
---|
[6a3a178] | 120 |
|
---|
| 121 | ***
|
---|
| 122 |
|
---|
[e29cc2e] | 123 | _This file was generated by [verb](https://github.com/verbose/verb) on December 28, 2015._ |
---|