source: trip-planner-front/node_modules/is-descriptor/README.md@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.7 KB
RevLine 
[6a3a178]1# is-descriptor [![NPM version](https://img.shields.io/npm/v/is-descriptor.svg?style=flat)](https://www.npmjs.com/package/is-descriptor) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-descriptor.svg?style=flat)](https://npmjs.org/package/is-descriptor) [![NPM total downloads](https://img.shields.io/npm/dt/is-descriptor.svg?style=flat)](https://npmjs.org/package/is-descriptor) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-descriptor.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-descriptor)
2
3> Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
4
5## Install
6
7Install with [npm](https://www.npmjs.com/):
8
9```sh
10$ npm install --save is-descriptor
11```
12
13## Usage
14
15```js
16var isDescriptor = require('is-descriptor');
17
18isDescriptor({value: 'foo'})
19//=> true
20isDescriptor({get: function(){}, set: function(){}})
21//=> true
22isDescriptor({get: 'foo', set: function(){}})
23//=> false
24```
25
26You may also check for a descriptor by passing an object as the first argument and property name (`string`) as the second argument.
27
28```js
29var obj = {};
30obj.foo = 'abc';
31
32Object.defineProperty(obj, 'bar', {
33 value: 'xyz'
34});
35
36isDescriptor(obj, 'foo');
37//=> true
38isDescriptor(obj, 'bar');
39//=> true
40```
41
42## Examples
43
44### value type
45
46`false` when not an object
47
48```js
49isDescriptor('a');
50//=> false
51isDescriptor(null);
52//=> false
53isDescriptor([]);
54//=> false
55```
56
57### data descriptor
58
59`true` when the object has valid properties with valid values.
60
61```js
62isDescriptor({value: 'foo'});
63//=> true
64isDescriptor({value: noop});
65//=> true
66```
67
68`false` when the object has invalid properties
69
70```js
71isDescriptor({value: 'foo', bar: 'baz'});
72//=> false
73isDescriptor({value: 'foo', bar: 'baz'});
74//=> false
75isDescriptor({value: 'foo', get: noop});
76//=> false
77isDescriptor({get: noop, value: noop});
78//=> false
79```
80
81`false` when a value is not the correct type
82
83```js
84isDescriptor({value: 'foo', enumerable: 'foo'});
85//=> false
86isDescriptor({value: 'foo', configurable: 'foo'});
87//=> false
88isDescriptor({value: 'foo', writable: 'foo'});
89//=> false
90```
91
92### accessor descriptor
93
94`true` when the object has valid properties with valid values.
95
96```js
97isDescriptor({get: noop, set: noop});
98//=> true
99isDescriptor({get: noop});
100//=> true
101isDescriptor({set: noop});
102//=> true
103```
104
105`false` when the object has invalid properties
106
107```js
108isDescriptor({get: noop, set: noop, bar: 'baz'});
109//=> false
110isDescriptor({get: noop, writable: true});
111//=> false
112isDescriptor({get: noop, value: true});
113//=> false
114```
115
116`false` when an accessor is not a function
117
118```js
119isDescriptor({get: noop, set: 'baz'});
120//=> false
121isDescriptor({get: 'foo', set: noop});
122//=> false
123isDescriptor({get: 'foo', bar: 'baz'});
124//=> false
125isDescriptor({get: 'foo', set: 'baz'});
126//=> false
127```
128
129`false` when a value is not the correct type
130
131```js
132isDescriptor({get: noop, set: noop, enumerable: 'foo'});
133//=> false
134isDescriptor({set: noop, configurable: 'foo'});
135//=> false
136isDescriptor({get: noop, configurable: 'foo'});
137//=> false
138```
139
140## About
141
142### Related projects
143
144* [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.")
145* [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.")
146* [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.")
147* [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.")
148
149### Contributing
150
151Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
152
153### Contributors
154
155| **Commits** | **Contributor** |
156| --- | --- |
157| 24 | [jonschlinkert](https://github.com/jonschlinkert) |
158| 1 | [doowb](https://github.com/doowb) |
159| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
160
161### Building docs
162
163_(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.)_
164
165To generate the readme, run the following command:
166
167```sh
168$ npm install -g verbose/verb#dev verb-generate-readme && verb
169```
170
171### Running tests
172
173Running 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:
174
175```sh
176$ npm install && npm test
177```
178
179### Author
180
181**Jon Schlinkert**
182
183* [github/jonschlinkert](https://github.com/jonschlinkert)
184* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
185
186### License
187
188Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
189Released under the [MIT License](LICENSE).
190
191***
192
193_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 22, 2017._
Note: See TracBrowser for help on using the repository browser.