\begin{quote}
\href{https://en.wikipedia.org/wiki/URL_normalization}{\texttt{ Normalize}} a URL \end{quote}
Useful when you need to display, store, deduplicate, sort, compare, etc, URLs.\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18378}{}\doxysection{Install}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18378}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install normalize-\/url }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18379}{}\doxysection{Usage}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18379}

\begin{DoxyCode}{0}
\DoxyCodeLine{const normalizeUrl = require('normalize-\/url');}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('sindresorhus.com');}
\DoxyCodeLine{//=> 'http://sindresorhus.com'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('HTTP://xn-\/-\/xample-\/hva.com:80/?b=bar\&a=foo');}
\DoxyCodeLine{//=> 'http://êxample.com/?a=foo\&b=bar' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18380}{}\doxysection{API}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18380}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18381}{}\doxysubsection{normalize\+Url(url, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18381}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18382}{}\doxysubsubsection{url}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18382}
Type\+: {\ttfamily string}

URL to normalize.\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18383}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18383}
Type\+: {\ttfamily Object}\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18384}{}\doxyparagraph{default\+Protocol}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18384}
Type\+: {\ttfamily string}~\newline
 Default\+: {\ttfamily http\+:}\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18385}{}\doxyparagraph{normalize\+Protocol}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18385}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Prepends {\ttfamily default\+Protocol} to the URL if it\textquotesingle{}s protocol-\/relative.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('//sindresorhus.com:80/');}
\DoxyCodeLine{//=> 'http://sindresorhus.com'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('//sindresorhus.com:80/', \{normalizeProtocol: false\});}
\DoxyCodeLine{//=> '//sindresorhus.com' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18386}{}\doxyparagraph{force\+Http}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18386}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily false}

Normalizes {\ttfamily https\+:} URLs to {\ttfamily http\+:}.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('https://sindresorhus.com:80/');}
\DoxyCodeLine{//=> 'https://sindresorhus.com'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('https://sindresorhus.com:80/', \{normalizeHttps: true\});}
\DoxyCodeLine{//=> 'http://sindresorhus.com' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18387}{}\doxyparagraph{force\+Https}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18387}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily false}

Normalizes {\ttfamily http\+:} URLs to {\ttfamily https\+:}.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('https://sindresorhus.com:80/');}
\DoxyCodeLine{//=> 'https://sindresorhus.com'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('http://sindresorhus.com:80/', \{normalizeHttp: true\});}
\DoxyCodeLine{//=> 'https://sindresorhus.com' }

\end{DoxyCode}


This option can\textquotesingle{}t be used with the {\ttfamily force\+Http} option at the same time.\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18388}{}\doxyparagraph{strip\+Hash}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18388}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Removes hash from the URL.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('sindresorhus.com/about.html\#contact');}
\DoxyCodeLine{//=> 'http://sindresorhus.com/about.html'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('sindresorhus.com/about.html\#contact', \{stripHash: false\});}
\DoxyCodeLine{//=> 'http://sindresorhus.com/about.html\#contact' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18389}{}\doxyparagraph{strip\+WWW}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18389}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Removes {\ttfamily www.} from the URL.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('http://www.sindresorhus.com/about.html\#contact');}
\DoxyCodeLine{//=> 'http://sindresorhus.com/about.html\#contact'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('http://www.sindresorhus.com/about.html\#contact', \{stripWWW: false\});}
\DoxyCodeLine{//=> 'http://www.sindresorhus.com/about.html\#contact' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18390}{}\doxyparagraph{remove\+Query\+Parameters}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18390}
Type\+: {\ttfamily Array$<$Reg\+Exp$\vert$string$>$}~\newline
 Default\+: {\ttfamily \mbox{[}/$^\wedge$utm\+\_\+\textbackslash{}w+/i\mbox{]}}

Removes query parameters that matches any of the provided strings or regexes.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('www.sindresorhus.com?foo=bar\&ref=test\_ref', \{}
\DoxyCodeLine{    removeQueryParameters: ['ref']}
\DoxyCodeLine{\});}
\DoxyCodeLine{//=> 'http://sindresorhus.com/?foo=bar' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18391}{}\doxyparagraph{remove\+Trailing\+Slash}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18391}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Removes trailing slash.

{\bfseries{Note\+:}} Trailing slash is always removed if the URL doesn\textquotesingle{}t have a pathname.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('http://sindresorhus.com/redirect/');}
\DoxyCodeLine{//=> 'http://sindresorhus.com/redirect'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('http://sindresorhus.com/redirect/', \{removeTrailingSlash: false\});}
\DoxyCodeLine{//=> 'http://sindresorhus.com/redirect/'}
\DoxyCodeLine{}
\DoxyCodeLine{normalizeUrl('http://sindresorhus.com/', \{removeTrailingSlash: false\});}
\DoxyCodeLine{//=> 'http://sindresorhus.com' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18392}{}\doxyparagraph{remove\+Directory\+Index}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18392}
Type\+: {\ttfamily boolean} {\ttfamily Array$<$Reg\+Exp$\vert$string$>$}~\newline
 Default\+: {\ttfamily false}

Removes the default directory index file from path that matches any of the provided strings or regexes. When {\ttfamily true}, the regex {\ttfamily /$^\wedge$index\textbackslash{}.\mbox{[}a-\/z\mbox{]}+\$/} is used.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('www.sindresorhus.com/foo/default.php', \{}
\DoxyCodeLine{    removeDirectoryIndex: [/\string^default\(\backslash\).[a-\/z]+\$/]}
\DoxyCodeLine{\});}
\DoxyCodeLine{//=> 'http://sindresorhus.com/foo' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18393}{}\doxyparagraph{sort\+Query\+Parameters}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18393}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Sorts the query parameters alphabetically by key.


\begin{DoxyCode}{0}
\DoxyCodeLine{normalizeUrl('www.sindresorhus.com?b=two\&a=one\&c=three', \{}
\DoxyCodeLine{    sortQueryParameters: false}
\DoxyCodeLine{\});}
\DoxyCodeLine{//=> 'http://sindresorhus.com/?b=two\&a=one\&c=three' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18394}{}\doxysection{Related}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18394}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/compare-urls}{\texttt{ compare-\/urls}} -\/ Compare URLs by first normalizing them
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_normalize_url_readme_autotoc_md18395}{}\doxysection{License}\label{md_sfcode_node_modules_normalize_url_readme_autotoc_md18395}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 