time-to-botec

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

README.md (2723B)


      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 # hasProperty
     22 
     23 > Test if an object has a specified property, either own or inherited.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var hasProp = require( '@stdlib/assert/has-property' );
     31 ```
     32 
     33 #### hasProp( value, property )
     34 
     35 Returns a `boolean` indicating if a `value` has a specified `property`, either own or inherited.
     36 
     37 ```javascript
     38 var value = {
     39     'beep': 'boop'
     40 };
     41 
     42 var bool = hasProp( value, 'beep' );
     43 // returns true
     44 
     45 bool = hasProp( value, 'hasOwnProperty' );
     46 // returns true
     47 
     48 bool = hasProp( value, 'bap' );
     49 // returns false
     50 ```
     51 
     52 </section>
     53 
     54 <!-- /.usage -->
     55 
     56 <section class="notes">
     57 
     58 ## Notes
     59 
     60 -   The function does **not** throw when provided `null` or `undefined`. Instead, the function returns `false`.
     61 
     62     ```javascript
     63     var bool = hasProp( null, 'a' );
     64     // returns false
     65 
     66     bool = hasProp( void 0, 'a' );
     67     // returns false
     68     ```
     69 
     70 -   Value arguments other than `null` or `undefined` are coerced to `objects`.
     71 
     72     ```javascript
     73     var bool = hasProp( 'beep', 'length' );
     74     // returns true
     75     ```
     76 
     77 -   Non-symbol property arguments are coerced to `strings`.
     78 
     79     ```javascript
     80     var value = {
     81         'null': false
     82     };
     83     var bool = hasProp( value, null );
     84     // returns true
     85 
     86     value = {
     87         '[object Object]': false
     88     };
     89     bool = hasProp( value, {} );
     90     // returns true
     91     ```
     92 
     93 </section>
     94 
     95 <!-- /.notes -->
     96 
     97 <section class="examples">
     98 
     99 ## Examples
    100 
    101 <!-- eslint-disable object-curly-newline, object-curly-spacing -->
    102 
    103 <!-- eslint no-undef: "error" -->
    104 
    105 ```javascript
    106 var hasProp = require( '@stdlib/assert/has-property' );
    107 
    108 var bool = hasProp( { 'a': 'b' }, 'a' );
    109 // returns true
    110 
    111 bool = hasProp( {}, 'hasOwnProperty' );
    112 // returns true
    113 
    114 bool = hasProp( { 'a': 'b' }, 'c' );
    115 // returns false
    116 
    117 bool = hasProp( { 'a': 'b' }, null );
    118 // returns false
    119 
    120 bool = hasProp( null, 'a' );
    121 // returns false
    122 
    123 bool = hasProp( void 0, 'a' );
    124 // returns false
    125 
    126 bool = hasProp( { 'null': false }, null );
    127 // returns true
    128 
    129 bool = hasProp( { '[object Object]': false }, {} );
    130 // returns true
    131 ```
    132 
    133 </section>
    134 
    135 <!-- /.examples -->
    136 
    137 <section class="links">
    138 
    139 </section>
    140 
    141 <!-- /.links -->