source: trip-planner-front/node_modules/is-data-descriptor/README.md@ 76712b2

Last change on this file since 76712b2 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[e29cc2e]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)
[6a3a178]2
3> Returns true if a value has the characteristics of a valid JavaScript data descriptor.
4
5## Install
6
7Install with [npm](https://www.npmjs.com/):
8
9```sh
[e29cc2e]10$ npm i is-data-descriptor --save
[6a3a178]11```
12
13## Usage
14
15```js
16var 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
25isDataDesc({value: 'foo'})
26isDataDesc({value: function() {}})
27isDataDesc({value: true})
28//=> true
29```
30
31`false` when not an object
32
33```js
34isDataDesc('a')
35//=> false
36isDataDesc(null)
37//=> false
38isDataDesc([])
39//=> false
40```
41
42`false` when the object has invalid properties
43
44```js
45isDataDesc({value: 'foo', bar: 'baz'})
46//=> false
47isDataDesc({value: 'foo', bar: 'baz'})
48//=> false
49isDataDesc({value: 'foo', get: function(){}})
50//=> false
51isDataDesc({get: function(){}, value: 'foo'})
52//=> false
53```
54
55`false` when a value is not the correct type
56
57```js
58isDataDesc({value: 'foo', enumerable: 'foo'})
59//=> false
60isDataDesc({value: 'foo', configurable: 'foo'})
61//=> false
62isDataDesc({value: 'foo', writable: 'foo'})
63//=> false
64```
65
66## Valid properties
67
68The only valid data descriptor properties are the following:
69
70* `configurable` (required)
71* `enumerable` (required)
72* `value` (optional)
73* `writable` (optional)
74
75To be a valid data descriptor, either `value` or `writable` must be defined.
76
77**Invalid properties**
78
79A descriptor may have additional _invalid_ properties (an error will **not** be thrown).
80
81```js
82var foo = {};
83
84Object.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
92console.log(foo.bar);
93//=> 'baz'
94```
95
[e29cc2e]96## Related projects
[6a3a178]97
[e29cc2e]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)
[6a3a178]101
[e29cc2e]102## Running tests
[6a3a178]103
[e29cc2e]104Install dev dependencies:
[6a3a178]105
106```sh
[e29cc2e]107$ npm i -d && npm test
[6a3a178]108```
109
[e29cc2e]110## Contributing
[6a3a178]111
[e29cc2e]112Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-data-descriptor/issues/new).
[6a3a178]113
[e29cc2e]114## Author
[6a3a178]115
116**Jon Schlinkert**
117
118* [github/jonschlinkert](https://github.com/jonschlinkert)
[e29cc2e]119* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
[6a3a178]120
[e29cc2e]121## License
[6a3a178]122
[e29cc2e]123Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
124Released under the MIT license.
[6a3a178]125
126***
127
[e29cc2e]128_This file was generated by [verb](https://github.com/verbose/verb) on December 28, 2015._
Note: See TracBrowser for help on using the repository browser.