time-to-botec

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

README.md (3994B)


      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 [POSIX][posix] filename.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var reFilenamePosix = require( '@stdlib/regexp/filename-posix' );
     31 ```
     32 
     33 #### reFilenamePosix()
     34 
     35 Returns a [regular expression][mdn-regexp] to split a [POSIX][posix] filename.
     36 
     37 ```javascript
     38 var RE_FILENAME_POSIX = reFilenamePosix();
     39 var parts = RE_FILENAME_POSIX.exec( '/foo/bar/index.js' ).slice();
     40 /* returns
     41     [
     42         '/foo/bar/index.js',  // input value
     43         '/',                  // root
     44         'foo/bar/',           // dirname
     45         'index.js',           // basename
     46         '.js'                 // extname
     47     ]
     48 */
     49 ```
     50 
     51 #### reFilenamePosix.REGEXP
     52 
     53 [Regular expression][mdn-regexp] to split a [POSIX][posix] filename.
     54 
     55 ```javascript
     56 var parts = reFilenamePosix.REGEXP.exec( '/foo/bar/index.js' ).slice();
     57 /* returns
     58     [
     59         '/foo/bar/index.js',  // input value
     60         '/',                  // root
     61         'foo/bar/',           // dirname
     62         'index.js',           // basename
     63         '.js'                 // extname
     64     ]
     65 */
     66 ```
     67 
     68 </section>
     69 
     70 <!-- /.usage -->
     71 
     72 <section class="notes">
     73 
     74 ## Notes
     75 
     76 -   When executed against dotfile filenames (e.g., `.gitignore`), the [regular expression][mdn-regexp] does **not** capture the basename as a filename extension.
     77 
     78     ```javascript
     79     var parts = reFilenamePosix.REGEXP.exec( '.bash_profile' ).slice();
     80     /* returns
     81       [
     82           '.bash_profile',
     83           '',
     84           '',
     85           '.bash_profile',
     86           ''
     87       ]
     88     */
     89 
     90     parts = reFilenamePosix.REGEXP.exec( '.travis.yml' ).slice();
     91     /* returns
     92       [
     93           '.travis.yml',
     94           '',
     95           '',
     96           '.travis.yml',
     97           '.yml'
     98       ]
     99     */
    100     ```
    101 
    102 </section>
    103 
    104 <!-- /.notes -->
    105 
    106 <section class="examples">
    107 
    108 ## Examples
    109 
    110 <!-- eslint no-undef: "error" -->
    111 
    112 ```javascript
    113 var reFilenamePosix = require( '@stdlib/regexp/filename-posix' );
    114 
    115 var RE_FILENAME_POSIX = reFilenamePosix();
    116 var parts = RE_FILENAME_POSIX.exec( 'index.js' ).slice();
    117 /* returns
    118     [
    119         'index.js',
    120         '',
    121         '',
    122         'index.js',
    123         '.js'
    124     ]
    125 */
    126 
    127 parts = RE_FILENAME_POSIX.exec( '/foo/bar/home.html' ).slice();
    128 /* returns
    129     [
    130         '/foo/bar/home.html',
    131         '/',
    132         'foo/bar/',
    133         'home.html',
    134         '.html'
    135     ]
    136 */
    137 
    138 parts = RE_FILENAME_POSIX.exec( 'foo/file.pdf' ).slice();
    139 /* returns
    140     [
    141         'foo/file.pdf',
    142         '',
    143         'foo/',
    144         'file.pdf',
    145         '.pdf'
    146     ]
    147 */
    148 
    149 parts = RE_FILENAME_POSIX.exec( 'beep/boop.' ).slice();
    150 /* returns
    151     [
    152         'beep/boop.',
    153         '',
    154         'beep/',
    155         'boop.',
    156         '.'
    157     ]
    158 */
    159 
    160 parts = RE_FILENAME_POSIX.exec( '' ).slice();
    161 /* returns
    162     [
    163         '',
    164         '',
    165         '',
    166         '',
    167         ''
    168     ]
    169 */
    170 
    171 parts = RE_FILENAME_POSIX.exec( '/foo/bar/file' ).slice();
    172 /* returns
    173     [
    174         '/foo/bar/file',
    175         '/',
    176         'foo/bar/',
    177         'file',
    178         ''
    179     ]
    180 */
    181 
    182 parts = RE_FILENAME_POSIX.exec( '/foo/bar/.gitignore' ).slice();
    183 /* returns
    184     [
    185         '/foo/bar/.gitignore',
    186         '/',
    187         'foo/bar/',
    188         '.gitignore',
    189         ''
    190     ]
    191 */
    192 ```
    193 
    194 </section>
    195 
    196 <!-- /.examples -->
    197 
    198 <section class="links">
    199 
    200 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    201 
    202 [posix]: https://en.wikipedia.org/wiki/POSIX
    203 
    204 </section>
    205 
    206 <!-- /.links -->