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
@esm2cjs/normalize-url
Normalize a URL. This is a fork of sindresorhus/normalize-url, but with CommonJS support.
postcss-normalize-url
Normalize URLs with PostCSS
normalize-url-plus
normalize-url plus additional features to supercharge link normalization!
cssnano-preset-default
Safe defaults for cssnano which require minimal configuration.
npm install normalize-url
99.5
Supply Chain
99.5
Quality
77
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
840 Stars
166 Commits
122 Forks
16 Watching
1 Branches
43 Contributors
Updated on 15 Oct 2024
Minified
Minified + Gzipped
JavaScript (95.02%)
TypeScript (4.98%)
Cumulative downloads
Total Downloads
Last day
-7.4%
5,195,466
Compared to previous day
Last week
2.1%
30,936,972
Compared to previous week
Last month
10.6%
127,100,748
Compared to previous month
Last year
-6.3%
1,382,052,449
Compared to previous year
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'
The latest stable version of the package.
Stable Version
3
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
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 7/30 approved changesets -- score normalized to 2
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
detected GitHub workflow tokens with excessive permissions
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 2024-11-18
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 More