time-to-botec

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

README.md (4502B)


      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
     22 
     23 > [Regular expression][mdn-regexp] to split a filename.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var reFilename = require( '@stdlib/regexp/filename' );
     31 ```
     32 
     33 #### reFilename( \[platform] )
     34 
     35 Returns a [regular expression][mdn-regexp] to split a filename.
     36 
     37 ```javascript
     38 var RE = reFilename();
     39 // returns <RegExp>
     40 
     41 RE = reFilename( 'posix' );
     42 // returns <RegExp>
     43 
     44 var parts = RE.exec( '/foo/bar/index.js' ).slice();
     45 /* returns
     46     [
     47         '/foo/bar/index.js',  // input value
     48         '/',                  // root
     49         'foo/bar/',           // dirname
     50         'index.js',           // basename
     51         '.js'                 // extname
     52     ]
     53 */
     54 
     55 RE = reFilename( 'win32' );
     56 // returns <RegExp>
     57 
     58 parts = RE.exec( 'C:\\foo\\bar\\index.js' ).slice();
     59 /* returns
     60     [
     61         'C:\\foo\\bar\\index.js',   // input value
     62         'C:',                       // device
     63         '\\',                       // slash
     64         'foo\\bar\\',               // dirname
     65         'index.js',                 // basename
     66         '.js'                       // extname
     67     ]
     68 */
     69 ```
     70 
     71 #### reFilename.REGEXP
     72 
     73 [Regular expression][mdn-regexp] to split a filename.
     74 
     75 ```javascript
     76 var bool = ( reFilename.REGEXP.toString() === reFilename().toString() );
     77 // returns true
     78 ```
     79 
     80 #### reFilename.REGEXP_POSIX
     81 
     82 [Regular expression][@stdlib/regexp/filename-posix] to split a [POSIX][posix] filename. 
     83 
     84 ```javascript
     85 var parts = reFilename.REGEXP_POSIX.exec( '/foo/bar/index.js' ).slice();
     86 /* returns
     87     [
     88         '/foo/bar/index.js',  // input value
     89         '/',                  // root
     90         'foo/bar/',           // dirname
     91         'index.js',           // basename
     92         '.js'                 // extname
     93     ]
     94 */
     95 ```
     96 
     97 #### reFilename.REGEXP_WIN32
     98 
     99 [Regular expression][@stdlib/regexp/filename-windows] to split a Windows filename.
    100 
    101 ```javascript
    102 var parts = reFilename.REGEXP_WIN32.exec( 'C:\\foo\\bar\\index.js' ).slice();
    103 /* returns
    104     [
    105         'C:\\foo\\bar\\index.js',   // input value
    106         'C:',                       // device
    107         '\\',                       // slash
    108         'foo\\bar\\',               // dirname
    109         'index.js',                 // basename
    110         '.js'                       // extname
    111     ]
    112 */
    113 ```
    114 
    115 </section>
    116 
    117 <!-- /.usage -->
    118 
    119 <section class="notes">
    120 
    121 ## Notes
    122 
    123 -   The as `REGEXP` exported [regular expression][mdn-regexp] is [platform][@stdlib/assert/is-windows]-dependent. If the current process is running on Windows, `REGEXP === REGEXP_WIN32`; otherwise, `REGEXP === REGEXP_POSIX`.
    124 
    125 </section>
    126 
    127 <!-- /.notes -->
    128 
    129 <section class="examples">
    130 
    131 ## Examples
    132 
    133 <!-- eslint no-undef: "error" -->
    134 
    135 ```javascript
    136 var reFilename = require( '@stdlib/regexp/filename' );
    137 var RE_FILENAME = reFilename();
    138 
    139 // Assuming a POSIX platform...
    140 var parts = RE_FILENAME.exec( '/foo/bar/index.js' ).slice();
    141 /* returns
    142     [
    143         '/foo/bar/index.js',
    144         '/',
    145         'foo/bar/',
    146         'index.js',
    147         '.js'
    148     ]
    149 */
    150 
    151 parts = reFilename.REGEXP_POSIX.exec( '/foo/bar/home.html' ).slice();
    152 /* returns
    153     [
    154         '/foo/bar/home.html',
    155         '/',
    156         'foo/bar/',
    157         'home.html',
    158         '.html'
    159     ]
    160 */
    161 
    162 parts = reFilename.REGEXP_WIN32.exec( 'C:\\foo\\bar\\home.html' ).slice();
    163 /* returns
    164     [
    165         'C:\\foo\\bar\\home.html',
    166         'C:',
    167         '\\',
    168         'foo\\bar\\',
    169         'home.html',
    170         '.html'
    171     ]
    172 */
    173 ```
    174 
    175 </section>
    176 
    177 <!-- /.examples -->
    178 
    179 <section class="links">
    180 
    181 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    182 
    183 [posix]: https://en.wikipedia.org/wiki/POSIX
    184 
    185 [@stdlib/assert/is-windows]: https://www.npmjs.com/package/@stdlib/assert-is-windows
    186 
    187 [@stdlib/regexp/filename-posix]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/filename-posix
    188 
    189 [@stdlib/regexp/filename-windows]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/filename-windows
    190 
    191 </section>
    192 
    193 <!-- /.links -->