You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. > Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
  3. - [Install](#install)
  4. - [Usage](#usage)
  5. - [Examples](#examples)
  6. - [API](#api)
  7. - [Related projects](#related-projects)
  8. - [Running tests](#running-tests)
  9. - [Contributing](#contributing)
  10. - [Author](#author)
  11. - [License](#license)
  12. _(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
  13. ## Install
  14. Install with [npm](https://www.npmjs.com/):
  15. ```sh
  16. $ npm i is-accessor-descriptor --save
  17. ```
  18. ## Usage
  19. ```js
  20. var isAccessor = require('is-accessor-descriptor');
  21. isAccessor({get: function() {}});
  22. //=> true
  23. ```
  24. You may also pass an object and property name to check if the property is an accessor:
  25. ```js
  26. isAccessor(foo, 'bar');
  27. ```
  28. ## Examples
  29. `false` when not an object
  30. ```js
  31. isAccessor('a')
  32. isAccessor(null)
  33. isAccessor([])
  34. //=> false
  35. ```
  36. `true` when the object has valid properties
  37. and the properties all have the correct JavaScript types:
  38. ```js
  39. isAccessor({get: noop, set: noop})
  40. isAccessor({get: noop})
  41. isAccessor({set: noop})
  42. //=> true
  43. ```
  44. `false` when the object has invalid properties
  45. ```js
  46. isAccessor({get: noop, set: noop, bar: 'baz'})
  47. isAccessor({get: noop, writable: true})
  48. isAccessor({get: noop, value: true})
  49. //=> false
  50. ```
  51. `false` when an accessor is not a function
  52. ```js
  53. isAccessor({get: noop, set: 'baz'})
  54. isAccessor({get: 'foo', set: noop})
  55. isAccessor({get: 'foo', bar: 'baz'})
  56. isAccessor({get: 'foo', set: 'baz'})
  57. //=> false
  58. ```
  59. `false` when a value is not the correct type
  60. ```js
  61. isAccessor({get: noop, set: noop, enumerable: 'foo'})
  62. isAccessor({set: noop, configurable: 'foo'})
  63. isAccessor({get: noop, configurable: 'foo'})
  64. //=> false
  65. ```
  66. ## Related projects
  67. * [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)
  68. * [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)
  69. * [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)
  70. * [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)
  71. ## Running tests
  72. Install dev dependencies:
  73. ```sh
  74. $ npm i -d && npm test
  75. ```
  76. ## Contributing
  77. 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).
  78. ## Author
  79. **Jon Schlinkert**
  80. * [github/jonschlinkert](https://github.com/jonschlinkert)
  81. * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  82. ## License
  83. Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
  84. Released under the MIT license.
  85. ***
  86. _This file was generated by [verb](https://github.com/verbose/verb) on December 28, 2015._