index.js (2474B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 /** 22 * Test if a value is a URI. 23 * 24 * @module @stdlib/assert/is-uri 25 * 26 * @example 27 * var isURI = require( '@stdlib/assert/is-uri' ); 28 * 29 * var bool = isURI( 'http://google.com' ); 30 * // returns true 31 * 32 * bool = isURI( 'http://localhost/' ); 33 * // returns true 34 * 35 * bool = isURI( 'http://example.w3.org/path%20with%20spaces.html' ); 36 * // returns true 37 * 38 * bool = isURI( 'http://example.w3.org/%20' ); 39 * // returns true 40 * 41 * bool = isURI( 'ftp://ftp.is.co.za/rfc/rfc1808.txt' ); 42 * // returns true 43 * 44 * bool = isURI( 'ftp://ftp.is.co.za/../../../rfc/rfc1808.txt' ); 45 * // returns true 46 * 47 * bool = isURI( 'http://www.ietf.org/rfc/rfc2396.txt' ); 48 * // returns true 49 * 50 * bool = isURI( 'ldap://[2001:db8::7]/c=GB?objectClass?one' ); 51 * // returns true 52 * 53 * bool = isURI( 'mailto:John.Doe@example.com' ); 54 * // returns true 55 * 56 * bool = isURI( 'news:comp.infosystems.www.servers.unix' ); 57 * // returns true 58 * 59 * bool = isURI( 'tel:+1-816-555-1212' ); 60 * // returns true 61 * 62 * bool = isURI( 'telnet://192.0.2.16:80/' ); 63 * // returns true 64 * 65 * bool = isURI( 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2' ); 66 * // returns true 67 * 68 * // No scheme: 69 * bool = isURI( '' ); 70 * // returns false 71 * 72 * // No scheme: 73 * bool = isURI( 'foo' ); 74 * // returns false 75 * 76 * // No scheme: 77 * bool = isURI( 'foo@bar' ); 78 * // returns false 79 * 80 * // No scheme: 81 * bool = isURI( '://foo/' ); 82 * // returns false 83 * 84 * // Illegal characters: 85 * bool = isURI( 'http://<foo>' ); 86 * // returns false 87 * 88 * // Invalid path: 89 * bool = isURI( 'http:////foo.html' ); 90 * // returns false 91 * 92 * // Incomplete hex escapes... 93 * bool = isURI( 'http://example.w3.org/%a' ); 94 * // returns false 95 * 96 * bool = isURI( 'http://example.w3.org/%a/foo' ); 97 * // returns false 98 * 99 * bool = isURI( 'http://example.w3.org/%at' ); 100 * // returns false 101 */ 102 103 // MODULES // 104 105 var isURI = require( './main.js' ); 106 107 108 // EXPORTS // 109 110 module.exports = isURI;