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