Gathering detailed insights and metrics for normalize-url
Gathering detailed insights and metrics for normalize-url
Gathering detailed insights and metrics for normalize-url
Gathering detailed insights and metrics for normalize-url
postcss-normalize-url
Normalize URLs with PostCSS
resolve-url-loader
Webpack loader that resolves relative paths in url() statements based on the original source file
url-join
Join urls and normalize as in path.join.
normalize-git-url
Normalizes Git URLs. For npm, but you can use it too.
npm install normalize-url
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.8
Supply Chain
99.5
Quality
76.1
Maintenance
100
Vulnerability
100
License
JavaScript (95.02%)
TypeScript (4.98%)
Total Downloads
8,161,137,129
Last Day
1,814,232
Last Week
30,158,881
Last Month
130,830,393
Last Year
1,410,927,186
MIT License
847 Stars
166 Commits
123 Forks
15 Watchers
1 Branches
43 Contributors
Updated on May 11, 2025
Minified
Minified + Gzipped
Latest Version
8.0.1
Package Id
normalize-url@8.0.1
Unpacked Size
25.25 kB
Size
6.50 kB
File Count
5
NPM Version
9.2.0
Node Version
18.19.0
Published on
Mar 10, 2024
Cumulative downloads
Total Downloads
Normalize a URL
Useful when you need to display, store, deduplicate, sort, compare, etc, URLs.
Note: This package does not do URL sanitization. Garbage in, garbage out. If you use this in a server context and accept URLs as user input, it's up to you to protect against invalid URLs, path traversal attacks, etc.
1npm install normalize-url
1import normalizeUrl from 'normalize-url';
2
3normalizeUrl('sindresorhus.com');
4//=> 'http://sindresorhus.com'
5
6normalizeUrl('//www.sindresorhus.com:80/../baz?b=bar&a=foo');
7//=> 'http://sindresorhus.com/baz?a=foo&b=bar'
URLs with custom protocols are not normalized and just passed through by default. Supported protocols are: https
, http
, file
, and data
.
Human-friendly URLs with basic auth (for example, user:password@sindresorhus.com
) are not handled because basic auth conflicts with custom protocols. Basic auth URLs are also deprecated.
Type: string
URL to normalize, including data URL.
Type: object
Type: string
Default: 'http'
Values: 'https' | 'http'
Type: boolean
Default: true
Prepend defaultProtocol
to the URL if it's protocol-relative.
1normalizeUrl('//sindresorhus.com');
2//=> 'http://sindresorhus.com'
3
4normalizeUrl('//sindresorhus.com', {normalizeProtocol: false});
5//=> '//sindresorhus.com'
Type: boolean
Default: false
Normalize HTTPS to HTTP.
1normalizeUrl('https://sindresorhus.com');
2//=> 'https://sindresorhus.com'
3
4normalizeUrl('https://sindresorhus.com', {forceHttp: true});
5//=> 'http://sindresorhus.com'
Type: boolean
Default: false
Normalize HTTP to HTTPS.
1normalizeUrl('http://sindresorhus.com');
2//=> 'http://sindresorhus.com'
3
4normalizeUrl('http://sindresorhus.com', {forceHttps: true});
5//=> 'https://sindresorhus.com'
This option cannot be used with the forceHttp
option at the same time.
Type: boolean
Default: true
Strip the authentication part of the URL.
1normalizeUrl('https://user:password@sindresorhus.com');
2//=> 'https://sindresorhus.com'
3
4normalizeUrl('https://user:password@sindresorhus.com', {stripAuthentication: false});
5//=> 'https://user:password@sindresorhus.com'
Type: boolean
Default: false
Strip the hash part of the URL.
1normalizeUrl('sindresorhus.com/about.html#contact');
2//=> 'http://sindresorhus.com/about.html#contact'
3
4normalizeUrl('sindresorhus.com/about.html#contact', {stripHash: true});
5//=> 'http://sindresorhus.com/about.html'
Type: boolean
Default: false
Remove the protocol from the URL: http://sindresorhus.com
→ sindresorhus.com
.
It will only remove https://
and http://
protocols.
1normalizeUrl('https://sindresorhus.com');
2//=> 'https://sindresorhus.com'
3
4normalizeUrl('https://sindresorhus.com', {stripProtocol: true});
5//=> 'sindresorhus.com'
Type: boolean
Default: true
Strip the text fragment part of the URL.
Note: The text fragment will always be removed if the stripHash
option is set to true
, as the hash contains the text fragment.
1normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello');
2//=> 'http://sindresorhus.com/about.html#'
3
4normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello');
5//=> 'http://sindresorhus.com/about.html#section'
6
7normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false});
8//=> 'http://sindresorhus.com/about.html#:~:text=hello'
9
10normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false});
11//=> 'http://sindresorhus.com/about.html#section:~:text=hello'
Type: boolean
Default: true
Remove www.
from the URL.
1normalizeUrl('http://www.sindresorhus.com');
2//=> 'http://sindresorhus.com'
3
4normalizeUrl('http://www.sindresorhus.com', {stripWWW: false});
5//=> 'http://www.sindresorhus.com'
Type: Array<RegExp | string> | boolean
Default: [/^utm_\w+/i]
Remove query parameters that matches any of the provided strings or regexes.
1normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
2 removeQueryParameters: ['ref']
3});
4//=> 'http://sindresorhus.com/?foo=bar'
If a boolean is provided, true
will remove all the query parameters.
1normalizeUrl('www.sindresorhus.com?foo=bar', { 2 removeQueryParameters: true 3}); 4//=> 'http://sindresorhus.com'
false
will not remove any query parameter.
1normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {
2 removeQueryParameters: false
3});
4//=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'
Type: Array<RegExp | string>
Default: undefined
Keeps only query parameters that matches any of the provided strings or regexes.
Note: It overrides the removeQueryParameters
option.
1normalizeUrl('https://sindresorhus.com?foo=bar&ref=unicorn', {
2 keepQueryParameters: ['ref']
3});
4//=> 'https://sindresorhus.com/?ref=unicorn'
Type: boolean
Default: true
Remove trailing slash.
Note: Trailing slash is always removed if the URL doesn't have a pathname unless the removeSingleSlash
option is set to false
.
1normalizeUrl('http://sindresorhus.com/redirect/');
2//=> 'http://sindresorhus.com/redirect'
3
4normalizeUrl('http://sindresorhus.com/redirect/', {removeTrailingSlash: false});
5//=> 'http://sindresorhus.com/redirect/'
6
7normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false});
8//=> 'http://sindresorhus.com'
Type: boolean
Default: true
Remove a sole /
pathname in the output. This option is independent of removeTrailingSlash
.
1normalizeUrl('https://sindresorhus.com/');
2//=> 'https://sindresorhus.com'
3
4normalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false});
5//=> 'https://sindresorhus.com/'
Type: boolean | Array<RegExp | string>
Default: false
Removes 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.
1normalizeUrl('www.sindresorhus.com/foo/default.php', {
2 removeDirectoryIndex: [/^default\.[a-z]+$/]
3});
4//=> 'http://sindresorhus.com/foo'
Type: boolean
Default: false
Removes an explicit port number from the URL.
Port 443 is always removed from HTTPS URLs and 80 is always removed from HTTP URLs regardless of this option.
1normalizeUrl('sindresorhus.com:123', { 2 removeExplicitPort: true 3}); 4//=> 'http://sindresorhus.com'
Type: boolean
Default: true
Sorts the query parameters alphabetically by key.
1normalizeUrl('www.sindresorhus.com?b=two&a=one&c=three', {
2 sortQueryParameters: false
3});
4//=> 'http://sindresorhus.com/?b=two&a=one&c=three'
7.5/10
Summary
ReDoS in normalize-url
Affected Versions
>= 4.3.0, < 4.5.1
Patched Versions
4.5.1
7.5/10
Summary
ReDoS in normalize-url
Affected Versions
>= 6.0.0, < 6.0.1
Patched Versions
6.0.1
7.5/10
Summary
ReDoS in normalize-url
Affected Versions
>= 5.0.0, < 5.3.1
Patched Versions
5.3.1
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 7/30 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-26
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
-12.5%
1,814,232
Compared to previous day
Last Week
-9.3%
30,158,881
Compared to previous week
Last Month
4%
130,830,393
Compared to previous month
Last Year
2.1%
1,410,927,186
Compared to previous year