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)
|
---|
2 |
|
---|
3 | > Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
|
---|
4 |
|
---|
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))_
|
---|
16 |
|
---|
17 | ## Install
|
---|
18 |
|
---|
19 | Install with [npm](https://www.npmjs.com/):
|
---|
20 |
|
---|
21 | ```sh
|
---|
22 | $ npm i is-accessor-descriptor --save
|
---|
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 |
|
---|
90 | ## Related projects
|
---|
91 |
|
---|
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)
|
---|
96 |
|
---|
97 | ## Running tests
|
---|
98 |
|
---|
99 | Install dev dependencies:
|
---|
100 |
|
---|
101 | ```sh
|
---|
102 | $ npm i -d && npm test
|
---|
103 | ```
|
---|
104 |
|
---|
105 | ## Contributing
|
---|
106 |
|
---|
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).
|
---|
108 |
|
---|
109 | ## Author
|
---|
110 |
|
---|
111 | **Jon Schlinkert**
|
---|
112 |
|
---|
113 | * [github/jonschlinkert](https://github.com/jonschlinkert)
|
---|
114 | * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
|
---|
115 |
|
---|
116 | ## License
|
---|
117 |
|
---|
118 | Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
|
---|
119 | Released under the MIT license.
|
---|
120 |
|
---|
121 | ***
|
---|
122 |
|
---|
123 | _This file was generated by [verb](https://github.com/verbose/verb) on December 28, 2015._ |
---|