Git Product home page Git Product logo

isuri's Introduction

isUri

Greenkeeper badge npm Downloads Node.js Version Build Status Coverage Status bitHound Dependencies bitHound Dev Dependencies bitHound Code

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 = require('isuri');

isUri.isValid('http://example.com'); // returns true
isUri.isValid('Bananas in pajamas are coming down the stairs'); // 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 = require('isuri');
var httpRegex = isUri.createUriRegex({ scheme: [ /https?/ ] });

httpRegex.test('http://example.com'); // returns true
httpRegex.test('https://example.com'); // returns true
httpRegex.test('ftp://example.com'); // returns false
httpRegex.test('Bananas in pajamas are coming down the stairs'); // returns false

Benchmarks

> Benchmarking complex-ipv4.js

  Testing URI "http://asdf:qw%[email protected]: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.js

  Testing 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.js

  Testing 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.js

  Testing 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.js

  Testing URI "mailto:[email protected]"

  1 test completed.

  isUri#test(uri) x 10,444,735 ops/sec ±0.73% (183 runs sampled)

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.