README.md (4454B)
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 # Convert Path 22 23 > Convert between POSIX and Windows paths. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var convertPath = require( '@stdlib/utils/convert-path' ); 41 ``` 42 43 #### convertPath( from, to ) 44 45 Converts between POSIX and Windows paths. 46 47 ```javascript 48 var p = convertPath( 'C:\\foo\\bar', 'posix' ); 49 // returns '/c/foo/bar' 50 ``` 51 52 The following output path conventions are supported: 53 54 - **win32**: Windows path convention; e.g., `C:\\foo\\bar`. 55 - **mixed**: mixed path convention (Windows volume convention and POSIX path separator); e.g., `C:/foo/bar`. 56 - **posix**: POSIX path convention; e.g., `/c/foo/bar`. 57 58 </section> 59 60 <!-- /.usage --> 61 62 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 63 64 <section class="notes"> 65 66 ## Notes 67 68 - A Windows [extended-length path][extended-length-path] **cannot** be converted to either a `mixed` or `posix` path convention, as forward slashes cannot be used as path separators. 69 - If a POSIX path begins with `/[A-Za-z]/` (e.g., `/c/`), the path is assumed to begin with a volume name. 70 - The function makes no attempt to verify that a provided path is valid. 71 72 </section> 73 74 <!-- /.notes --> 75 76 <!-- Package usage examples. --> 77 78 <section class="examples"> 79 80 ## Examples 81 82 <!-- eslint no-undef: "error" --> 83 84 ```javascript 85 var convertPath = require( '@stdlib/utils/convert-path' ); 86 87 var p1; 88 var p2; 89 90 p1 = '/c/foo/bar/beep.c'; 91 p2 = convertPath( p1, 'win32' ); 92 // returns 'c:\foo\bar\beep.c' 93 94 p1 = '/c/foo/bar/beep.c'; 95 p2 = convertPath( p1, 'mixed' ); 96 // returns 'c:/foo/bar/beep.c' 97 98 p1 = '/c/foo/bar/beep.c'; 99 p2 = convertPath( p1, 'posix' ); 100 // returns '/c/foo/bar/beep.c' 101 102 p1 = 'C:\\\\foo\\bar\\beep.c'; 103 p2 = convertPath( p1, 'win32' ); 104 // returns 'C:\\foo\bar\beep.c' 105 106 p1 = 'C:\\\\foo\\bar\\beep.c'; 107 p2 = convertPath( p1, 'mixed' ); 108 // returns 'C:/foo/bar/beep.c' 109 110 p1 = 'C:\\\\foo\\bar\\beep.c'; 111 p2 = convertPath( p1, 'posix' ); 112 // returns '/c/foo/bar/beep.c' 113 ``` 114 115 </section> 116 117 <!-- /.examples --> 118 119 <!-- Section for describing a command-line interface. --> 120 121 * * * 122 123 <section class="cli"> 124 125 ## CLI 126 127 <!-- CLI usage documentation. --> 128 129 <section class="usage"> 130 131 ### Usage 132 133 ```text 134 Usage: convert-path [options] [<path>] --out=<output> 135 136 Options: 137 138 -h, --help Print this message. 139 -V, --version Print the package version. 140 -o, --out output Output path convention. 141 ``` 142 143 </section> 144 145 <!-- /.usage --> 146 147 <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 148 149 <section class="notes"> 150 151 </section> 152 153 <!-- /.notes --> 154 155 <!-- CLI usage examples. --> 156 157 <section class="examples"> 158 159 ### Examples 160 161 ```bash 162 $ convert-path /c/foo/bar --out=mixed 163 c:/foo/bar 164 ``` 165 166 To use as a [standard stream][standard-streams], 167 168 ```bash 169 $ echo -n '/c/foo/bar' | convert-path --out=win32 170 c:\foo\bar 171 ``` 172 173 </section> 174 175 <!-- /.examples --> 176 177 </section> 178 179 <!-- /.cli --> 180 181 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 182 183 <section class="references"> 184 185 </section> 186 187 <!-- /.references --> 188 189 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 190 191 <section class="links"> 192 193 [extended-length-path]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx 194 195 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams 196 197 </section> 198 199 <!-- /.links -->