Normalize a URL
Useful when you need to display, store, deduplicate, sort, compare, etc, URLs.
$ npm install --save normalize-url
const normalizeUrl = require('normalize-url');
normalizeUrl('sindresorhus.com');
//=> 'http://sindresorhus.com'
normalizeUrl('HTTP://xn--xample-hva.com:80/?b=bar&a=foo');
//=> 'http://êxample.com/?a=foo&b=bar'
normalizeUrl(url, [options])
Type: string
URL to normalize.
normalizeProtocol
Type: boolean
Default: true
Prepend http: to the URL if it's protocol-relative.
normalizeHttps
Type: boolean
Default: false
Normalize https: URLs to http:.
stripFragment
Type: boolean
Default: true
Remove the fragment at the end of the URL.
stripWWW
Type: boolean
Default: true
Remove www. from the URL.
removeQueryParameters
Type: Array<RegExp|string>
Default: [/^utm_\w+/i]
Remove query parameters that matches any of the provided strings or regexes.
removeTrailingSlash
Type: boolean
Default: true
Remove trailing slash.
Note: Trailing slash is always removed if the URL doesn't have a pathname.
removeDirectoryIndex
Type: boolean Array<RegExp|string>
Default: false
Remove the default directory index file from path that matches any of the provided strings or regexes. When true, the regex /^index\.[a-z]+$/ is used.
MIT © Sindre Sorhus