normalize-url ![Build Status](https://travis-ci.org/sindresorhus/normalize-url.svg?branch=master)
Normalize a URL
Useful when you need to display, store, deduplicate, sort, compare, etc, URLs.
Install
$ npm install --save normalize-url
Usage
const normalizeUrl = require('normalize-url');
normalizeUrl('sindresorhus.com');
normalizeUrl('HTTP://xn--xample-hva.com:80/?b=bar&a=foo');
API
normalizeUrl(url, [options])
url
Type: string
URL to normalize.
options
normalizeProtocol
Type: boolean
Default: true
Prepend http:
to the URL if it's protocol-relative.
normalizeUrl('//sindresorhus.com:80/');
normalizeUrl('//sindresorhus.com:80/', {normalizeProtocol: false});
stripFragment
Type: boolean
Default: true
Remove the fragment at the end of the URL.
normalizeUrl('sindresorhus.com/about.html#contact');
normalizeUrl('sindresorhus.com/about.html#contact', {stripFragment: false});
stripWWW
Type: boolean
Default: true
Remove www.
from the URL.
normalizeUrl('http://www.sindresorhus.com/about.html#contact');
normalizeUrl('http://www.sindresorhus.com/about.html#contact', {stripWWW: false});
Related
License
MIT © Sindre Sorhus