README.md (3959B)
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 # isURI 22 23 > Test if a value is a [URI][uri]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isURI = require( '@stdlib/assert/is-uri' ); 31 ``` 32 33 #### isURI( value ) 34 35 Tests if a `value` is a [URI][uri]. 36 37 ```javascript 38 var bool = isURI( 'https://google.com' ); 39 // returns true 40 41 bool = isURI( 'ftp://ftp.is.co.za/rfc/rfc1808.txt' ); 42 // returns true 43 44 bool = isURI( '' ); 45 // returns false 46 47 bool = isURI( 'foo' ); 48 // returns false 49 50 bool = isURI( null ); 51 // returns false 52 53 bool = isURI( NaN ); 54 // returns false 55 56 bool = isURI( true ); 57 // returns false 58 ``` 59 60 </section> 61 62 <!-- /.usage --> 63 64 <section class="notes"> 65 66 ## Notes 67 68 - For more information regarding the URI scheme, see [RFC 3986][rfc-3986] and [Wikipedia][uri]. 69 - On the distinction between URI, URL, and URN, see [The Difference Between URLs and URIs][difference-url-uri]. 70 71 </section> 72 73 <!-- /.notes --> 74 75 <section class="examples"> 76 77 ## Examples 78 79 <!-- eslint no-undef: "error" --> 80 81 ```javascript 82 var isURI = require( '@stdlib/assert/is-uri' ); 83 84 /* Valid */ 85 86 var bool = isURI( 'http://google.com' ); 87 // returns true 88 89 bool = isURI( 'http://localhost/' ); 90 // returns true 91 92 bool = isURI( 'http://example.w3.org/path%20with%20spaces.html' ); 93 // returns true 94 95 bool = isURI( 'http://example.w3.org/%20' ); 96 // returns true 97 98 bool = isURI( 'ftp://ftp.is.co.za/rfc/rfc1808.txt' ); 99 // returns true 100 101 bool = isURI( 'ftp://ftp.is.co.za/../../../rfc/rfc1808.txt' ); 102 // returns true 103 104 bool = isURI( 'http://www.ietf.org/rfc/rfc2396.txt' ); 105 // returns true 106 107 bool = isURI( 'ldap://[2001:db8::7]/c=GB?objectClass?one' ); 108 // returns true 109 110 bool = isURI( 'mailto:John.Doe@example.com' ); 111 // returns true 112 113 bool = isURI( 'news:comp.infosystems.www.servers.unix' ); 114 // returns true 115 116 bool = isURI( 'tel:+1-816-555-1212' ); 117 // returns true 118 119 bool = isURI( 'telnet://192.0.2.16:80/' ); 120 // returns true 121 122 bool = isURI( 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2' ); 123 // returns true 124 125 /* Invalid */ 126 127 // No scheme: 128 bool = isURI( '' ); 129 // returns false 130 131 // No scheme: 132 bool = isURI( 'foo' ); 133 // returns false 134 135 // No scheme: 136 bool = isURI( 'foo@bar' ); 137 // returns false 138 139 // No scheme: 140 bool = isURI( '://foo/' ); 141 // returns false 142 143 // Illegal characters: 144 bool = isURI( 'http://<foo>' ); 145 // returns false 146 147 // Invalid path: 148 bool = isURI( 'http:////foo.html' ); 149 // returns false 150 151 // Incomplete hex escapes... 152 bool = isURI( 'http://example.w3.org/%a' ); 153 // returns false 154 155 bool = isURI( 'http://example.w3.org/%a/foo' ); 156 // returns false 157 158 bool = isURI( 'http://example.w3.org/%at' ); 159 // returns false 160 ``` 161 162 </section> 163 164 <!-- /.examples --> 165 166 * * * 167 168 <section class="cli"> 169 170 ## CLI 171 172 <section class="usage"> 173 174 ### Usage 175 176 ```text 177 Usage: is-uri [options] [<uri>] 178 179 Options: 180 181 -h, --help Print this message. 182 -V, --version Print the package version. 183 ``` 184 185 </section> 186 187 <!-- /.usage --> 188 189 <section class="examples"> 190 191 ### Examples 192 193 ```bash 194 $ is-uri http://google.com 195 true 196 ``` 197 198 To use as a [standard stream][standard-streams], 199 200 ```bash 201 $ echo -n 'http://google.com' | is-uri 202 true 203 ``` 204 205 </section> 206 207 <!-- /.examples --> 208 209 </section> 210 211 <!-- /.cli --> 212 213 <section class="links"> 214 215 [uri]: http://en.wikipedia.org/wiki/URI_scheme 216 217 [rfc-3986]: https://tools.ietf.org/html/rfc3986 218 219 [difference-url-uri]: https://danielmiessler.com/study/url-uri/ 220 221 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams 222 223 </section> 224 225 <!-- /.links -->