normalize-url
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -140,3 +140,3 @@ declare namespace normalizeUrl { | ||
__Note__: Trailing slash is always removed if the URL doesn't have a pathname. | ||
__Note__: Trailing slash is always removed if the URL doesn't have a pathname unless the `removeSingleSlash` option is set to `false`. | ||
@@ -160,2 +160,18 @@ @default true | ||
/** | ||
Remove a sole `/` pathname in the output. This option is independant of `removeTrailingSlash`. | ||
@default true | ||
@example | ||
``` | ||
normalizeUrl('https://sindresorhus.com/'); | ||
//=> 'https://sindresorhus.com' | ||
normalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false}); | ||
//=> 'https://sindresorhus.com/' | ||
``` | ||
*/ | ||
readonly removeSingleSlash?: boolean; | ||
/** | ||
Removes the default directory index file from path that matches any of the provided strings or regexes. | ||
@@ -162,0 +178,0 @@ When `true`, the regex `/^index\.[a-z]+$/` is used. |
@@ -73,2 +73,3 @@ 'use strict'; | ||
removeTrailingSlash: true, | ||
removeSingleSlash: true, | ||
removeDirectoryIndex: false, | ||
@@ -181,4 +182,4 @@ sortQueryParameters: true, | ||
// Remove ending `/` | ||
if ((options.removeTrailingSlash || urlObj.pathname === '/') && urlObj.hash === '') { | ||
// Remove ending `/` unless removeSingleSlash is false | ||
if ((options.removeTrailingSlash || urlObj.pathname === '/') && urlObj.hash === '' && options.removeSingleSlash) { | ||
urlString = urlString.replace(/\/$/, ''); | ||
@@ -185,0 +186,0 @@ } |
{ | ||
"name": "normalize-url", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Normalize a URL", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -174,3 +174,3 @@ # normalize-url [![Build Status](https://travis-ci.org/sindresorhus/normalize-url.svg?branch=master)](https://travis-ci.org/sindresorhus/normalize-url) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/normalize-url/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/normalize-url?branch=master) | ||
**Note:** Trailing slash is always removed if the URL doesn't have a pathname. | ||
**Note:** Trailing slash is always removed if the URL doesn't have a pathname unless the `removeSingleSlash` option is set to `false`. | ||
@@ -188,2 +188,18 @@ ```js | ||
##### removeSingleSlash | ||
Type: `boolean`\ | ||
Default: `true` | ||
Remove a sole `/` pathname in the output. This option is independant of `removeTrailingSlash`. | ||
```js | ||
normalizeUrl('https://sindresorhus.com/'); | ||
//=> 'https://sindresorhus.com' | ||
normalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false}); | ||
//=> 'https://sindresorhus.com/' | ||
``` | ||
##### removeDirectoryIndex | ||
@@ -190,0 +206,0 @@ |
18219
329
247