time-to-botec

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

README.md (3136B)


      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 # Filename Extension
     22 
     23 > [Regular expression][regexp] to capture a filename extension.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var reExtname = require( '@stdlib/regexp/extname' );
     31 ```
     32 
     33 #### reExtname( \[platform] )
     34 
     35 Returns a [regular expression][regexp] to capture a filename extension.
     36 
     37 ```javascript
     38 var RE = reExtname();
     39 // returns <RegExp>
     40 
     41 RE = reExtname( 'posix' );
     42 // returns <RegExp>
     43 
     44 var ext = RE.exec( '/foo/bar/index.js' )[ 1 ];
     45 // returns '.js'
     46 
     47 RE = reExtname( 'win32' );
     48 // returns <RegExp>
     49 
     50 ext = RE.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
     51 // returns '.js'
     52 ```
     53 
     54 #### reExtname.REGEXP
     55 
     56 [Regular expression][regexp] to capture a filename extension.
     57 
     58 ```javascript
     59 var bool = ( reExtname.REGEXP.toString() === reExtname().toString() );
     60 // returns true
     61 ```
     62 
     63 #### reExtname.REGEXP_POSIX
     64 
     65 [Regular expression][@stdlib/regexp/extname-posix] to capture a [POSIX][posix] filename extension.
     66 
     67 ```javascript
     68 var ext = reExtname.REGEXP_POSIX.exec( '/foo/bar/index.js' )[ 1 ];
     69 // returns '.js'
     70 ```
     71 
     72 #### reExtname.REGEXP_WIN32
     73 
     74 [Regular expression][@stdlib/regexp/extname-windows] to capture a Windows filename extension.
     75 
     76 ```javascript
     77 var ext = reExtname.REGEXP_WIN32.exec( 'C:\\foo\\bar\\index.js' )[ 1 ];
     78 // returns '.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 reExtname = require( '@stdlib/regexp/extname' );
    103 var RE_EXTNAME = reExtname();
    104 var ext;
    105 
    106 // Assuming a POSIX platform...
    107 ext = RE_EXTNAME.exec( '/foo/bar/index.js' )[ 1 ];
    108 // returns '.js'
    109 
    110 ext = reExtname.REGEXP_WIN32.exec( '/foo/bar/home.html' )[ 1 ];
    111 // returns '.html'
    112 
    113 ext = reExtname.REGEXP_WIN32.exec( 'C:\\foo\\bar\\home.html' )[ 1 ];
    114 // returns '.html'
    115 ```
    116 
    117 </section>
    118 
    119 <!-- /.examples -->
    120 
    121 <section class="links">
    122 
    123 [regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    124 
    125 [posix]: https://en.wikipedia.org/wiki/POSIX
    126 
    127 [@stdlib/assert/is-windows]: https://www.npmjs.com/package/@stdlib/assert-is-windows
    128 
    129 [@stdlib/regexp/extname-posix]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/extname-posix
    130 
    131 [@stdlib/regexp/extname-windows]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/extname-windows
    132 
    133 </section>
    134 
    135 <!-- /.links -->