README.md (3815B)
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 # isAbsolutePath 22 23 > Test if a value is an absolute path. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var isAbsolutePath = require( '@stdlib/assert/is-absolute-path' ); 37 ``` 38 39 #### isAbsolutePath( value ) 40 41 Tests if a `value` is an absolute path. 42 43 ```javascript 44 var IS_WINDOWS = require( '@stdlib/assert/is-windows' ); 45 46 var bool; 47 if ( IS_WINDOWS ) { 48 bool = isAbsolutePath( 'C:\\foo\\bar\\baz' ); 49 // returns true 50 } else { 51 bool = isAbsolutePath( '/foo/bar/baz' ); 52 // returns true 53 } 54 ``` 55 56 #### isAbsolutePath.posix( value ) 57 58 Tests if a `value` is a POSIX absolute path. 59 60 ```javascript 61 var bool = isAbsolutePath.posix( '/foo/bar/baz' ); 62 // returns true 63 64 bool = isAbsolutePath.posix( 'foo/bar/baz' ); 65 // returns false 66 ``` 67 68 #### isAbsolutePath.win32( value ) 69 70 Tests if a `value` is a Windows absolute path. 71 72 ```javascript 73 var bool = isAbsolutePath.win32( 'C:\\foo\\bar\\baz' ); 74 // returns true 75 76 bool = isAbsolutePath.win32( 'foo\\bar\\baz' ); 77 // returns false 78 ``` 79 80 </section> 81 82 <!-- /.usage --> 83 84 <section class="notes"> 85 86 ## Notes 87 88 - `isAbsolutePath()` is platform-specific. On Windows platforms, the function is equal to `isAbsolutePath.win32()`. On POSIX platforms, the function is equal to `isAbsolutePath.posix()`. 89 90 </section> 91 92 <!-- /.notes --> 93 94 <section class="examples"> 95 96 ## Examples 97 98 <!-- eslint no-undef: "error" --> 99 100 ```javascript 101 var isAbsolutePath = require( '@stdlib/assert/is-absolute-path' ); 102 103 var bool = isAbsolutePath.posix( '/foo/bar/baz' ); 104 // returns true 105 106 bool = isAbsolutePath.posix( '/foo/..' ); 107 // returns true 108 109 bool = isAbsolutePath.posix( 'foo/' ); 110 // returns false 111 112 bool = isAbsolutePath.posix( 'foo' ); 113 // returns false 114 115 bool = isAbsolutePath.posix( '.' ); 116 // returns false 117 118 bool = isAbsolutePath.posix( '' ); 119 // returns false 120 121 bool = isAbsolutePath.win32( 'C:\\foo\\bar\\baz' ); 122 // returns true 123 124 bool = isAbsolutePath.win32( '//server' ); 125 // returns true 126 127 bool = isAbsolutePath.win32( '\\\\server' ); 128 // returns true 129 130 bool = isAbsolutePath.win32( 'C:/foo/bar/baz' ); 131 // returns true 132 133 bool = isAbsolutePath.win32( '/foo/..' ); 134 // returns true 135 136 bool = isAbsolutePath.win32( 'foo\\bar\\baz' ); 137 // returns false 138 139 bool = isAbsolutePath.win32( 'foo/bar/baz' ); 140 // returns false 141 142 bool = isAbsolutePath.win32( 'foo/..' ); 143 // returns false 144 145 bool = isAbsolutePath.win32( '.' ); 146 // returns false 147 148 bool = isAbsolutePath.win32( '' ); 149 // returns false 150 ``` 151 152 </section> 153 154 <!-- /.examples --> 155 156 * * * 157 158 <section class="cli"> 159 160 ## CLI 161 162 <section class="usage"> 163 164 ### Usage 165 166 ```text 167 Usage: is-absolute-path [options] [<path>] 168 169 Options: 170 171 -h, --help Print this message. 172 -V, --version Print the package version. 173 --platform name Platform: 'win32' or 'posix'. 174 ``` 175 176 </section> 177 178 <!-- /.usage --> 179 180 <section class="examples"> 181 182 ### Examples 183 184 ```bash 185 $ is-absolute-path /foo/bar/baz --platform=posix 186 true 187 ``` 188 189 To use as a [standard stream][standard-streams], 190 191 ```bash 192 $ echo -n './docs/repl.txt' | is-absolute-path 193 false 194 ``` 195 196 </section> 197 198 <!-- /.examples --> 199 200 </section> 201 202 <!-- /.cli --> 203 204 <section class="links"> 205 206 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams 207 208 </section> 209 210 <!-- /.links -->