normalize-url 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +24 -7
- package/index.js +6 -0
- package/package.json +1 -1
- package/readme.md +23 -7
package/index.d.ts
CHANGED
|
@@ -13,10 +13,10 @@ export interface Options {
|
|
|
13
13
|
|
|
14
14
|
@example
|
|
15
15
|
```
|
|
16
|
-
normalizeUrl('//sindresorhus.com
|
|
16
|
+
normalizeUrl('//sindresorhus.com');
|
|
17
17
|
//=> 'http://sindresorhus.com'
|
|
18
18
|
|
|
19
|
-
normalizeUrl('//sindresorhus.com
|
|
19
|
+
normalizeUrl('//sindresorhus.com', {normalizeProtocol: false});
|
|
20
20
|
//=> '//sindresorhus.com'
|
|
21
21
|
```
|
|
22
22
|
*/
|
|
@@ -29,10 +29,10 @@ export interface Options {
|
|
|
29
29
|
|
|
30
30
|
@example
|
|
31
31
|
```
|
|
32
|
-
normalizeUrl('https://sindresorhus.com
|
|
32
|
+
normalizeUrl('https://sindresorhus.com');
|
|
33
33
|
//=> 'https://sindresorhus.com'
|
|
34
34
|
|
|
35
|
-
normalizeUrl('https://sindresorhus.com
|
|
35
|
+
normalizeUrl('https://sindresorhus.com', {forceHttp: true});
|
|
36
36
|
//=> 'http://sindresorhus.com'
|
|
37
37
|
```
|
|
38
38
|
*/
|
|
@@ -47,10 +47,10 @@ export interface Options {
|
|
|
47
47
|
|
|
48
48
|
@example
|
|
49
49
|
```
|
|
50
|
-
normalizeUrl('
|
|
51
|
-
//=> '
|
|
50
|
+
normalizeUrl('http://sindresorhus.com');
|
|
51
|
+
//=> 'http://sindresorhus.com'
|
|
52
52
|
|
|
53
|
-
normalizeUrl('http://sindresorhus.com
|
|
53
|
+
normalizeUrl('http://sindresorhus.com', {forceHttps: true});
|
|
54
54
|
//=> 'https://sindresorhus.com'
|
|
55
55
|
```
|
|
56
56
|
*/
|
|
@@ -249,6 +249,23 @@ export interface Options {
|
|
|
249
249
|
*/
|
|
250
250
|
readonly removeDirectoryIndex?: boolean | ReadonlyArray<RegExp | string>;
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
Removes an explicit port number from the URL.
|
|
254
|
+
|
|
255
|
+
Port 443 is always removed from HTTPS URLs and 80 is always removed from HTTP URLs regardless of this option.
|
|
256
|
+
|
|
257
|
+
@default false
|
|
258
|
+
|
|
259
|
+
@example
|
|
260
|
+
```
|
|
261
|
+
normalizeUrl('sindresorhus.com:123', {
|
|
262
|
+
removeExplicitPort: true
|
|
263
|
+
});
|
|
264
|
+
//=> 'http://sindresorhus.com'
|
|
265
|
+
```
|
|
266
|
+
*/
|
|
267
|
+
readonly removeExplicitPort?: boolean;
|
|
268
|
+
|
|
252
269
|
/**
|
|
253
270
|
Sorts the query parameters alphabetically by key.
|
|
254
271
|
|
package/index.js
CHANGED
|
@@ -69,6 +69,7 @@ export default function normalizeUrl(urlString, options) {
|
|
|
69
69
|
removeTrailingSlash: true,
|
|
70
70
|
removeSingleSlash: true,
|
|
71
71
|
removeDirectoryIndex: false,
|
|
72
|
+
removeExplicitPort: false,
|
|
72
73
|
sortQueryParameters: true,
|
|
73
74
|
...options,
|
|
74
75
|
};
|
|
@@ -228,6 +229,11 @@ export default function normalizeUrl(urlString, options) {
|
|
|
228
229
|
urlObject.pathname = urlObject.pathname.replace(/\/$/, '');
|
|
229
230
|
}
|
|
230
231
|
|
|
232
|
+
// Remove an explicit port number, excluding a default port number, if applicable
|
|
233
|
+
if (options.removeExplicitPort && urlObject.port) {
|
|
234
|
+
urlObject.port = '';
|
|
235
|
+
}
|
|
236
|
+
|
|
231
237
|
const oldUrlString = urlString;
|
|
232
238
|
|
|
233
239
|
// Take advantage of many of the Node `url` normalizations
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -54,10 +54,10 @@ Default: `true`
|
|
|
54
54
|
Prepend `defaultProtocol` to the URL if it's protocol-relative.
|
|
55
55
|
|
|
56
56
|
```js
|
|
57
|
-
normalizeUrl('//sindresorhus.com
|
|
57
|
+
normalizeUrl('//sindresorhus.com');
|
|
58
58
|
//=> 'http://sindresorhus.com'
|
|
59
59
|
|
|
60
|
-
normalizeUrl('//sindresorhus.com
|
|
60
|
+
normalizeUrl('//sindresorhus.com', {normalizeProtocol: false});
|
|
61
61
|
//=> '//sindresorhus.com'
|
|
62
62
|
```
|
|
63
63
|
|
|
@@ -69,10 +69,10 @@ Default: `false`
|
|
|
69
69
|
Normalize `https:` to `http:`.
|
|
70
70
|
|
|
71
71
|
```js
|
|
72
|
-
normalizeUrl('https://sindresorhus.com
|
|
72
|
+
normalizeUrl('https://sindresorhus.com');
|
|
73
73
|
//=> 'https://sindresorhus.com'
|
|
74
74
|
|
|
75
|
-
normalizeUrl('https://sindresorhus.com
|
|
75
|
+
normalizeUrl('https://sindresorhus.com', {forceHttp: true});
|
|
76
76
|
//=> 'http://sindresorhus.com'
|
|
77
77
|
```
|
|
78
78
|
|
|
@@ -84,10 +84,10 @@ Default: `false`
|
|
|
84
84
|
Normalize `http:` to `https:`.
|
|
85
85
|
|
|
86
86
|
```js
|
|
87
|
-
normalizeUrl('
|
|
88
|
-
//=> '
|
|
87
|
+
normalizeUrl('http://sindresorhus.com');
|
|
88
|
+
//=> 'http://sindresorhus.com'
|
|
89
89
|
|
|
90
|
-
normalizeUrl('http://sindresorhus.com
|
|
90
|
+
normalizeUrl('http://sindresorhus.com', {forceHttps: true});
|
|
91
91
|
//=> 'https://sindresorhus.com'
|
|
92
92
|
```
|
|
93
93
|
|
|
@@ -275,6 +275,22 @@ normalizeUrl('www.sindresorhus.com/foo/default.php', {
|
|
|
275
275
|
//=> 'http://sindresorhus.com/foo'
|
|
276
276
|
```
|
|
277
277
|
|
|
278
|
+
##### removeExplicitPort
|
|
279
|
+
|
|
280
|
+
Type: `boolean`\
|
|
281
|
+
Default: `false`
|
|
282
|
+
|
|
283
|
+
Removes an explicit port number from the URL.
|
|
284
|
+
|
|
285
|
+
Port 443 is always removed from HTTPS URLs and 80 is always removed from HTTP URLs regardless of this option.
|
|
286
|
+
|
|
287
|
+
```js
|
|
288
|
+
normalizeUrl('sindresorhus.com:123', {
|
|
289
|
+
removeExplicitPort: true
|
|
290
|
+
});
|
|
291
|
+
//=> 'http://sindresorhus.com'
|
|
292
|
+
```
|
|
293
|
+
|
|
278
294
|
##### sortQueryParameters
|
|
279
295
|
|
|
280
296
|
Type: `boolean`\
|