README.md (2907B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # isDataProperty 22 23 > Test if an object's own property has a data descriptor. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isDataProperty = require( '@stdlib/assert/is-data-property' ); 31 ``` 32 33 #### isDataProperty( value, property ) 34 35 Returns a `boolean` indicating if a `value` has a data `property`. 36 37 <!-- eslint-disable no-restricted-syntax --> 38 39 ```javascript 40 var defineProperty = require( '@stdlib/utils/define-property' ); 41 42 var obj = { 43 'foo': 'bar' 44 }; 45 46 defineProperty( obj, 'beep', { 47 'configurable': false, 48 'enumerable': false, 49 'writable': false, 50 'value': 'boop' 51 }); 52 53 defineProperty( obj, 'accessor', { 54 'configurable': false, 55 'enumerable': false, 56 'get': function getter() { 57 return obj.foo; 58 }, 59 'set': function setter( v ) { 60 obj.foo = v; 61 } 62 }); 63 64 var bool = isDataProperty( obj, 'foo' ); 65 // returns true 66 67 bool = isDataProperty( obj, 'beep' ); 68 // returns true 69 70 bool = isDataProperty( obj, 'accessor' ); 71 // returns false 72 ``` 73 74 </section> 75 76 <!-- /.usage --> 77 78 <section class="notes"> 79 80 ## Notes 81 82 - Value arguments other than `null` or `undefined` are coerced to `objects`. 83 84 ```javascript 85 var bool = isDataProperty( 'beep', 'length' ); 86 // returns true 87 ``` 88 89 - Non-symbol property arguments are coerced to `strings`. 90 91 ```javascript 92 var obj = { 93 'null': 'foo' 94 }; 95 96 var bool = isDataProperty( obj, null ); 97 // returns true 98 ``` 99 100 </section> 101 102 <!-- /.notes --> 103 104 <section class="examples"> 105 106 ## Examples 107 108 <!-- eslint-disable object-curly-newline --> 109 110 <!-- eslint no-undef: "error" --> 111 112 ```javascript 113 var isDataProperty = require( '@stdlib/assert/is-data-property' ); 114 115 var bool = isDataProperty( [ 'a' ], 'length' ); 116 // returns true 117 118 bool = isDataProperty( { 'a': 'b' }, 'a' ); 119 // returns true 120 121 bool = isDataProperty( [ 'a' ], 0 ); 122 // returns true 123 124 bool = isDataProperty( { 'null': false }, null ); 125 // returns true 126 127 bool = isDataProperty( { '[object Object]': false }, {} ); 128 // returns true 129 130 bool = isDataProperty( {}, 'toString' ); 131 // returns false 132 133 bool = isDataProperty( {}, 'hasOwnProperty' ); 134 // returns false 135 136 bool = isDataProperty( null, 'a' ); 137 // returns false 138 139 bool = isDataProperty( void 0, 'a' ); 140 // returns false 141 ``` 142 143 </section> 144 145 <!-- /.examples --> 146 147 <section class="links"> 148 149 </section> 150 151 <!-- /.links -->