JSPM

  • Created
  • Published
  • Downloads 33513156
  • Score
    100M100P100Q238218F
  • License MIT

Normalize a URL

Package Exports

  • normalize-url

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (normalize-url) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

normalize-url Build Status

Normalize a URL

Useful when you need to display, store, deduplicate, sort, compare, etc, URLs.

Install

$ npm install --save normalize-url

Usage

var 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

API

normalizeUrl(url, [options])

url

Required
Type: string

URL to normalize.

options

normalizeProtocol

Type: boolean
Default: true

Prepend http: to protocol-relative URLs.

normalizeUrl('//sindresorhus.com:80/', {normalizeProtocol: false});
//=> //sindresorhus.com
stripFragment

Type: boolean
Default: true

Remove the fragment at the end of the URL.

normalizeUrl('sindresorhus.com/about.html#contact', {stripFragment: false});
//=> http://sindresorhus.com/about.html#contact

License

MIT © Sindre Sorhus