time-to-botec

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

README.md (3240B)


      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 # isAccessorProperty
     22 
     23 > Test if an object's own property has an accessor descriptor.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var isAccessorProperty = require( '@stdlib/assert/is-accessor-property' );
     31 ```
     32 
     33 #### isAccessorProperty( value, property )
     34 
     35 Returns a `boolean` indicating if an object's own `property` has an accessor descriptor.
     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': 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 = isAccessorProperty( obj, 'foo' );
     65 // returns false
     66 
     67 bool = isAccessorProperty( obj, 'beep' );
     68 // returns false
     69 
     70 bool = isAccessorProperty( 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 = isAccessorProperty( 'beep', 'length' );
     86     // returns false
     87     ```
     88 
     89 -   Non-symbol property arguments are coerced to `strings`.
     90 
     91     ```javascript
     92     var defineProperty = require( '@stdlib/utils/define-property' );
     93 
     94     var obj = {};
     95 
     96     function getter() {
     97         return true;
     98     }
     99 
    100     defineProperty( obj, 'null', {
    101         'configurable': true,
    102         'enumerable': true,
    103         'get': getter
    104     });
    105 
    106     var bool = isAccessorProperty( 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 isAccessorProperty = require( '@stdlib/assert/is-accessor-property' );
    124 
    125 var bool = isAccessorProperty( [ 'a' ], 'length' );
    126 // returns false
    127 
    128 bool = isAccessorProperty( { 'a': 'b' }, 'a' );
    129 // returns false
    130 
    131 bool = isAccessorProperty( [ 'a' ], 0 );
    132 // returns false
    133 
    134 bool = isAccessorProperty( { 'null': false }, null );
    135 // returns false
    136 
    137 bool = isAccessorProperty( { '[object Object]': false }, {} );
    138 // returns false
    139 
    140 bool = isAccessorProperty( {}, 'toString' );
    141 // returns false
    142 
    143 bool = isAccessorProperty( {}, 'hasOwnProperty' );
    144 // returns false
    145 
    146 bool = isAccessorProperty( null, 'a' );
    147 // returns false
    148 
    149 bool = isAccessorProperty( void 0, 'a' );
    150 // returns false
    151 ```
    152 
    153 </section>
    154 
    155 <!-- /.examples -->
    156 
    157 <section class="links">
    158 
    159 </section>
    160 
    161 <!-- /.links -->