time-to-botec

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

README.md (2692B)


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