Skip to content

Repository files navigation

url-http

Last version Coverage Status NPM Status

Get input as normalized WHATWG URL.

Install

$ npm install url-http --save

Usage

const urlHttp = require('url-http')

!!urlHttp('https://kikobeats.com') // ==> true
!!urlHttp('https://kikobeats.com') // ==> true
!!urlHttp('mailto://kiko@beats.com') // ==> false
!!urlHttp('callto:192.168.103.77+type=ip') // ==> false

Beyond the scheme, it requires the host to be one the public internet can resolve: an IP literal, localhost, or a domain whose TLD is in the public suffix list. Hosts such as http://internal/ or https://example.local/ are rejected, as are URLs carrying credentials.

If you need to run the package in a browser environment, you can save some bytes using the lightweight version, which checks the scheme only:

const urlHttp = require('url-http/lightweight')

!!urlHttp('https://kikobeats.com') // ==> true
!!urlHttp('https://kikobeats.com') // ==> true
!!urlHttp('mailto://kiko@beats.com') // ==> false
!!urlHttp('callto:192.168.103.77+type=ip') // ==> false

License

url-http © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · X @Kikobeats

About

Normalize any input into a WHATWG URL limited to HTTP and HTTPS schemes.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages