isUri
Javascript implementation for truly checking if the provided input is a valid URI, Based on RFC 3986.
Install
NPM
$ npm install isuri
Node.js
var isUri = ; isUri; // returns trueisUri; // returns false
isUri.isValid(value)
Checks if the value provided is a valid URI and returns true if so, returns false otherwise.
isUri.uriRegex()
Returns the regular expression used for validating URIs.
isUri.createUriRegex([options])
Creates a new regular expression for validating URIs which accepts the following parameters:
options
- optional settings:scheme
- Specifies one or more acceptable Schemes, should only include the scheme name. Can be an Array or String (strings are automatically escaped for use in a Regular Expression).
var isUri = ;var httpRegex = isUri; httpRegex; // returns truehttpRegex; // returns truehttpRegex; // returns falsehttpRegex; // returns false
Benchmarks
> Benchmarking complex-ipv4.jsTesting URI "http://asdf:qw%20er@127.0.0.1:8000?asdf=12345&asda=fc%2F#bacon"1 test completed.isUri#test(uri) x 6,229,053 ops/sec ±0.83% (183 runs sampled)> Benchmarking complex-ipv6.jsTesting URI "http://asdf:qw%20er@[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8000?asdf=12345&asda=fc%2F#bacon"1 test completed.isUri#test(uri) x 5,197,138 ops/sec ±0.74% (182 runs sampled)> Benchmarking complex-ipvFuture.jsTesting URI "http://asdf:qw%20er@[v1.09azAZ-._~!$&'()*+,;=:]:8000?asdf=12345&asda=fc%2F#bacon"1 test completed.isUri#test(uri) x 4,418,023 ops/sec ±0.63% (183 runs sampled)> Benchmarking complex-uri.jsTesting URI "http://asdf:qw%20er@localhost:8000?asdf=12345&asda=fc%2F#bacon"1 test completed.isUri#test(uri) x 6,113,035 ops/sec ±0.68% (184 runs sampled)> Benchmarking simple-uri.jsTesting URI "mailto:John.Doe@example.com"1 test completed.isUri#test(uri) x 10,444,735 ops/sec ±0.73% (183 runs sampled)