time-to-botec

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

README.md (2143B)


      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 # Function Name
     22 
     23 > [Regular expression][regexp] to capture a function name.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var reFunctionName = require( '@stdlib/regexp/function-name' );
     31 ```
     32 
     33 #### reFunctionName
     34 
     35 Returns a [regular expression][regexp] to capture a `function` name.
     36 
     37 ```javascript
     38 function beep() {
     39     return 'boop';
     40 }
     41 
     42 var RE_FUNCTION_NAME = reFunctionName();
     43 var str = RE_FUNCTION_NAME.exec( beep.toString() )[ 1 ];
     44 // returns 'beep'
     45 ```
     46 
     47 #### reFunctionName.REGEXP
     48 
     49 [Regular expression][regexp] to capture a `function` name.
     50 
     51 <!-- eslint-disable stdlib/no-builtin-math -->
     52 
     53 ```javascript
     54 var str = reFunctionName.REGEXP.exec( Math.sqrt.toString() )[ 1 ];
     55 // returns 'sqrt'
     56 ```
     57 
     58 </section>
     59 
     60 <!-- /.usage -->
     61 
     62 <section class="examples">
     63 
     64 ## Examples
     65 
     66 <!-- eslint-disable func-names, no-restricted-syntax, no-empty-function, stdlib/no-builtin-math -->
     67 
     68 <!-- eslint no-undef: "error" -->
     69 
     70 ```javascript
     71 var Int8Array = require( '@stdlib/array/int8' );
     72 var reFunctionName = require( '@stdlib/regexp/function-name' );
     73 var RE_FUNCTION_NAME = reFunctionName();
     74 
     75 function fname( fcn ) {
     76     return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];
     77 }
     78 
     79 var f = fname( Math.sqrt );
     80 // returns 'sqrt'
     81 
     82 f = fname( Int8Array );
     83 // returns 'Int8Array'
     84 
     85 f = fname( Object.prototype.toString );
     86 // returns 'toString'
     87 
     88 f = fname( function () {} );
     89 // returns ''
     90 ```
     91 
     92 </section>
     93 
     94 <!-- /.examples -->
     95 
     96 <section class="links">
     97 
     98 [regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
     99 
    100 </section>
    101 
    102 <!-- /.links -->