cspell-io 8.8.3 → 8.9.0-alpha.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/dist/esm/node/file/url.d.ts +1 -32
- package/dist/esm/node/file/url.js +4 -89
- package/package.json +4 -3
|
@@ -1,41 +1,10 @@
|
|
|
1
|
+
export { basenameOfUrlPathname, isFileURL, isURL, isUrlLike, toFileURL, toURL, urlBasename, urlParent as urlDirname, } from '@cspell/url';
|
|
1
2
|
export declare function isZipped(filename: string | URL): boolean;
|
|
2
|
-
export declare function isUrlLike(filename: string | URL): boolean;
|
|
3
3
|
export declare function isSupportedURL(url: URL): boolean;
|
|
4
|
-
export declare function isFileURL(url: URL): boolean;
|
|
5
|
-
/**
|
|
6
|
-
* Try to make a file URL.
|
|
7
|
-
* - if filenameOrUrl is already a URL, it is returned as is.
|
|
8
|
-
* -
|
|
9
|
-
* @param filenameOrUrl
|
|
10
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
11
|
-
* @returns a URL
|
|
12
|
-
*/
|
|
13
|
-
export declare function toFileURL(filenameOrUrl: string | URL, relativeTo?: string | URL): URL;
|
|
14
|
-
/**
|
|
15
|
-
* Try to make a URL.
|
|
16
|
-
* @param filenameOrUrl
|
|
17
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
18
|
-
* @returns a URL
|
|
19
|
-
*/
|
|
20
|
-
export declare function toURL(filenameOrUrl: string | URL, relativeTo?: string | URL): URL;
|
|
21
|
-
/**
|
|
22
|
-
* Try to determine the base name of a URL.
|
|
23
|
-
* @param url
|
|
24
|
-
* @returns the base name of a URL, including the trailing `/` if present.
|
|
25
|
-
*/
|
|
26
|
-
export declare function urlBasename(url: string | URL): string;
|
|
27
|
-
/**
|
|
28
|
-
* Try to determine the parent directory URL of the uri.
|
|
29
|
-
* If it is not a hierarchical URL, then it will return the URL.
|
|
30
|
-
* @param url - url to extract the dirname from.
|
|
31
|
-
* @returns a URL
|
|
32
|
-
*/
|
|
33
|
-
export declare function urlDirname(url: string | URL): URL;
|
|
34
4
|
/**
|
|
35
5
|
* return the basename of a path, removing the trailing `/` if present.
|
|
36
6
|
* @param path
|
|
37
7
|
* @returns
|
|
38
8
|
*/
|
|
39
9
|
export declare function basename(path: string): string;
|
|
40
|
-
export declare function normalizePathForUrl(filePath: string): string;
|
|
41
10
|
//# sourceMappingURL=url.d.ts.map
|
|
@@ -1,106 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { basenameOfUrlPathname } from '@cspell/url';
|
|
2
|
+
export { basenameOfUrlPathname, isFileURL, isURL, isUrlLike, toFileURL, toURL, urlBasename, urlParent as urlDirname, } from '@cspell/url';
|
|
3
3
|
const isZippedRegExp = /\.gz($|[?#])/i;
|
|
4
|
-
const isURLRegExp = /^([\w-]{2,64}:\/\/|data:)/i;
|
|
5
|
-
const isWindowsPath = /^[a-z]:[\\/]/i;
|
|
6
4
|
const supportedProtocols = { 'file:': true, 'http:': true, 'https:': true };
|
|
7
5
|
export function isZipped(filename) {
|
|
8
6
|
const path = typeof filename === 'string' ? filename : filename.pathname;
|
|
9
7
|
return isZippedRegExp.test(path);
|
|
10
8
|
}
|
|
11
|
-
export function isUrlLike(filename) {
|
|
12
|
-
return filename instanceof URL || isURLRegExp.test(filename);
|
|
13
|
-
}
|
|
14
9
|
export function isSupportedURL(url) {
|
|
15
10
|
return !!supportedProtocols[url.protocol];
|
|
16
11
|
}
|
|
17
|
-
export function isFileURL(url) {
|
|
18
|
-
return url.protocol === 'file:';
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Try to make a file URL.
|
|
22
|
-
* - if filenameOrUrl is already a URL, it is returned as is.
|
|
23
|
-
* -
|
|
24
|
-
* @param filenameOrUrl
|
|
25
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
26
|
-
* @returns a URL
|
|
27
|
-
*/
|
|
28
|
-
export function toFileURL(filenameOrUrl, relativeTo) {
|
|
29
|
-
if (typeof filenameOrUrl !== 'string')
|
|
30
|
-
return filenameOrUrl;
|
|
31
|
-
return isUrlLike(filenameOrUrl)
|
|
32
|
-
? new URL(filenameOrUrl)
|
|
33
|
-
: relativeTo && isUrlLike(relativeTo)
|
|
34
|
-
? new URL(normalizePathForUrl(filenameOrUrl), relativeTo)
|
|
35
|
-
: relativeTo
|
|
36
|
-
? pathToFileURL(path.resolve(relativeTo.toString(), filenameOrUrl))
|
|
37
|
-
: pathToFileURL(filenameOrUrl);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Try to make a URL.
|
|
41
|
-
* @param filenameOrUrl
|
|
42
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
43
|
-
* @returns a URL
|
|
44
|
-
*/
|
|
45
|
-
export function toURL(filenameOrUrl, relativeTo) {
|
|
46
|
-
return filenameOrUrl instanceof URL ? filenameOrUrl : new URL(filenameOrUrl, relativeTo);
|
|
47
|
-
}
|
|
48
|
-
const regMatchFilename = /filename=([^;,]*)/;
|
|
49
|
-
/**
|
|
50
|
-
* Try to determine the base name of a URL.
|
|
51
|
-
* @param url
|
|
52
|
-
* @returns the base name of a URL, including the trailing `/` if present.
|
|
53
|
-
*/
|
|
54
|
-
export function urlBasename(url) {
|
|
55
|
-
function guessDataUrlName(header) {
|
|
56
|
-
const filenameMatch = header.match(regMatchFilename);
|
|
57
|
-
if (filenameMatch)
|
|
58
|
-
return filenameMatch[1];
|
|
59
|
-
const mime = header.split(';', 1)[0];
|
|
60
|
-
return mime.replaceAll(/\W/g, '.');
|
|
61
|
-
}
|
|
62
|
-
url = toURL(url);
|
|
63
|
-
if (url.protocol === 'data:') {
|
|
64
|
-
return guessDataUrlName(url.pathname.split(',', 1)[0]);
|
|
65
|
-
}
|
|
66
|
-
const suffix = url.pathname.endsWith('/') ? '/' : '';
|
|
67
|
-
return basename(url.pathname) + suffix;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Try to determine the parent directory URL of the uri.
|
|
71
|
-
* If it is not a hierarchical URL, then it will return the URL.
|
|
72
|
-
* @param url - url to extract the dirname from.
|
|
73
|
-
* @returns a URL
|
|
74
|
-
*/
|
|
75
|
-
export function urlDirname(url) {
|
|
76
|
-
url = toURL(url);
|
|
77
|
-
if (url.protocol === 'data:') {
|
|
78
|
-
return url;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
return new URL(url.pathname.endsWith('/') ? '..' : '.', url);
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
return url;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
12
|
/**
|
|
88
13
|
* return the basename of a path, removing the trailing `/` if present.
|
|
89
14
|
* @param path
|
|
90
15
|
* @returns
|
|
91
16
|
*/
|
|
92
17
|
export function basename(path) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return idx >= 0 ? path.slice(idx + 1) : path;
|
|
96
|
-
}
|
|
97
|
-
export function normalizePathForUrl(filePath) {
|
|
98
|
-
const pathname = filePath.replaceAll('\\', '/');
|
|
99
|
-
const raw = pathname.replace(isWindowsPath, '/$&');
|
|
100
|
-
return raw
|
|
101
|
-
.split('/')
|
|
102
|
-
.map(encodeURIComponent)
|
|
103
|
-
.join('/')
|
|
104
|
-
.replace(/^\/([a-z])%3A/i, '/$1:');
|
|
18
|
+
const base = basenameOfUrlPathname(path);
|
|
19
|
+
return base.endsWith('/') && !base.endsWith(':/') ? base.slice(0, -1) : base;
|
|
105
20
|
}
|
|
106
21
|
//# sourceMappingURL=url.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-io",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0-alpha.0",
|
|
4
4
|
"description": "A library of useful I/O functions used across various cspell tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"typescript": "^5.4.5"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@cspell/cspell-service-bus": "8.
|
|
55
|
+
"@cspell/cspell-service-bus": "8.9.0-alpha.0",
|
|
56
|
+
"@cspell/url": "8.9.0-alpha.0"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "700ed688420d2f3e784c05e2709ad33953aadadc"
|
|
58
59
|
}
|