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