@cspell/url 8.17.0 → 8.17.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 +234 -0
- package/dist/index.js +376 -0
- package/package.json +7 -6
- package/dist/FileUrlBuilder.d.mts +0 -86
- package/dist/FileUrlBuilder.mjs +0 -199
- package/dist/dataUrl.d.mts +0 -8
- package/dist/dataUrl.mjs +0 -25
- package/dist/defaultFileUrlBuilder.d.mts +0 -27
- package/dist/defaultFileUrlBuilder.mjs +0 -37
- package/dist/fileUrl.d.mts +0 -22
- package/dist/fileUrl.mjs +0 -58
- package/dist/index.d.mts +0 -7
- package/dist/index.mjs +0 -6
- package/dist/url.d.mts +0 -114
- package/dist/url.mjs +0 -187
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import Path from 'node:path';
|
|
2
|
-
export declare const percentRegEx: RegExp;
|
|
3
|
-
export declare const backslashRegEx: RegExp;
|
|
4
|
-
export declare const newlineRegEx: RegExp;
|
|
5
|
-
export declare const carriageReturnRegEx: RegExp;
|
|
6
|
-
export declare const tabRegEx: RegExp;
|
|
7
|
-
export declare const questionRegex: RegExp;
|
|
8
|
-
export declare const hashRegex: RegExp;
|
|
9
|
-
export interface PathInterface {
|
|
10
|
-
sep: string;
|
|
11
|
-
resolve(...paths: string[]): string;
|
|
12
|
-
parse(path: string): Path.ParsedPath;
|
|
13
|
-
normalize(path: string): string;
|
|
14
|
-
relative(from: string, to: string): string;
|
|
15
|
-
isAbsolute(path: string): boolean;
|
|
16
|
-
}
|
|
17
|
-
export interface BuilderOptions {
|
|
18
|
-
windows?: boolean | undefined;
|
|
19
|
-
path?: PathInterface | undefined;
|
|
20
|
-
cwd?: URL | undefined;
|
|
21
|
-
}
|
|
22
|
-
export declare class FileUrlBuilder {
|
|
23
|
-
#private;
|
|
24
|
-
private windows;
|
|
25
|
-
readonly path: PathInterface;
|
|
26
|
-
readonly cwd: URL;
|
|
27
|
-
constructor(options?: BuilderOptions);
|
|
28
|
-
/**
|
|
29
|
-
* Encode special characters in a file path to use in a URL.
|
|
30
|
-
* @param filepath
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
encodePathChars(filepath: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Normalize a file path for use in a URL.
|
|
36
|
-
* ```js
|
|
37
|
-
* const url = new URL(normalizeFilePathForUrl('path\\to\\file.txt'), 'file:///Users/user/');
|
|
38
|
-
* // Result: file:///Users/user/path/to/file.txt
|
|
39
|
-
* ```
|
|
40
|
-
* @param filePath
|
|
41
|
-
* @returns a normalized file path for use as a relative path in a URL.
|
|
42
|
-
*/
|
|
43
|
-
normalizeFilePathForUrl(filePath: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Try to make a file URL.
|
|
46
|
-
* - if filenameOrUrl is already a URL, it is returned as is.
|
|
47
|
-
* @param filenameOrUrl
|
|
48
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
49
|
-
* @returns a URL
|
|
50
|
-
*/
|
|
51
|
-
toFileURL(filenameOrUrl: string | URL, relativeTo?: string | URL): URL;
|
|
52
|
-
/**
|
|
53
|
-
* Try to make a URL for a directory.
|
|
54
|
-
* - if dirOrUrl is already a URL, a slash is appended to the pathname.
|
|
55
|
-
* @param dirOrUrl - directory path to convert to a file URL.
|
|
56
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
57
|
-
* @returns a URL
|
|
58
|
-
*/
|
|
59
|
-
toFileDirURL(dirOrUrl: string | URL, relativeTo?: string | URL): URL;
|
|
60
|
-
urlToFilePathOrHref(url: URL | string): string;
|
|
61
|
-
/**
|
|
62
|
-
* Calculate the relative path to go from `urlFrom` to `urlTo`.
|
|
63
|
-
* The protocol is not evaluated. Only the `url.pathname` is used.
|
|
64
|
-
* The result: `new URL(relative(urlFrom, urlTo), urlFrom).pathname === urlTo.pathname`
|
|
65
|
-
* @param urlFrom
|
|
66
|
-
* @param urlTo
|
|
67
|
-
* @returns the relative path
|
|
68
|
-
*/
|
|
69
|
-
relative(urlFrom: URL, urlTo: URL): string;
|
|
70
|
-
/**
|
|
71
|
-
* Get the parent directory of a URL.
|
|
72
|
-
* @param url
|
|
73
|
-
*/
|
|
74
|
-
urlDirname(url: URL | string): URL;
|
|
75
|
-
pathToFileURL(pathname: string, relativeToURL?: URL | string): URL;
|
|
76
|
-
rootFileURL(filePath?: string): URL;
|
|
77
|
-
/**
|
|
78
|
-
* Determine if a filePath is absolute.
|
|
79
|
-
*
|
|
80
|
-
* @param filePath
|
|
81
|
-
* @returns true if `URL` or `path.isAbsolute(filePath)`
|
|
82
|
-
*/
|
|
83
|
-
isAbsolute(filePath: string): boolean;
|
|
84
|
-
isUrlLike(url: string | URL): boolean;
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=FileUrlBuilder.d.mts.map
|
package/dist/FileUrlBuilder.mjs
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import Path from 'node:path';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { isFileURL, isWindows, isWindowsFileUrl, isWindowsPathnameWithDriveLatter, pathWindowsDriveLetterToUpper, regExpWindowsPathDriveLetter, toFilePathOrHref, } from './fileUrl.mjs';
|
|
5
|
-
import { addTrailingSlash, isUrlLike, normalizeWindowsUrl, regExpWindowsPath, urlParent, urlToUrlRelative, } from './url.mjs';
|
|
6
|
-
const isWindowsPathRegEx = regExpWindowsPathDriveLetter;
|
|
7
|
-
const isWindowsPathname = regExpWindowsPath;
|
|
8
|
-
export const percentRegEx = /%/g;
|
|
9
|
-
export const backslashRegEx = /\\/g;
|
|
10
|
-
export const newlineRegEx = /\n/g;
|
|
11
|
-
export const carriageReturnRegEx = /\r/g;
|
|
12
|
-
export const tabRegEx = /\t/g;
|
|
13
|
-
export const questionRegex = /\?/g;
|
|
14
|
-
export const hashRegex = /#/g;
|
|
15
|
-
const ProtocolFile = 'file:';
|
|
16
|
-
export class FileUrlBuilder {
|
|
17
|
-
windows;
|
|
18
|
-
path;
|
|
19
|
-
cwd;
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
const sep = options.path?.sep;
|
|
22
|
-
this.windows = options.windows ?? (sep ? sep === '\\' : undefined) ?? isWindows;
|
|
23
|
-
this.path = options.path ?? (this.windows ? Path.win32 : Path.posix);
|
|
24
|
-
// note: `this.path.resolve() + '/'` is used on purpose instead of `'./'`
|
|
25
|
-
this.cwd = options.cwd ?? this.pathToFileURL(this.path.resolve() + '/', this.rootFileURL());
|
|
26
|
-
assert(this.path.sep === (this.windows ? '\\' : '/'), `Path separator should match OS type Windows: ${this.windows === true ? 'true' : (this.windows ?? 'undefined') || 'false'}, ` +
|
|
27
|
-
`sep: ${this.path.sep}, ` +
|
|
28
|
-
`options: ` +
|
|
29
|
-
JSON.stringify({
|
|
30
|
-
isWindows,
|
|
31
|
-
sep: `${sep}`,
|
|
32
|
-
windows: options.windows,
|
|
33
|
-
pathSep: options.path?.sep,
|
|
34
|
-
n: options.path?.normalize('path/file.txt'),
|
|
35
|
-
cwd: options.cwd?.href,
|
|
36
|
-
win32: this.path === Path.win32,
|
|
37
|
-
posix: this.path === Path.posix,
|
|
38
|
-
'win32.normalize': this.path.normalize === Path.win32.normalize,
|
|
39
|
-
'posix.normalize': this.path.normalize === Path.posix.normalize,
|
|
40
|
-
}) +
|
|
41
|
-
``);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Encode special characters in a file path to use in a URL.
|
|
45
|
-
* @param filepath
|
|
46
|
-
* @returns
|
|
47
|
-
*/
|
|
48
|
-
encodePathChars(filepath) {
|
|
49
|
-
filepath = filepath.replaceAll(percentRegEx, '%25');
|
|
50
|
-
// In posix, backslash is a valid character in paths:
|
|
51
|
-
if (!this.windows && !isWindows && filepath.includes('\\')) {
|
|
52
|
-
filepath = filepath.replaceAll(backslashRegEx, '%5C');
|
|
53
|
-
}
|
|
54
|
-
filepath = filepath.replaceAll(newlineRegEx, '%0A');
|
|
55
|
-
filepath = filepath.replaceAll(carriageReturnRegEx, '%0D');
|
|
56
|
-
filepath = filepath.replaceAll(tabRegEx, '%09');
|
|
57
|
-
return filepath;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Normalize a file path for use in a URL.
|
|
61
|
-
* ```js
|
|
62
|
-
* const url = new URL(normalizeFilePathForUrl('path\\to\\file.txt'), 'file:///Users/user/');
|
|
63
|
-
* // Result: file:///Users/user/path/to/file.txt
|
|
64
|
-
* ```
|
|
65
|
-
* @param filePath
|
|
66
|
-
* @returns a normalized file path for use as a relative path in a URL.
|
|
67
|
-
*/
|
|
68
|
-
normalizeFilePathForUrl(filePath) {
|
|
69
|
-
filePath = this.encodePathChars(filePath);
|
|
70
|
-
filePath = filePath.replaceAll(questionRegex, '%3F');
|
|
71
|
-
filePath = filePath.replaceAll(hashRegex, '%23');
|
|
72
|
-
const pathname = filePath.replaceAll('\\', '/');
|
|
73
|
-
return pathname.replace(isWindowsPathRegEx, (drive) => `/${drive}`.toUpperCase());
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Try to make a file URL.
|
|
77
|
-
* - if filenameOrUrl is already a URL, it is returned as is.
|
|
78
|
-
* @param filenameOrUrl
|
|
79
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
80
|
-
* @returns a URL
|
|
81
|
-
*/
|
|
82
|
-
toFileURL(filenameOrUrl, relativeTo) {
|
|
83
|
-
return normalizeWindowsUrl(this.#toFileURL(filenameOrUrl, relativeTo));
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Try to make a file URL.
|
|
87
|
-
* - if filenameOrUrl is already a URL, it is returned as is.
|
|
88
|
-
* @param filenameOrUrl
|
|
89
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
90
|
-
* @returns a URL
|
|
91
|
-
*/
|
|
92
|
-
#toFileURL(filenameOrUrl, relativeTo) {
|
|
93
|
-
if (typeof filenameOrUrl !== 'string')
|
|
94
|
-
return filenameOrUrl;
|
|
95
|
-
if (isUrlLike(filenameOrUrl))
|
|
96
|
-
return normalizeWindowsUrl(new URL(filenameOrUrl));
|
|
97
|
-
relativeTo ??= this.cwd;
|
|
98
|
-
isWindows && (filenameOrUrl = filenameOrUrl.replaceAll('\\', '/'));
|
|
99
|
-
if (this.isAbsolute(filenameOrUrl) && isFileURL(relativeTo)) {
|
|
100
|
-
const pathname = this.normalizeFilePathForUrl(filenameOrUrl);
|
|
101
|
-
if (isWindowsFileUrl(relativeTo) && !isWindowsPathnameWithDriveLatter(pathname)) {
|
|
102
|
-
const relFilePrefix = relativeTo.toString().slice(0, 10);
|
|
103
|
-
return normalizeWindowsUrl(new URL(relFilePrefix + pathname));
|
|
104
|
-
}
|
|
105
|
-
return normalizeWindowsUrl(new URL('file://' + pathname));
|
|
106
|
-
}
|
|
107
|
-
if (isUrlLike(relativeTo)) {
|
|
108
|
-
const pathname = this.normalizeFilePathForUrl(filenameOrUrl);
|
|
109
|
-
return normalizeWindowsUrl(new URL(pathname, relativeTo));
|
|
110
|
-
}
|
|
111
|
-
// Resolve removes the trailing slash, so we need to add it back.
|
|
112
|
-
const appendSlash = filenameOrUrl.endsWith('/') ? '/' : '';
|
|
113
|
-
const pathname = this.normalizeFilePathForUrl(this.path.resolve(relativeTo.toString(), filenameOrUrl)) + appendSlash;
|
|
114
|
-
return normalizeWindowsUrl(new URL('file://' + pathname));
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Try to make a URL for a directory.
|
|
118
|
-
* - if dirOrUrl is already a URL, a slash is appended to the pathname.
|
|
119
|
-
* @param dirOrUrl - directory path to convert to a file URL.
|
|
120
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
121
|
-
* @returns a URL
|
|
122
|
-
*/
|
|
123
|
-
toFileDirURL(dirOrUrl, relativeTo) {
|
|
124
|
-
return addTrailingSlash(this.toFileURL(dirOrUrl, relativeTo));
|
|
125
|
-
}
|
|
126
|
-
urlToFilePathOrHref(url) {
|
|
127
|
-
url = this.toFileURL(url);
|
|
128
|
-
return this.#urlToFilePathOrHref(url);
|
|
129
|
-
}
|
|
130
|
-
#urlToFilePathOrHref(url) {
|
|
131
|
-
if (url.protocol !== ProtocolFile || url.hostname)
|
|
132
|
-
return url.href;
|
|
133
|
-
const p = this.path === Path
|
|
134
|
-
? toFilePathOrHref(url)
|
|
135
|
-
: decodeURIComponent(url.pathname.split('/').join(this.path.sep));
|
|
136
|
-
return pathWindowsDriveLetterToUpper(p.replace(isWindowsPathname, '$1'));
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Calculate the relative path to go from `urlFrom` to `urlTo`.
|
|
140
|
-
* The protocol is not evaluated. Only the `url.pathname` is used.
|
|
141
|
-
* The result: `new URL(relative(urlFrom, urlTo), urlFrom).pathname === urlTo.pathname`
|
|
142
|
-
* @param urlFrom
|
|
143
|
-
* @param urlTo
|
|
144
|
-
* @returns the relative path
|
|
145
|
-
*/
|
|
146
|
-
relative(urlFrom, urlTo) {
|
|
147
|
-
if (urlFrom.protocol === urlTo.protocol && urlFrom.protocol === ProtocolFile) {
|
|
148
|
-
if (urlFrom.href === urlTo.href)
|
|
149
|
-
return '';
|
|
150
|
-
urlFrom = urlFrom.pathname.endsWith('/') ? urlFrom : new URL('./', urlFrom);
|
|
151
|
-
const fromPath = urlFrom.pathname;
|
|
152
|
-
const toPath = urlTo.pathname;
|
|
153
|
-
if (toPath.startsWith(fromPath))
|
|
154
|
-
return decodeURIComponent(toPath.slice(fromPath.length));
|
|
155
|
-
const pFrom = this.#urlToFilePathOrHref(urlFrom);
|
|
156
|
-
const pTo = this.#urlToFilePathOrHref(urlTo);
|
|
157
|
-
const toIsDir = urlTo.pathname.endsWith('/');
|
|
158
|
-
let pathname = this.normalizeFilePathForUrl(this.path.relative(pFrom, pTo));
|
|
159
|
-
if (toIsDir && !pathname.endsWith('/'))
|
|
160
|
-
pathname += '/';
|
|
161
|
-
return decodeURIComponent(pathname);
|
|
162
|
-
}
|
|
163
|
-
return decodeURIComponent(urlToUrlRelative(urlFrom, urlTo));
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Get the parent directory of a URL.
|
|
167
|
-
* @param url
|
|
168
|
-
*/
|
|
169
|
-
urlDirname(url) {
|
|
170
|
-
return urlParent(this.toFileURL(url));
|
|
171
|
-
}
|
|
172
|
-
pathToFileURL(pathname, relativeToURL) {
|
|
173
|
-
return new URL(this.normalizeFilePathForUrl(pathname), relativeToURL || this.cwd);
|
|
174
|
-
}
|
|
175
|
-
rootFileURL(filePath) {
|
|
176
|
-
const path = this.path;
|
|
177
|
-
const p = path.parse(path.normalize(path.resolve(filePath ?? '.')));
|
|
178
|
-
return new URL(this.normalizeFilePathForUrl(p.root), this.#getFsRootURL());
|
|
179
|
-
}
|
|
180
|
-
#getFsRootURL() {
|
|
181
|
-
if (this.path === Path)
|
|
182
|
-
return pathToFileURL('/');
|
|
183
|
-
const p = this.path.resolve('/');
|
|
184
|
-
return new URL(this.normalizeFilePathForUrl(p), 'file:///');
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Determine if a filePath is absolute.
|
|
188
|
-
*
|
|
189
|
-
* @param filePath
|
|
190
|
-
* @returns true if `URL` or `path.isAbsolute(filePath)`
|
|
191
|
-
*/
|
|
192
|
-
isAbsolute(filePath) {
|
|
193
|
-
return isUrlLike(filePath) || this.path.isAbsolute(filePath);
|
|
194
|
-
}
|
|
195
|
-
isUrlLike(url) {
|
|
196
|
-
return isUrlLike(url);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
//# sourceMappingURL=FileUrlBuilder.mjs.map
|
package/dist/dataUrl.d.mts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Try to determine the base name of a URL.
|
|
3
|
-
* @param url
|
|
4
|
-
* @returns the base name of a URL, including the trailing `/` if present.
|
|
5
|
-
*/
|
|
6
|
-
export declare function urlBasename(url: string | URL): string;
|
|
7
|
-
export declare function isDataURL(url: string | URL): boolean;
|
|
8
|
-
//# sourceMappingURL=dataUrl.d.mts.map
|
package/dist/dataUrl.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { basenameOfUrlPathname, hasProtocol, toURL } from './url.mjs';
|
|
2
|
-
const regMatchFilename = /filename=([^;,]*)/;
|
|
3
|
-
/**
|
|
4
|
-
* Try to determine the base name of a URL.
|
|
5
|
-
* @param url
|
|
6
|
-
* @returns the base name of a URL, including the trailing `/` if present.
|
|
7
|
-
*/
|
|
8
|
-
export function urlBasename(url) {
|
|
9
|
-
function guessDataUrlName(header) {
|
|
10
|
-
const filenameMatch = header.match(regMatchFilename);
|
|
11
|
-
if (filenameMatch)
|
|
12
|
-
return filenameMatch[1];
|
|
13
|
-
const mime = header.split(';', 1)[0];
|
|
14
|
-
return mime.replaceAll(/\W/g, '.');
|
|
15
|
-
}
|
|
16
|
-
url = toURL(url);
|
|
17
|
-
if (url.protocol === 'data:') {
|
|
18
|
-
return guessDataUrlName(url.pathname.split(',', 1)[0]);
|
|
19
|
-
}
|
|
20
|
-
return basenameOfUrlPathname(url.pathname);
|
|
21
|
-
}
|
|
22
|
-
export function isDataURL(url) {
|
|
23
|
-
return hasProtocol(url, 'data:');
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=dataUrl.mjs.map
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export declare function encodePathChars(filepath: string): string;
|
|
2
|
-
/**
|
|
3
|
-
* Normalize a file path for use in a URL.
|
|
4
|
-
* ```js
|
|
5
|
-
* const url = new URL(normalizeFilePathForUrl('path\\to\\file.txt'), 'file:///Users/user/');
|
|
6
|
-
* // Result: file:///Users/user/path/to/file.txt
|
|
7
|
-
* ```
|
|
8
|
-
* @param filePath
|
|
9
|
-
* @returns a normalized file path for use as a relative path in a URL.
|
|
10
|
-
*/
|
|
11
|
-
export declare function normalizeFilePathForUrl(filePath: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Try to make a file URL.
|
|
14
|
-
* - if filenameOrUrl is already a URL, it is returned as is.
|
|
15
|
-
* -
|
|
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 toFileURL(filenameOrUrl: string | URL, relativeTo?: string | URL): URL;
|
|
21
|
-
/**
|
|
22
|
-
* Converts a file path to a URL and adds a trailing slash.
|
|
23
|
-
* @param dir - url to a directory
|
|
24
|
-
* @returns a URL
|
|
25
|
-
*/
|
|
26
|
-
export declare function toFileDirURL(dir: string | URL): URL;
|
|
27
|
-
//# sourceMappingURL=defaultFileUrlBuilder.d.mts.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { FileUrlBuilder } from './FileUrlBuilder.mjs';
|
|
2
|
-
const fileUrlBuilder = new FileUrlBuilder();
|
|
3
|
-
export function encodePathChars(filepath) {
|
|
4
|
-
return fileUrlBuilder.encodePathChars(filepath);
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Normalize a file path for use in a URL.
|
|
8
|
-
* ```js
|
|
9
|
-
* const url = new URL(normalizeFilePathForUrl('path\\to\\file.txt'), 'file:///Users/user/');
|
|
10
|
-
* // Result: file:///Users/user/path/to/file.txt
|
|
11
|
-
* ```
|
|
12
|
-
* @param filePath
|
|
13
|
-
* @returns a normalized file path for use as a relative path in a URL.
|
|
14
|
-
*/
|
|
15
|
-
export function normalizeFilePathForUrl(filePath) {
|
|
16
|
-
return fileUrlBuilder.normalizeFilePathForUrl(filePath);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Try to make a file URL.
|
|
20
|
-
* - if filenameOrUrl is already a URL, it is returned as is.
|
|
21
|
-
* -
|
|
22
|
-
* @param filenameOrUrl
|
|
23
|
-
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
|
|
24
|
-
* @returns a URL
|
|
25
|
-
*/
|
|
26
|
-
export function toFileURL(filenameOrUrl, relativeTo) {
|
|
27
|
-
return fileUrlBuilder.toFileURL(filenameOrUrl, relativeTo);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Converts a file path to a URL and adds a trailing slash.
|
|
31
|
-
* @param dir - url to a directory
|
|
32
|
-
* @returns a URL
|
|
33
|
-
*/
|
|
34
|
-
export function toFileDirURL(dir) {
|
|
35
|
-
return fileUrlBuilder.toFileDirURL(dir);
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=defaultFileUrlBuilder.mjs.map
|
package/dist/fileUrl.d.mts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare const isWindows: boolean;
|
|
2
|
-
export declare function isWindowsPathnameWithDriveLatter(pathname: string): boolean;
|
|
3
|
-
/**
|
|
4
|
-
* @param url - URL or string to check if it is a file URL.
|
|
5
|
-
* @returns true if the URL is a file URL.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isFileURL(url: URL | string): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Convert a URL into a string. If it is a file URL, convert it to a path.
|
|
10
|
-
* @param url - URL
|
|
11
|
-
* @returns path or href
|
|
12
|
-
*/
|
|
13
|
-
export declare function toFilePathOrHref(url: URL | string): string;
|
|
14
|
-
export declare const regExpWindowsPathDriveLetter: RegExp;
|
|
15
|
-
export declare function pathWindowsDriveLetterToUpper(absoluteFilePath: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Test if a url is a file url with a windows path. It does check for UNC paths.
|
|
18
|
-
* @param url - the url
|
|
19
|
-
* @returns true if the url is a file url with a windows path with a drive letter.
|
|
20
|
-
*/
|
|
21
|
-
export declare function isWindowsFileUrl(url: URL | string): boolean;
|
|
22
|
-
//# sourceMappingURL=fileUrl.d.mts.map
|
package/dist/fileUrl.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
-
import { hasProtocol } from './url.mjs';
|
|
3
|
-
export const isWindows = process.platform === 'win32';
|
|
4
|
-
const windowsUrlPathRegExp = /^\/[a-zA-Z]:\//;
|
|
5
|
-
export function isWindowsPathnameWithDriveLatter(pathname) {
|
|
6
|
-
return windowsUrlPathRegExp.test(pathname);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @param url - URL or string to check if it is a file URL.
|
|
10
|
-
* @returns true if the URL is a file URL.
|
|
11
|
-
*/
|
|
12
|
-
export function isFileURL(url) {
|
|
13
|
-
return hasProtocol(url, 'file:');
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Convert a URL into a string. If it is a file URL, convert it to a path.
|
|
17
|
-
* @param url - URL
|
|
18
|
-
* @returns path or href
|
|
19
|
-
*/
|
|
20
|
-
export function toFilePathOrHref(url) {
|
|
21
|
-
return isFileURL(url) && url.toString().startsWith('file:///') ? toFilePath(url) : url.toString();
|
|
22
|
-
}
|
|
23
|
-
function toFilePath(url) {
|
|
24
|
-
try {
|
|
25
|
-
// Fix drive letter if necessary.
|
|
26
|
-
if (isWindows) {
|
|
27
|
-
const u = new URL(url);
|
|
28
|
-
if (!isWindowsPathnameWithDriveLatter(u.pathname)) {
|
|
29
|
-
const cwdUrl = pathToFileURL(process.cwd());
|
|
30
|
-
if (cwdUrl.hostname) {
|
|
31
|
-
return fileURLToPath(new URL(u.pathname, cwdUrl));
|
|
32
|
-
}
|
|
33
|
-
const drive = cwdUrl.pathname.split('/')[1];
|
|
34
|
-
u.pathname = `/${drive}${u.pathname}`;
|
|
35
|
-
return fileURLToPath(u);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return pathWindowsDriveLetterToUpper(fileURLToPath(url));
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
// console.error('Failed to convert URL to path', url);
|
|
42
|
-
return url.toString();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export const regExpWindowsPathDriveLetter = /^([a-zA-Z]):[\\/]/;
|
|
46
|
-
export function pathWindowsDriveLetterToUpper(absoluteFilePath) {
|
|
47
|
-
return absoluteFilePath.replace(regExpWindowsPathDriveLetter, (s) => s.toUpperCase());
|
|
48
|
-
}
|
|
49
|
-
const regExpWindowsFileUrl = /^file:\/\/\/[a-zA-Z]:\//;
|
|
50
|
-
/**
|
|
51
|
-
* Test if a url is a file url with a windows path. It does check for UNC paths.
|
|
52
|
-
* @param url - the url
|
|
53
|
-
* @returns true if the url is a file url with a windows path with a drive letter.
|
|
54
|
-
*/
|
|
55
|
-
export function isWindowsFileUrl(url) {
|
|
56
|
-
return regExpWindowsFileUrl.test(url.toString());
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=fileUrl.mjs.map
|
package/dist/index.d.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { isDataURL, urlBasename } from './dataUrl.mjs';
|
|
2
|
-
export { encodePathChars, normalizeFilePathForUrl, toFileDirURL, toFileURL } from './defaultFileUrlBuilder.mjs';
|
|
3
|
-
export { isFileURL, toFilePathOrHref } from './fileUrl.mjs';
|
|
4
|
-
export type { BuilderOptions, PathInterface } from './FileUrlBuilder.mjs';
|
|
5
|
-
export { FileUrlBuilder } from './FileUrlBuilder.mjs';
|
|
6
|
-
export { addTrailingSlash, basenameOfUrlPathname, fixUncUrl, hasProtocol, isNotUrlLike, isURL, isUrlLike, normalizeWindowsUrl, toURL, urlDirname, urlParent, urlRelative, } from './url.mjs';
|
|
7
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { isDataURL, urlBasename } from './dataUrl.mjs';
|
|
2
|
-
export { encodePathChars, normalizeFilePathForUrl, toFileDirURL, toFileURL } from './defaultFileUrlBuilder.mjs';
|
|
3
|
-
export { isFileURL, toFilePathOrHref } from './fileUrl.mjs';
|
|
4
|
-
export { FileUrlBuilder } from './FileUrlBuilder.mjs';
|
|
5
|
-
export { addTrailingSlash, basenameOfUrlPathname, fixUncUrl, hasProtocol, isNotUrlLike, isURL, isUrlLike, normalizeWindowsUrl, toURL, urlDirname, urlParent, urlRelative, } from './url.mjs';
|
|
6
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/url.d.mts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Try to make a URL.
|
|
3
|
-
* @param url
|
|
4
|
-
* @param relativeTo - optional URL, if given, url will be parsed as relative.
|
|
5
|
-
* @returns a URL
|
|
6
|
-
*/
|
|
7
|
-
export declare function toURL(url: string | URL, relativeTo?: string | URL): URL;
|
|
8
|
-
/**
|
|
9
|
-
* Try to determine the parent directory URL of the uri.
|
|
10
|
-
* If it is not a hierarchical URL, then it will return the URL.
|
|
11
|
-
* @param url - url to extract the dirname from.
|
|
12
|
-
* @returns a URL
|
|
13
|
-
*/
|
|
14
|
-
export declare function urlParent(url: string | URL): URL;
|
|
15
|
-
/**
|
|
16
|
-
* Alias of {@link urlParent}
|
|
17
|
-
* Try to determine the parent directory URL of the uri.
|
|
18
|
-
* If it is not a hierarchical URL, then it will return the URL.
|
|
19
|
-
* @param url - url to extract the dirname from.
|
|
20
|
-
* @returns a URL
|
|
21
|
-
*/
|
|
22
|
-
export declare const urlDirname: typeof urlParent;
|
|
23
|
-
/**
|
|
24
|
-
* return the basename (last portion of the URL pathname) of a path. It does NOT remove the trailing slash.
|
|
25
|
-
* @param path - URL pathname to extract the basename from.
|
|
26
|
-
*/
|
|
27
|
-
export declare function basenameOfUrlPathname(path: string): string;
|
|
28
|
-
/**
|
|
29
|
-
* @param filename - filename to check if it is a string containing a URL.
|
|
30
|
-
*/
|
|
31
|
-
export declare function isUrlLike(filename: string): boolean;
|
|
32
|
-
export declare function isUrlLike(filename: URL): true;
|
|
33
|
-
/**
|
|
34
|
-
* @param filename - filename to check if it is a string containing a URL or a URL object.
|
|
35
|
-
*/
|
|
36
|
-
export declare function isUrlLike(filename: string | URL): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* @param filename - filename to check if it is a string containing a URL.
|
|
39
|
-
*/
|
|
40
|
-
export declare function isNotUrlLike(filename: string): boolean;
|
|
41
|
-
export declare function isNotUrlLike(filename: URL): false;
|
|
42
|
-
/**
|
|
43
|
-
* @param filename - filename to check if it is a string containing a URL or a URL object.
|
|
44
|
-
*/
|
|
45
|
-
export declare function isNotUrlLike(filename: string | URL): filename is string;
|
|
46
|
-
/**
|
|
47
|
-
* Check if `url` is a URL instance.
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
export declare function isURL(url: unknown): url is URL;
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
* @param url - url to check
|
|
54
|
-
* @param protocol - protocol to check against - e.g. 'file:', 'http:', 'https:'
|
|
55
|
-
* @returns
|
|
56
|
-
*/
|
|
57
|
-
export declare function hasProtocol(url: string | URL, protocol: string): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Attempts to add a trailing slash to the URL pathname if it does not already have one.
|
|
60
|
-
* Some If the pathname doesn't start with a `/`, a trailing slash is not added.
|
|
61
|
-
* @param url - a URL
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
export declare function addTrailingSlash(url: URL): URL;
|
|
65
|
-
/**
|
|
66
|
-
* Remove the filename at the end of the URL pathname.
|
|
67
|
-
* If the URL pathname ends with a `/`, it is considered a directory and the URL is returned as is.
|
|
68
|
-
* If the URL pathname does not start with a `/`, it is considered an non-regular URL and the URL is returned as is.
|
|
69
|
-
* @param url
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
export declare function urlRemoveFilename(url: URL): URL;
|
|
73
|
-
/**
|
|
74
|
-
* Extract the filename from the URL pathname.
|
|
75
|
-
*
|
|
76
|
-
* ```ts
|
|
77
|
-
* url.href === new URL(urlFilename(url), urlRemoveFilename(url)).href
|
|
78
|
-
* ```
|
|
79
|
-
* @param url - URL to extract the filename from.
|
|
80
|
-
* @returns the filename or empty string if the URL pathname ends with a `/`.
|
|
81
|
-
*/
|
|
82
|
-
export declare function urlFilename(url: URL): string;
|
|
83
|
-
/**
|
|
84
|
-
* Calculate the relative path to go from `urlFrom` to `urlTo`.
|
|
85
|
-
* The protocol is not evaluated. Only the `url.pathname` is used.
|
|
86
|
-
* @param urlFrom
|
|
87
|
-
* @param urlTo
|
|
88
|
-
* @returns the relative path
|
|
89
|
-
*/
|
|
90
|
-
export declare function urlRelative(urlFrom: string | URL, urlTo: string | URL): string;
|
|
91
|
-
/**
|
|
92
|
-
* Calculate the relative path to go from `urlFrom` to `urlTo`.
|
|
93
|
-
* The protocol is not evaluated. Only the `url.pathname` is used.
|
|
94
|
-
* @param urlFrom
|
|
95
|
-
* @param urlTo
|
|
96
|
-
* @returns the relative path
|
|
97
|
-
*/
|
|
98
|
-
export declare function urlToUrlRelative(urlFrom: URL, urlTo: URL): string;
|
|
99
|
-
export declare const regExpWindowsPath: RegExp;
|
|
100
|
-
export declare const regExpEncodedColon: RegExp;
|
|
101
|
-
/**
|
|
102
|
-
* Ensure that a windows file url is correctly formatted with a capitol letter for the drive.
|
|
103
|
-
*
|
|
104
|
-
* @param url - URL to check.
|
|
105
|
-
* @returns a new URL if modified or converted from a string.
|
|
106
|
-
*/
|
|
107
|
-
export declare function normalizeWindowsUrl(url: URL | string): URL;
|
|
108
|
-
/**
|
|
109
|
-
* There is a bug is NodeJS that sometimes causes UNC paths converted to a URL to be prefixed with `file:////`.
|
|
110
|
-
* @param url - URL to check.
|
|
111
|
-
* @returns fixed URL if needed.
|
|
112
|
-
*/
|
|
113
|
-
export declare function fixUncUrl(url: URL): URL;
|
|
114
|
-
//# sourceMappingURL=url.d.mts.map
|