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