README.md (3364B)
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 # isWriteOnlyProperty 22 23 > Test if an object's own property is [write-only][@stdlib/utils/define-write-only-accessor]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isWriteOnlyProperty = require( '@stdlib/assert/is-write-only-property' ); 31 ``` 32 33 #### isWriteOnlyProperty( value, property ) 34 35 Returns a `boolean` indicating if a `value` has a [write-only][@stdlib/utils/define-write-only-accessor] `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': true, 56 'set': function setter( v ) { 57 obj.foo = v; 58 } 59 }); 60 61 var bool = isWriteOnlyProperty( obj, 'foo' ); 62 // returns false 63 64 bool = isWriteOnlyProperty( obj, 'beep' ); 65 // returns false 66 67 bool = isWriteOnlyProperty( obj, 'accessor' ); 68 // returns true 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 = isWriteOnlyProperty( 'beep', 'length' ); 83 // returns false 84 ``` 85 86 - Property arguments are coerced to `strings`. 87 88 ```javascript 89 var defineProperty = require( '@stdlib/utils/define-property' ); 90 91 var obj = {}; 92 93 function setter( v ) { 94 obj.null = v; 95 } 96 97 defineProperty( obj, 'null', { 98 'configurable': false, 99 'enumerable': true, 100 'set': setter 101 }); 102 103 var bool = isWriteOnlyProperty( obj, null ); 104 // returns true 105 ``` 106 107 </section> 108 109 <!-- /.notes --> 110 111 <section class="examples"> 112 113 ## Examples 114 115 <!-- eslint-disable object-curly-newline --> 116 117 <!-- eslint no-undef: "error" --> 118 119 ```javascript 120 var isWriteOnlyProperty = require( '@stdlib/assert/is-write-only-property' ); 121 122 var bool = isWriteOnlyProperty( 'a', 'length' ); 123 // returns false 124 125 bool = isWriteOnlyProperty( { 'a': 'b' }, 'a' ); 126 // returns false 127 128 bool = isWriteOnlyProperty( [ 'a' ], 0 ); 129 // returns false 130 131 bool = isWriteOnlyProperty( { 'null': false }, null ); 132 // returns false 133 134 bool = isWriteOnlyProperty( { '[object Object]': false }, {} ); 135 // returns false 136 137 bool = isWriteOnlyProperty( {}, 'toString' ); 138 // returns false 139 140 bool = isWriteOnlyProperty( {}, 'hasOwnProperty' ); 141 // returns false 142 143 bool = isWriteOnlyProperty( null, 'a' ); 144 // returns false 145 146 bool = isWriteOnlyProperty( void 0, 'a' ); 147 // returns false 148 ``` 149 150 </section> 151 152 <!-- /.examples --> 153 154 <section class="links"> 155 156 [@stdlib/utils/define-write-only-accessor]: https://www.npmjs.com/package/@stdlib/utils-define-write-only-accessor 157 158 </section> 159 160 <!-- /.links -->