normalize-url 8.1.0 → 8.1.1

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.
Files changed (2) hide show
  1. package/index.js +11 -14
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -29,14 +29,12 @@ const normalizeDataURL = (urlString, {stripHash}) => {
29
29
  throw new Error(`Invalid URL: ${urlString}`);
30
30
  }
31
31
 
32
- let {type, data, hash} = match.groups;
32
+ const {type, data, hash} = match.groups;
33
33
  const mediaType = type.split(';');
34
- hash = stripHash ? '' : hash;
35
34
 
36
- let isBase64 = false;
37
- if (mediaType[mediaType.length - 1] === 'base64') {
35
+ const isBase64 = mediaType.at(-1) === 'base64';
36
+ if (isBase64) {
38
37
  mediaType.pop();
39
- isBase64 = true;
40
38
  }
41
39
 
42
40
  // Lowercase MIME type
@@ -58,9 +56,7 @@ const normalizeDataURL = (urlString, {stripHash}) => {
58
56
  })
59
57
  .filter(Boolean);
60
58
 
61
- const normalizedMediaType = [
62
- ...attributes,
63
- ];
59
+ const normalizedMediaType = [...attributes];
64
60
 
65
61
  if (isBase64) {
66
62
  normalizedMediaType.push('base64');
@@ -70,7 +66,8 @@ const normalizeDataURL = (urlString, {stripHash}) => {
70
66
  normalizedMediaType.unshift(mimeType);
71
67
  }
72
68
 
73
- return `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ''}`;
69
+ const hashPart = stripHash || !hash ? '' : `#${hash}`;
70
+ return `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hashPart}`;
74
71
  };
75
72
 
76
73
  export default function normalizeUrl(urlString, options) {
@@ -193,12 +190,12 @@ export default function normalizeUrl(urlString, options) {
193
190
  }
194
191
 
195
192
  if (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {
196
- let pathComponents = urlObject.pathname.split('/');
197
- const lastComponent = pathComponents[pathComponents.length - 1];
193
+ const pathComponents = urlObject.pathname.split('/').filter(Boolean);
194
+ const lastComponent = pathComponents.at(-1);
198
195
 
199
- if (testParameter(lastComponent, options.removeDirectoryIndex)) {
200
- pathComponents = pathComponents.slice(0, -1);
201
- urlObject.pathname = pathComponents.slice(1).join('/') + '/';
196
+ if (lastComponent && testParameter(lastComponent, options.removeDirectoryIndex)) {
197
+ pathComponents.pop();
198
+ urlObject.pathname = pathComponents.length > 0 ? `/${pathComponents.join('/')}/` : '/';
202
199
  }
203
200
  }
204
201
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "normalize-url",
3
- "version": "8.1.0",
3
+ "version": "8.1.1",
4
4
  "description": "Normalize a URL",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/normalize-url",