README.md (3159B)
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 # isEnumerableProperty 22 23 > Test if an object's own property is enumerable. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isEnumerableProperty = require( '@stdlib/assert/is-enumerable-property' ); 31 ``` 32 33 #### isEnumerableProperty( value, property ) 34 35 Returns a `boolean` indicating if a `value` has an enumerable `property`. 36 37 ```javascript 38 var value = { 39 'beep': 'boop' 40 }; 41 42 var bool = isEnumerableProperty( value, 'beep' ); 43 // returns true 44 45 bool = isEnumerableProperty( value, 'constructor' ); 46 // returns false 47 ``` 48 49 </section> 50 51 <!-- /.usage --> 52 53 <section class="notes"> 54 55 ## Notes 56 57 - In contrast to the native [Object.prototype.propertyIsEnumerable][mdn-object-property-is-enumerable], this function does **not** throw when provided `null` or `undefined`. Instead, the function returns `false`. 58 59 ```javascript 60 var bool = isEnumerableProperty( null, 'a' ); 61 // returns false 62 63 bool = isEnumerableProperty( void 0, 'a' ); 64 // returns false 65 ``` 66 67 - Value arguments other than `null` or `undefined` are coerced to `objects`. 68 69 ```javascript 70 var bool = isEnumerableProperty( 'beep', '1' ); 71 // returns true 72 ``` 73 74 - Property arguments are coerced to `strings`. 75 76 ```javascript 77 var value = { 78 'null': false 79 }; 80 var bool = isEnumerableProperty( value, null ); 81 // returns true 82 83 value = { 84 '[object Object]': false 85 }; 86 bool = isEnumerableProperty( value, {} ); 87 // returns true 88 ``` 89 90 </section> 91 92 <!-- /.notes --> 93 94 <section class="examples"> 95 96 ## Examples 97 98 <!-- eslint-disable object-curly-newline --> 99 100 <!-- eslint no-undef: "error" --> 101 102 ```javascript 103 var isEnumerableProperty = require( '@stdlib/assert/is-enumerable-property' ); 104 105 var bool = isEnumerableProperty( { 'a': 'b' }, 'a' ); 106 // returns true 107 108 bool = isEnumerableProperty( [ 'a' ], 0 ); 109 // returns true 110 111 bool = isEnumerableProperty( [ 'a' ], 'length' ); 112 // returns false 113 114 bool = isEnumerableProperty( {}, 'toString' ); 115 // returns false 116 117 bool = isEnumerableProperty( {}, 'hasOwnProperty' ); 118 // returns false 119 120 bool = isEnumerableProperty( null, 'a' ); 121 // returns false 122 123 bool = isEnumerableProperty( void 0, 'a' ); 124 // returns false 125 126 bool = isEnumerableProperty( { 'null': false }, null ); 127 // returns true 128 129 bool = isEnumerableProperty( { '[object Object]': false }, {} ); 130 // returns true 131 ``` 132 133 </section> 134 135 <!-- /.examples --> 136 137 <section class="links"> 138 139 [mdn-object-property-is-enumerable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable 140 141 </section> 142 143 <!-- /.links -->