UNPKG

2.55 kBMarkdownView Raw
1# is-data-descriptor [![NPM version](https://badge.fury.io/js/is-data-descriptor.svg)](http://badge.fury.io/js/is-data-descriptor)
2
3> Returns true if a value appears to be a valid JavaScript data descriptor.
4
5## Install
6
7Install with [npm](https://www.npmjs.com/)
8
9```sh
10$ npm i is-data-descriptor --save
11```
12
13## Usage
14
15```js
16var isDataDescriptor = require('is-data-descriptor');
17```
18
19### true when the descriptor has valid properties
20
21And all of the descriptor properties are the correct JavaScript types.
22
23```js
24// `value` can be anything
25isDescriptor({value: 'foo'})
26isDescriptor({value: function() {}})
27isDescriptor({value: true})
28//=> true
29```
30
31### false when not an object
32
33```js
34isDescriptor('a')
35//=> false
36isDescriptor(null)
37//=> false
38isDescriptor([])
39//=> false
40```
41
42### false when the object has invalid properties
43
44```js
45isDescriptor({value: 'foo', bar: 'baz'})
46//=> false
47isDescriptor({value: 'foo', bar: 'baz'})
48//=> false
49isDescriptor({value: 'foo', get: function(){}})
50//=> false
51isDescriptor({get: function(){}, value: 'foo'})
52//=> false
53```
54
55### false when a value is not the correct type
56
57```js
58isDescriptor({value: 'foo', enumerable: 'foo'})
59//=> false
60isDescriptor({value: 'foo', configurable: 'foo'})
61//=> false
62isDescriptor({value: 'foo', writable: 'foo'})
63//=> false
64```
65
66## Related projects
67
68* [arr-diff](https://www.npmjs.com/package/arr-diff): Returns an array with only the unique values from the first array, by excluding all… [more](https://www.npmjs.com/package/arr-diff) | [homepage](https://github.com/jonschlinkert/arr-diff)
69* [is-accessor-descriptor](https://www.npmjs.com/package/is-accessor-descriptor): Returns true if a value is a valid JavaScript accessor descriptor. | [homepage](https://github.com/jonschlinkert/is-accessor-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
72## Running tests
73
74Install dev dependencies:
75
76```sh
77$ npm i -d && npm test
78```
79
80## Contributing
81
82Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-data-descriptor/issues/new).
83
84## Author
85
86**Jon Schlinkert**
87
88+ [github/jonschlinkert](https://github.com/jonschlinkert)
89+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
90
91## License
92
93Copyright © 2015 Jon Schlinkert
94Released under the MIT license.
95
96***
97
98_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 31, 2015._