web 3d图形渲染器
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.

160 lines
5.2 KiB

  1. # is-data-descriptor [![NPM version](https://img.shields.io/npm/v/is-data-descriptor.svg?style=flat)](https://www.npmjs.com/package/is-data-descriptor) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-data-descriptor.svg?style=flat)](https://npmjs.org/package/is-data-descriptor) [![NPM total downloads](https://img.shields.io/npm/dt/is-data-descriptor.svg?style=flat)](https://npmjs.org/package/is-data-descriptor) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-data-descriptor.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-data-descriptor)
  2. > Returns true if a value has the characteristics of a valid JavaScript data 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-data-descriptor
  8. ```
  9. ## Usage
  10. ```js
  11. var isDataDesc = require('is-data-descriptor');
  12. ```
  13. ## Examples
  14. `true` when the descriptor has valid properties with valid values.
  15. ```js
  16. // `value` can be anything
  17. isDataDesc({value: 'foo'})
  18. isDataDesc({value: function() {}})
  19. isDataDesc({value: true})
  20. //=> true
  21. ```
  22. `false` when not an object
  23. ```js
  24. isDataDesc('a')
  25. //=> false
  26. isDataDesc(null)
  27. //=> false
  28. isDataDesc([])
  29. //=> false
  30. ```
  31. `false` when the object has invalid properties
  32. ```js
  33. isDataDesc({value: 'foo', bar: 'baz'})
  34. //=> false
  35. isDataDesc({value: 'foo', bar: 'baz'})
  36. //=> false
  37. isDataDesc({value: 'foo', get: function(){}})
  38. //=> false
  39. isDataDesc({get: function(){}, value: 'foo'})
  40. //=> false
  41. ```
  42. `false` when a value is not the correct type
  43. ```js
  44. isDataDesc({value: 'foo', enumerable: 'foo'})
  45. //=> false
  46. isDataDesc({value: 'foo', configurable: 'foo'})
  47. //=> false
  48. isDataDesc({value: 'foo', writable: 'foo'})
  49. //=> false
  50. ```
  51. ## Valid properties
  52. The only valid data descriptor properties are the following:
  53. * `configurable` (required)
  54. * `enumerable` (required)
  55. * `value` (optional)
  56. * `writable` (optional)
  57. To be a valid data descriptor, either `value` or `writable` must be defined.
  58. **Invalid properties**
  59. A descriptor may have additional _invalid_ properties (an error will **not** be thrown).
  60. ```js
  61. var foo = {};
  62. Object.defineProperty(foo, 'bar', {
  63. enumerable: true,
  64. whatever: 'blah', // invalid, but doesn't cause an error
  65. get: function() {
  66. return 'baz';
  67. }
  68. });
  69. console.log(foo.bar);
  70. //=> 'baz'
  71. ```
  72. ## About
  73. <details>
  74. <summary><strong>Contributing</strong></summary>
  75. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  76. </details>
  77. <details>
  78. <summary><strong>Running Tests</strong></summary>
  79. 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:
  80. ```sh
  81. $ npm install && npm test
  82. ```
  83. </details>
  84. <details>
  85. <summary><strong>Building docs</strong></summary>
  86. _(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.)_
  87. To generate the readme, run the following command:
  88. ```sh
  89. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  90. ```
  91. </details>
  92. ### Related projects
  93. You might also be interested in these projects:
  94. * [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.")
  95. * [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.")
  96. * [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.")
  97. * [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.")
  98. ### Contributors
  99. | **Commits** | **Contributor** |
  100. | --- | --- |
  101. | 21 | [jonschlinkert](https://github.com/jonschlinkert) |
  102. | 2 | [realityking](https://github.com/realityking) |
  103. ### Author
  104. **Jon Schlinkert**
  105. * [github/jonschlinkert](https://github.com/jonschlinkert)
  106. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  107. ### License
  108. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  109. Released under the [MIT License](LICENSE).
  110. ***
  111. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._