time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3441B)


      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 # isReadOnlyPropertyIn
     22 
     23 > Test if an object's own or inherited property is [read-only][@stdlib/utils/define-read-only-property].
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var isReadOnlyPropertyIn = require( '@stdlib/assert/is-read-only-property-in' );
     31 ```
     32 
     33 #### isReadOnlyPropertyIn( 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 bool;
     43 var obj;
     44 
     45 function Foo() {
     46     this.foo = 'bar';
     47     return this;
     48 }
     49 
     50 defineProperty( Foo.prototype, 'beep', {
     51     'configurable': false,
     52     'enumerable': false,
     53     'writable': false,
     54     'value': 'boop'
     55 });
     56 
     57 defineProperty( Foo.prototype, 'accessor', {
     58     'configurable': false,
     59     'enumerable': true,
     60     'get': function getter() {
     61         return obj.foo;
     62     }
     63 });
     64 
     65 obj = new Foo();
     66 
     67 bool = isReadOnlyPropertyIn( obj, 'foo' );
     68 // returns false
     69 
     70 bool = isReadOnlyPropertyIn( obj, 'beep' );
     71 // returns true
     72 
     73 bool = isReadOnlyPropertyIn( obj, 'accessor' );
     74 // returns true
     75 ```
     76 
     77 </section>
     78 
     79 <!-- /.usage -->
     80 
     81 <section class="notes">
     82 
     83 ## Notes
     84 
     85 -   Value arguments other than `null` or `undefined` are coerced to `objects`.
     86 
     87     ```javascript
     88     var bool = isReadOnlyPropertyIn( 'beep', 'length' );
     89     // returns true
     90     ```
     91 
     92 -   Property arguments are coerced to `strings`.
     93 
     94     ```javascript
     95     var defineProperty = require( '@stdlib/utils/define-property' );
     96 
     97     var obj = {};
     98 
     99     defineProperty( obj, 'null', {
    100         'configurable': false,
    101         'enumerable': true,
    102         'writable': false,
    103         'value': true
    104     });
    105 
    106     var bool = isReadOnlyPropertyIn( obj, null );
    107     // returns true
    108     ```
    109 
    110 </section>
    111 
    112 <!-- /.notes -->
    113 
    114 <section class="examples">
    115 
    116 ## Examples
    117 
    118 <!-- eslint-disable object-curly-newline -->
    119 
    120 <!-- eslint no-undef: "error" -->
    121 
    122 ```javascript
    123 var isReadOnlyPropertyIn = require( '@stdlib/assert/is-read-only-property-in' );
    124 
    125 var bool = isReadOnlyPropertyIn( 'a', 'length' );
    126 // returns true
    127 
    128 bool = isReadOnlyPropertyIn( { 'a': 'b' }, 'a' );
    129 // returns false
    130 
    131 bool = isReadOnlyPropertyIn( [ 'a' ], 0 );
    132 // returns false
    133 
    134 bool = isReadOnlyPropertyIn( { 'null': false }, null );
    135 // returns false
    136 
    137 bool = isReadOnlyPropertyIn( { '[object Object]': false }, {} );
    138 // returns false
    139 
    140 bool = isReadOnlyPropertyIn( {}, 'toString' );
    141 // returns false
    142 
    143 bool = isReadOnlyPropertyIn( {}, 'hasOwnProperty' );
    144 // returns false
    145 
    146 bool = isReadOnlyPropertyIn( null, 'a' );
    147 // returns false
    148 
    149 bool = isReadOnlyPropertyIn( void 0, 'a' );
    150 // returns false
    151 ```
    152 
    153 </section>
    154 
    155 <!-- /.examples -->
    156 
    157 <section class="links">
    158 
    159 [@stdlib/utils/define-read-only-property]: https://www.npmjs.com/package/@stdlib/utils-define-read-only-property
    160 
    161 </section>
    162 
    163 <!-- /.links -->