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.
- package/index.js +11 -14
- 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
|
-
|
|
32
|
+
const {type, data, hash} = match.groups;
|
|
33
33
|
const mediaType = type.split(';');
|
|
34
|
-
hash = stripHash ? '' : hash;
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
197
|
-
const lastComponent = pathComponents
|
|
193
|
+
const pathComponents = urlObject.pathname.split('/').filter(Boolean);
|
|
194
|
+
const lastComponent = pathComponents.at(-1);
|
|
198
195
|
|
|
199
|
-
if (testParameter(lastComponent, options.removeDirectoryIndex)) {
|
|
200
|
-
pathComponents
|
|
201
|
-
urlObject.pathname = pathComponents.
|
|
196
|
+
if (lastComponent && testParameter(lastComponent, options.removeDirectoryIndex)) {
|
|
197
|
+
pathComponents.pop();
|
|
198
|
+
urlObject.pathname = pathComponents.length > 0 ? `/${pathComponents.join('/')}/` : '/';
|
|
202
199
|
}
|
|
203
200
|
}
|
|
204
201
|
|