README.md (3213B)
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 # Dirname 22 23 > [Regular expression][regexp] to capture a path [dirname][dirname]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var reDirname = require( '@stdlib/regexp/dirname' ); 31 ``` 32 33 #### reDirname( \[platform] ) 34 35 Returns a [regular expression][regexp] to capture a path [dirname][dirname]. 36 37 ```javascript 38 var RE = reDirname(); 39 // returns <RegExp> 40 41 RE = reDirname( 'posix' ); 42 // returns <RegExp> 43 44 var dir = RE.exec( '/foo/bar/index.js' )[ 1 ]; 45 // returns '/foo/bar' 46 47 RE = reDirname( 'win32' ); 48 // returns <RegExp> 49 50 dir = RE.exec( 'C:\\foo\\bar\\index.js' )[ 1 ]; 51 // returns 'C:\\foo\\bar' 52 ``` 53 54 #### reBasename.REGEXP 55 56 [Regular expression][regexp] to capture a path dirname. 57 58 ```javascript 59 var bool = ( reDirname.REGEXP.toString() === reDirname().toString() ); 60 // returns true 61 ``` 62 63 #### reDirname.REGEXP_POSIX 64 65 [Regular expression][@stdlib/regexp/dirname-posix] to capture a [POSIX][posix] path dirname. 66 67 ```javascript 68 var dir = reDirname.REGEXP_POSIX.exec( '/foo/bar/index.js' )[ 1 ]; 69 // returns '/foo/bar' 70 ``` 71 72 #### reDirname.REGEXP_WIN32 73 74 [Regular expression][@stdlib/regexp/dirname-windows] to capture a Windows path dirname. 75 76 ```javascript 77 var dir = reDirname.REGEXP_WIN32.exec( 'C:\\foo\\bar\\index.js' )[ 1 ]; 78 // returns 'C:\\foo\\bar' 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 reDirname = require( '@stdlib/regexp/dirname' ); 103 var RE_DIRNAME = reDirname(); 104 var dir; 105 106 // Assuming a POSIX platform... 107 dir = RE_DIRNAME.exec( '/foo/bar/index.js' )[ 1 ]; 108 // returns '/foo/bar' 109 110 dir = reDirname.REGEXP_POSIX.exec( '/foo/bar/home.html' )[ 1 ]; 111 // returns '/foo/bar' 112 113 dir = reDirname.REGEXP_WIN32.exec( 'C:\\foo\\bar\\home.html' )[ 1 ]; 114 // returns 'C:\\foo\\bar' 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 [dirname]: https://en.wikipedia.org/wiki/Dirname 126 127 [posix]: https://en.wikipedia.org/wiki/POSIX 128 129 [@stdlib/assert/is-windows]: https://www.npmjs.com/package/@stdlib/assert-is-windows 130 131 [@stdlib/regexp/dirname-posix]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/dirname-posix 132 133 [@stdlib/regexp/dirname-windows]: https://www.npmjs.com/package/@stdlib/regexp/tree/main/dirname-windows 134 135 </section> 136 137 <!-- /.links -->