normalize-url
Advanced tools
Comparing version
@@ -40,3 +40,4 @@ 'use strict'; | ||
stripWWW: true, | ||
removeQueryParameters: [/^utm_\w+/i] | ||
removeQueryParameters: [/^utm_\w+/i], | ||
removeTrailingSlash: true | ||
}, opts); | ||
@@ -125,3 +126,5 @@ | ||
// remove ending `/` | ||
str = str.replace(/\/$/, ''); | ||
if (opts.removeTrailingSlash || urlObj.pathname === '/') { | ||
str = str.replace(/\/$/, ''); | ||
} | ||
@@ -128,0 +131,0 @@ // restore relative protocol, if applicable |
{ | ||
"name": "normalize-url", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"description": "Normalize a URL", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -99,3 +99,23 @@ # normalize-url [](https://travis-ci.org/sindresorhus/normalize-url) | ||
##### removeTrailingSlash | ||
Type: `boolean`<br> | ||
Default: `true` | ||
Remove trailing slash. | ||
**Note:** Trailing slash is always removed if the URL doesn't have a pathname. | ||
```js | ||
normalizeUrl('http://sindresorhus.com/redirect/'); | ||
//=> 'http://sindresorhus.com/redirect' | ||
normalizeUrl('http://sindresorhus.com/redirect/', {removeTrailingSlash: false}); | ||
//=> 'http://sindresorhus.com/redirect/' | ||
normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false}); | ||
//=> 'http://sindresorhus.com' | ||
``` | ||
## Related | ||
@@ -102,0 +122,0 @@ |
7818
8.16%109
2.83%128
18.52%