websocket快速操作工具
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.

143 lines
5.2 KiB

  1. # is-accessor-descriptor [![NPM version](https://img.shields.io/npm/v/is-accessor-descriptor.svg?style=flat)](https://www.npmjs.com/package/is-accessor-descriptor) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-accessor-descriptor.svg?style=flat)](https://npmjs.org/package/is-accessor-descriptor) [![NPM total downloads](https://img.shields.io/npm/dt/is-accessor-descriptor.svg?style=flat)](https://npmjs.org/package/is-accessor-descriptor) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-accessor-descriptor.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-accessor-descriptor)
  2. > Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
  3. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
  4. ## Install
  5. Install with [npm](https://www.npmjs.com/):
  6. ```sh
  7. $ npm install --save is-accessor-descriptor
  8. ```
  9. ## Usage
  10. ```js
  11. var isAccessor = require('is-accessor-descriptor');
  12. isAccessor({get: function() {}});
  13. //=> true
  14. ```
  15. You may also pass an object and property name to check if the property is an accessor:
  16. ```js
  17. isAccessor(foo, 'bar');
  18. ```
  19. ## Examples
  20. `false` when not an object
  21. ```js
  22. isAccessor('a')
  23. isAccessor(null)
  24. isAccessor([])
  25. //=> false
  26. ```
  27. `true` when the object has valid properties
  28. and the properties all have the correct JavaScript types:
  29. ```js
  30. isAccessor({get: noop, set: noop})
  31. isAccessor({get: noop})
  32. isAccessor({set: noop})
  33. //=> true
  34. ```
  35. `false` when the object has invalid properties
  36. ```js
  37. isAccessor({get: noop, set: noop, bar: 'baz'})
  38. isAccessor({get: noop, writable: true})
  39. isAccessor({get: noop, value: true})
  40. //=> false
  41. ```
  42. `false` when an accessor is not a function
  43. ```js
  44. isAccessor({get: noop, set: 'baz'})
  45. isAccessor({get: 'foo', set: noop})
  46. isAccessor({get: 'foo', bar: 'baz'})
  47. isAccessor({get: 'foo', set: 'baz'})
  48. //=> false
  49. ```
  50. `false` when a value is not the correct type
  51. ```js
  52. isAccessor({get: noop, set: noop, enumerable: 'foo'})
  53. isAccessor({set: noop, configurable: 'foo'})
  54. isAccessor({get: noop, configurable: 'foo'})
  55. //=> false
  56. ```
  57. ## About
  58. <details>
  59. <summary><strong>Contributing</strong></summary>
  60. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  61. </details>
  62. <details>
  63. <summary><strong>Running Tests</strong></summary>
  64. 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:
  65. ```sh
  66. $ npm install && npm test
  67. ```
  68. </details>
  69. <details>
  70. <summary><strong>Building docs</strong></summary>
  71. _(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.)_
  72. To generate the readme, run the following command:
  73. ```sh
  74. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  75. ```
  76. </details>
  77. ### Related projects
  78. You might also be interested in these projects:
  79. * [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.")
  80. * [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.")
  81. * [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.")
  82. * [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.")
  83. * [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.")
  84. ### Contributors
  85. | **Commits** | **Contributor** |
  86. | --- | --- |
  87. | 22 | [jonschlinkert](https://github.com/jonschlinkert) |
  88. | 2 | [realityking](https://github.com/realityking) |
  89. ### Author
  90. **Jon Schlinkert**
  91. * [github/jonschlinkert](https://github.com/jonschlinkert)
  92. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  93. ### License
  94. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  95. Released under the [MIT License](LICENSE).
  96. ***
  97. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._