README.md (3066B)
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 # isDataPropertyIn 22 23 > Test if an object's own or inherited property has a data descriptor. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isDataPropertyIn = require( '@stdlib/assert/is-data-property-in' ); 31 ``` 32 33 #### isDataPropertyIn( value, property ) 34 35 Returns a `boolean` indicating if a `value` has a data `property` (either own or inherited). 36 37 <!-- eslint-disable no-restricted-syntax --> 38 39 ```javascript 40 var defineProperty = require( '@stdlib/utils/define-property' ); 41 42 var bool; 43 var obj; 44 45 function Foo() { 46 this.foo = 'bar'; 47 return this; 48 } 49 50 defineProperty( Foo.prototype, 'beep', { 51 'configurable': false, 52 'enumerable': false, 53 'writable': false, 54 'value': 'boop' 55 }); 56 57 defineProperty( Foo.prototype, 'accessor', { 58 'configurable': false, 59 'enumerable': false, 60 'get': function getter() { 61 return obj.foo; 62 }, 63 'set': function setter( v ) { 64 obj.foo = v; 65 } 66 }); 67 68 obj = new Foo(); 69 70 bool = isDataPropertyIn( obj, 'foo' ); 71 // returns true 72 73 bool = isDataPropertyIn( obj, 'beep' ); 74 // returns true 75 76 bool = isDataPropertyIn( obj, 'accessor' ); 77 // returns false 78 ``` 79 80 </section> 81 82 <!-- /.usage --> 83 84 <section class="notes"> 85 86 ## Notes 87 88 - Value arguments other than `null` or `undefined` are coerced to `objects`. 89 90 ```javascript 91 var bool = isDataPropertyIn( 'beep', 'length' ); 92 // returns true 93 ``` 94 95 - Non-symbol property arguments are coerced to `strings`. 96 97 ```javascript 98 var obj = { 99 'null': 'foo' 100 }; 101 102 var bool = isDataPropertyIn( obj, null ); 103 // returns true 104 ``` 105 106 </section> 107 108 <!-- /.notes --> 109 110 <section class="examples"> 111 112 ## Examples 113 114 <!-- eslint-disable object-curly-newline --> 115 116 <!-- eslint no-undef: "error" --> 117 118 ```javascript 119 var isDataPropertyIn = require( '@stdlib/assert/is-data-property-in' ); 120 121 var bool = isDataPropertyIn( [ 'a' ], 'length' ); 122 // returns true 123 124 bool = isDataPropertyIn( { 'a': 'b' }, 'a' ); 125 // returns true 126 127 bool = isDataPropertyIn( [ 'a' ], 0 ); 128 // returns true 129 130 bool = isDataPropertyIn( { 'null': false }, null ); 131 // returns true 132 133 bool = isDataPropertyIn( { '[object Object]': false }, {} ); 134 // returns true 135 136 bool = isDataPropertyIn( {}, 'toString' ); 137 // returns true 138 139 bool = isDataPropertyIn( {}, 'hasOwnProperty' ); 140 // returns true 141 142 bool = isDataPropertyIn( null, 'a' ); 143 // returns false 144 145 bool = isDataPropertyIn( void 0, 'a' ); 146 // returns false 147 ``` 148 149 </section> 150 151 <!-- /.examples --> 152 153 <section class="links"> 154 155 </section> 156 157 <!-- /.links -->