README.md (3074B)
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 # isReadWritePropertyIn 22 23 > Test if an object's own or inherited property is readable and writable. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isReadWritePropertyIn = require( '@stdlib/assert/is-read-write-property-in' ); 31 ``` 32 33 #### isReadWritePropertyIn( value, property ) 34 35 Returns a `boolean` indicating if a `value` has a readable **and** writable `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': true, 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 = isReadWritePropertyIn( obj, 'foo' ); 65 // returns true 66 67 bool = isReadWritePropertyIn( obj, 'beep' ); 68 // returns true 69 70 bool = isReadWritePropertyIn( obj, 'accessor' ); 71 // returns true 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 = isReadWritePropertyIn( 'beep', 'length' ); 86 // returns false 87 ``` 88 89 - Property arguments are coerced to `strings`. 90 91 ```javascript 92 var obj = { 93 'null': 'foo' 94 }; 95 96 var bool = isReadWritePropertyIn( 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 isReadWritePropertyIn = require( '@stdlib/assert/is-read-write-property-in' ); 114 115 var bool = isReadWritePropertyIn( [ 'a' ], 'length' ); 116 // returns true 117 118 bool = isReadWritePropertyIn( { 'a': 'b' }, 'a' ); 119 // returns true 120 121 bool = isReadWritePropertyIn( [ 'a' ], 0 ); 122 // returns true 123 124 bool = isReadWritePropertyIn( { 'null': false }, null ); 125 // returns true 126 127 bool = isReadWritePropertyIn( { '[object Object]': false }, {} ); 128 // returns true 129 130 bool = isReadWritePropertyIn( {}, 'toString' ); 131 // returns true 132 133 bool = isReadWritePropertyIn( {}, 'hasOwnProperty' ); 134 // returns true 135 136 bool = isReadWritePropertyIn( null, 'a' ); 137 // returns false 138 139 bool = isReadWritePropertyIn( void 0, 'a' ); 140 // returns false 141 ``` 142 143 </section> 144 145 <!-- /.examples --> 146 147 <section class="links"> 148 149 </section> 150 151 <!-- /.links -->