@cspell/url 9.2.0 → 9.2.2
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/dist/index.d.ts +0 -22
- package/dist/index.js +5 -10
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -172,12 +172,6 @@ declare function urlParent(url: string | URL): URL;
|
|
|
172
172
|
* @returns a URL
|
|
173
173
|
*/
|
|
174
174
|
declare const urlDirname: typeof urlParent;
|
|
175
|
-
/**
|
|
176
|
-
* Remove the file portion of the URL and return the directory portion.
|
|
177
|
-
* If the URL pathname ends with a `/`, it is considered a directory and the URL is returned as is.
|
|
178
|
-
* @param url - url to extract the dirname from.
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
175
|
/**
|
|
182
176
|
* return the basename (last portion of the URL pathname) of a path. It does NOT remove the trailing slash.
|
|
183
177
|
* @param path - URL pathname to extract the basename from.
|
|
@@ -220,14 +214,6 @@ declare function hasProtocol(url: string | URL, protocol: string): boolean;
|
|
|
220
214
|
* @returns
|
|
221
215
|
*/
|
|
222
216
|
declare function addTrailingSlash(url: URL): URL;
|
|
223
|
-
/**
|
|
224
|
-
* Remove the filename at the end of the URL pathname.
|
|
225
|
-
* If the URL pathname ends with a `/`, it is considered a directory and the URL is returned as is.
|
|
226
|
-
* If the URL pathname does not start with a `/`, it is considered an non-regular URL and the URL is returned as is.
|
|
227
|
-
* @param url
|
|
228
|
-
* @returns
|
|
229
|
-
*/
|
|
230
|
-
|
|
231
217
|
/**
|
|
232
218
|
* Calculate the relative path to go from `urlFrom` to `urlTo`.
|
|
233
219
|
* The protocol is not evaluated. Only the `url.pathname` is used.
|
|
@@ -236,14 +222,6 @@ declare function addTrailingSlash(url: URL): URL;
|
|
|
236
222
|
* @returns the relative path
|
|
237
223
|
*/
|
|
238
224
|
declare function urlRelative(urlFrom: string | URL, urlTo: string | URL): string;
|
|
239
|
-
/**
|
|
240
|
-
* Calculate the relative path to go from `urlFrom` to `urlTo`.
|
|
241
|
-
* The protocol is not evaluated. Only the `url.pathname` is used.
|
|
242
|
-
* @param urlFrom
|
|
243
|
-
* @param urlTo
|
|
244
|
-
* @returns the relative path
|
|
245
|
-
*/
|
|
246
|
-
|
|
247
225
|
/**
|
|
248
226
|
* Ensure that a windows file url is correctly formatted with a capitol letter for the drive.
|
|
249
227
|
*
|
package/dist/index.js
CHANGED
|
@@ -25,8 +25,7 @@ function urlParent(url) {
|
|
|
25
25
|
const hasTrailingSlash = url.pathname.endsWith("/");
|
|
26
26
|
if (!url.pathname.startsWith("/")) {
|
|
27
27
|
if (!url.pathname) return url;
|
|
28
|
-
const
|
|
29
|
-
const pathname = parts.join("/") + "/";
|
|
28
|
+
const pathname = url.pathname.split("/").slice(0, hasTrailingSlash ? -2 : -1).join("/") + "/";
|
|
30
29
|
return new URL(url.protocol + (url.host ? "//" + url.host : "") + pathname + url.search + url.hash);
|
|
31
30
|
}
|
|
32
31
|
return new URL(hasTrailingSlash ? ".." : ".", url);
|
|
@@ -160,8 +159,7 @@ function urlBasename(url) {
|
|
|
160
159
|
function guessDataUrlName(header) {
|
|
161
160
|
const filenameMatch = header.match(regMatchFilename);
|
|
162
161
|
if (filenameMatch) return filenameMatch[1];
|
|
163
|
-
|
|
164
|
-
return mime.replaceAll(/\W/g, ".");
|
|
162
|
+
return header.split(";", 1)[0].replaceAll(/\W/g, ".");
|
|
165
163
|
}
|
|
166
164
|
url = toURL(url);
|
|
167
165
|
if (url.protocol === "data:") return guessDataUrlName(url.pathname.split(",", 1)[0]);
|
|
@@ -200,8 +198,7 @@ function toFilePath(url) {
|
|
|
200
198
|
if (!isWindowsPathnameWithDriveLatter(u.pathname)) {
|
|
201
199
|
const cwdUrl = pathToFileURL(process.cwd());
|
|
202
200
|
if (cwdUrl.hostname) return fileURLToPath(new URL(u.pathname, cwdUrl));
|
|
203
|
-
|
|
204
|
-
u.pathname = `/${drive}${u.pathname}`;
|
|
201
|
+
u.pathname = `/${cwdUrl.pathname.split("/")[1]}${u.pathname}`;
|
|
205
202
|
return fileURLToPath(u);
|
|
206
203
|
}
|
|
207
204
|
}
|
|
@@ -284,8 +281,7 @@ var FileUrlBuilder = class {
|
|
|
284
281
|
filePath = this.encodePathChars(filePath);
|
|
285
282
|
filePath = filePath.replaceAll(questionRegex, "%3F");
|
|
286
283
|
filePath = filePath.replaceAll(hashRegex, "%23");
|
|
287
|
-
|
|
288
|
-
return pathname.replace(isWindowsPathRegEx, (drive) => `/${drive}`.toUpperCase());
|
|
284
|
+
return filePath.replaceAll("\\", "/").replace(isWindowsPathRegEx, (drive) => `/${drive}`.toUpperCase());
|
|
289
285
|
}
|
|
290
286
|
/**
|
|
291
287
|
* Try to make a file URL.
|
|
@@ -341,8 +337,7 @@ var FileUrlBuilder = class {
|
|
|
341
337
|
}
|
|
342
338
|
#urlToFilePathOrHref(url) {
|
|
343
339
|
if (url.protocol !== ProtocolFile || url.hostname) return url.href;
|
|
344
|
-
|
|
345
|
-
return pathWindowsDriveLetterToUpper(p.replace(isWindowsPathname, "$1"));
|
|
340
|
+
return pathWindowsDriveLetterToUpper((this.path === Path ? toFilePathOrHref(url) : decodeURIComponent(url.pathname.split("/").join(this.path.sep))).replace(isWindowsPathname, "$1"));
|
|
346
341
|
}
|
|
347
342
|
/**
|
|
348
343
|
* Calculate the relative path to go from `urlFrom` to `urlTo`.
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"provenance": true
|
|
6
6
|
},
|
|
7
|
-
"version": "9.2.
|
|
7
|
+
"version": "9.2.2",
|
|
8
8
|
"description": "URL parsing and manipulation utilities for cspell",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"cspell",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=20"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "594a58399cb9dad07cbb1d9cef6f2adb87560dd7"
|
|
62
62
|
}
|