time-to-botec

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

README.md (3204B)


      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 # Basename
     22 
     23 > [Regular expression][regexp] to capture the last part of a path.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var reBasename = require( '@stdlib/regexp/basename' );
     31 ```
     32 
     33 #### reBasename( \[platform] )
     34 
     35 Returns a [regular expression][regexp] to capture the last part of a path.
     36 
     37 ```javascript
     38 var RE = reBasename();
     39 // returns <RegExp>
     40 
     41 RE = reBasename( 'posix' );
     42 // returns <RegExp>
     43 
     44 var base = RE.exec( '/foo/bar/index.js' )[ 1 ];
     45 // returns 'index.js'
     46 
     47 RE = reBasename( 'win32' );
     48 // returns <RegExp>
     49 
     50 base = RE.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
     51 // returns 'index.js'
     52 ```
     53 
     54 #### reBasename.REGEXP
     55 
     56 [Regular expression][regexp] to capture the last part of a path.
     57 
     58 ```javascript
     59 var bool = ( reBasename.REGEXP.toString() === reBasename().toString() );
     60 // returns true
     61 ```
     62 
     63 #### reBasename.REGEXP_POSIX
     64 
     65 [Regular expression][@stdlib/regexp/basename-posix] to capture the last part of a [POSIX][posix] path. 
     66 
     67 ```javascript
     68 var base = reBasename.REGEXP_POSIX.exec( '/foo/bar/index.js' )[ 1 ];
     69 // returns 'index.js'
     70 ```
     71 
     72 #### reBasename.REGEXP_WIN32
     73 
     74 [Regular expression][@stdlib/regexp/basename-windows] to capture the last part of a Windows path. 
     75 
     76 ```javascript
     77 var base = reBasename.REGEXP_WIN32.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
     78 // returns 'index.js'
     79 ```
     80 
     81 </section>
     82 
     83 <!-- /.usage -->
     84 
     85 <section class="notes">
     86 
     87 ## Notes
     88 
     89 -   The as `REGEXP` exported [regular expression][regexp] is [platform][@stdlib/assert/is-windows]-dependent. If the current process is running on Windows, `REGEXP === REGEXP_WIN32`; otherwise, `REGEXP === REGEXP_POSIX`.
     90 
     91 </section>
     92 
     93 <!-- /.notes -->
     94 
     95 <section class="examples">
     96 
     97 ## Examples
     98 
     99 <!-- eslint no-undef: "error" -->
    100 
    101 ```javascript
    102 var reBasename = require( '@stdlib/regexp/basename' );
    103 var RE_BASENAME = reBasename();
    104 
    105 // Assuming a POSIX platform...
    106 var base = RE_BASENAME.exec( '/foo/bar/index.js' )[ 1 ];
    107 // returns 'index.js'
    108 
    109 base = reBasename.REGEXP_POSIX.exec( '/foo/bar/home.html' )[ 1 ];
    110 // returns 'home.html'
    111 
    112 base = reBasename.REGEXP_WIN32.exec( 'C:\\foo\\bar\\home.html' )[ 1 ];
    113 // returns 'home.html'
    114 ```
    115 
    116 </section>
    117 
    118 <!-- /.examples -->
    119 
    120 <section class="links">
    121 
    122 [regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    123 
    124 [posix]: https://en.wikipedia.org/wiki/POSIX
    125 
    126 [@stdlib/assert/is-windows]: https://www.npmjs.com/package/@stdlib/assert-is-windows
    127 
    128 [@stdlib/regexp/basename-posix]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/basename-posix
    129 
    130 [@stdlib/regexp/basename-windows]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/basename-windows
    131 
    132 </section>
    133 
    134 <!-- /.links -->