.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / class-utils / node_modules / is-data-descriptor / README.md
1 # is-data-descriptor [![NPM version](https://img.shields.io/npm/v/is-data-descriptor.svg)](https://www.npmjs.com/package/is-data-descriptor) [![Build Status](https://img.shields.io/travis/jonschlinkert/is-data-descriptor.svg)](https://travis-ci.org/jonschlinkert/is-data-descriptor)
2
3 > Returns true if a value has the characteristics of a valid JavaScript data descriptor.
4
5 ## Install
6
7 Install with [npm](https://www.npmjs.com/):
8
9 ```sh
10 $ npm i is-data-descriptor --save
11 ```
12
13 ## Usage
14
15 ```js
16 var isDataDesc = require('is-data-descriptor');
17 ```
18
19 ## Examples
20
21 `true` when the descriptor has valid properties with valid values.
22
23 ```js
24 // `value` can be anything
25 isDataDesc({value: 'foo'})
26 isDataDesc({value: function() {}})
27 isDataDesc({value: true})
28 //=> true
29 ```
30
31 `false` when not an object
32
33 ```js
34 isDataDesc('a')
35 //=> false
36 isDataDesc(null)
37 //=> false
38 isDataDesc([])
39 //=> false
40 ```
41
42 `false` when the object has invalid properties
43
44 ```js
45 isDataDesc({value: 'foo', bar: 'baz'})
46 //=> false
47 isDataDesc({value: 'foo', bar: 'baz'})
48 //=> false
49 isDataDesc({value: 'foo', get: function(){}})
50 //=> false
51 isDataDesc({get: function(){}, value: 'foo'})
52 //=> false
53 ```
54
55 `false` when a value is not the correct type
56
57 ```js
58 isDataDesc({value: 'foo', enumerable: 'foo'})
59 //=> false
60 isDataDesc({value: 'foo', configurable: 'foo'})
61 //=> false
62 isDataDesc({value: 'foo', writable: 'foo'})
63 //=> false
64 ```
65
66 ## Valid properties
67
68 The only valid data descriptor properties are the following:
69
70 * `configurable` (required)
71 * `enumerable` (required)
72 * `value` (optional)
73 * `writable` (optional)
74
75 To be a valid data descriptor, either `value` or `writable` must be defined.
76
77 **Invalid properties**
78
79 A descriptor may have additional _invalid_ properties (an error will **not** be thrown).
80
81 ```js
82 var foo = {};
83
84 Object.defineProperty(foo, 'bar', {
85   enumerable: true,
86   whatever: 'blah', // invalid, but doesn't cause an error
87   get: function() {
88     return 'baz';
89   }
90 });
91
92 console.log(foo.bar);
93 //=> 'baz'
94 ```
95
96 ## Related projects
97
98 * [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)
99 * [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)
100 * [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)
101
102 ## Running tests
103
104 Install dev dependencies:
105
106 ```sh
107 $ npm i -d && npm test
108 ```
109
110 ## Contributing
111
112 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-data-descriptor/issues/new).
113
114 ## Author
115
116 **Jon Schlinkert**
117
118 * [github/jonschlinkert](https://github.com/jonschlinkert)
119 * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
120
121 ## License
122
123 Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
124 Released under the MIT license.
125
126 ***
127
128 _This file was generated by [verb](https://github.com/verbose/verb) on December 28, 2015._