@helpers4/url 2.0.0-alpha.2 → 2.0.0-alpha.21
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/LICENSE.md +150 -650
- package/README.md +13 -8
- package/lib/index.d.ts +513 -8
- package/lib/index.js +302 -68
- package/lib/index.js.map +1 -0
- package/llms.txt +519 -0
- package/meta/api.json +492 -0
- package/meta/category.json +6 -0
- package/meta/examples.json +115 -0
- package/meta/licenses.json +4 -0
- package/package.json +22 -9
package/lib/index.js
CHANGED
|
@@ -1,79 +1,313 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region helpers/url/cleanPath.ts
|
|
2
|
+
/**
|
|
3
|
+
* This file is part of helpers4.
|
|
4
|
+
* Copyright (C) 2025 baxyz
|
|
5
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Clean an URL by removing duplicate slashes.
|
|
9
|
+
* The protocol part of the URL is not modified.
|
|
10
|
+
*
|
|
11
|
+
* @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
|
|
12
|
+
* @returns The cleaned URL string, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* cleanPath('/path//to///resource') // => '/path/to/resource'
|
|
17
|
+
* cleanPath('http://example.com//path//to///resource') // => 'http://example.com/path/to/resource'
|
|
18
|
+
* cleanPath(undefined) // => undefined
|
|
19
|
+
* cleanPath(null) // => null
|
|
20
|
+
* ```
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
function cleanPath(url) {
|
|
24
|
+
if (url === void 0 || url === null) return url;
|
|
25
|
+
return url.replace(/([^:]\/)\/+/g, "$1");
|
|
7
26
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region helpers/url/extractPureURI.ts
|
|
29
|
+
function extractPureURI(url) {
|
|
30
|
+
if (url === void 0 || url === null) return url;
|
|
31
|
+
const queryIndex = url.indexOf("?");
|
|
32
|
+
const fragmentIndex = url.indexOf("#");
|
|
33
|
+
let cutIndex = -1;
|
|
34
|
+
if (queryIndex !== -1 && fragmentIndex !== -1) cutIndex = Math.min(queryIndex, fragmentIndex);
|
|
35
|
+
else if (queryIndex !== -1) cutIndex = queryIndex;
|
|
36
|
+
else if (fragmentIndex !== -1) cutIndex = fragmentIndex;
|
|
37
|
+
if (cutIndex === -1) return url;
|
|
38
|
+
return url.substring(0, cutIndex);
|
|
14
39
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region helpers/url/onlyPath.ts
|
|
42
|
+
/**
|
|
43
|
+
* Extract only the path from an URI with optional query and fragments.
|
|
44
|
+
*
|
|
45
|
+
* For example, all these parameters will return `/path`:
|
|
46
|
+
* - `/path`
|
|
47
|
+
* - `/path?query=thing`
|
|
48
|
+
* - `/path#fragment`
|
|
49
|
+
* - `/path?query=thing#fragment`
|
|
50
|
+
*
|
|
51
|
+
* @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
|
|
52
|
+
* @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* onlyPath('/path') // => '/path'
|
|
57
|
+
* onlyPath('/path?query=thing') // => '/path'
|
|
58
|
+
* onlyPath('/path#fragment') // => '/path'
|
|
59
|
+
* onlyPath('/path?query=thing#fragment') // => '/path'
|
|
60
|
+
* onlyPath(undefined) // => undefined
|
|
61
|
+
* onlyPath(null) // => null
|
|
62
|
+
* ```
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
*/
|
|
65
|
+
function onlyPath(url) {
|
|
66
|
+
if (url === void 0 || url === null) return url;
|
|
67
|
+
const [path] = url.split(/[?#]/);
|
|
68
|
+
return path;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region helpers/url/parsePackageRepository.ts
|
|
72
|
+
/** Maps known GitHub/GitLab/Bitbucket domains to their platform name. */
|
|
73
|
+
var DOMAIN_TO_HOST = {
|
|
74
|
+
"github.com": "github",
|
|
75
|
+
"gitlab.com": "gitlab",
|
|
76
|
+
"bitbucket.org": "bitbucket"
|
|
77
|
+
};
|
|
78
|
+
/** SCP-style SSH URL: `git@github.com:owner/repo.git` */
|
|
79
|
+
var RE_SSH_SCP = /^git@([\w.-]+):([\w.-]+\/[\w.-]+?)(?:\.git)?(?:[#?].*)?$/;
|
|
80
|
+
/**
|
|
81
|
+
* URL-form remote: `git+https://…`, `https://…`, `git://…`, `git+ssh://git@…`
|
|
82
|
+
* Captures: [1] domain, [2] owner/repo path
|
|
83
|
+
*/
|
|
84
|
+
var RE_URL = /^(?:git\+(?:https?|ssh)|https?|git):\/\/(?:[^@/]+@)?([\w.-]+)\/([\w.-]+\/[\w.-]+?)(?:\.git)?(?:[#?].*)?$/;
|
|
85
|
+
function makeOwnerRepoResult(type, host, rawPath, directory) {
|
|
86
|
+
const slashIdx = rawPath.indexOf("/");
|
|
87
|
+
const owner = rawPath.slice(0, slashIdx);
|
|
88
|
+
const repo = rawPath.slice(slashIdx + 1);
|
|
89
|
+
return {
|
|
90
|
+
type,
|
|
91
|
+
host,
|
|
92
|
+
slug: `${owner}/${repo}`,
|
|
93
|
+
owner,
|
|
94
|
+
repo,
|
|
95
|
+
gistId: void 0,
|
|
96
|
+
directory
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function parseRawUrl(raw, type, directory) {
|
|
100
|
+
const shorthandMatch = /^(github|gitlab|bitbucket):([\w.-]+\/[\w.-]+)$/.exec(raw);
|
|
101
|
+
if (shorthandMatch) {
|
|
102
|
+
const host = shorthandMatch[1];
|
|
103
|
+
const slug = shorthandMatch[2];
|
|
104
|
+
const slashIdx = slug.indexOf("/");
|
|
105
|
+
return {
|
|
106
|
+
type,
|
|
107
|
+
host,
|
|
108
|
+
slug,
|
|
109
|
+
owner: slug.slice(0, slashIdx),
|
|
110
|
+
repo: slug.slice(slashIdx + 1),
|
|
111
|
+
gistId: void 0,
|
|
112
|
+
directory
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const gistMatch = /^gist:([\w-]+)$/.exec(raw);
|
|
116
|
+
if (gistMatch) return {
|
|
117
|
+
type,
|
|
118
|
+
host: "gist",
|
|
119
|
+
slug: void 0,
|
|
120
|
+
owner: void 0,
|
|
121
|
+
repo: void 0,
|
|
122
|
+
gistId: gistMatch[1],
|
|
123
|
+
directory
|
|
124
|
+
};
|
|
125
|
+
const bareMatch = /^([\w.-]+)\/([\w.-]+)$/.exec(raw);
|
|
126
|
+
if (bareMatch) {
|
|
127
|
+
const owner = bareMatch[1];
|
|
128
|
+
const repo = bareMatch[2];
|
|
129
|
+
return {
|
|
130
|
+
type,
|
|
131
|
+
host: "github",
|
|
132
|
+
slug: `${owner}/${repo}`,
|
|
133
|
+
owner,
|
|
134
|
+
repo,
|
|
135
|
+
gistId: void 0,
|
|
136
|
+
directory
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const sshMatch = RE_SSH_SCP.exec(raw);
|
|
140
|
+
if (sshMatch) return makeOwnerRepoResult(type, DOMAIN_TO_HOST[sshMatch[1]] ?? sshMatch[1], sshMatch[2], directory);
|
|
141
|
+
const urlMatch = RE_URL.exec(raw);
|
|
142
|
+
if (urlMatch) return makeOwnerRepoResult(type, DOMAIN_TO_HOST[urlMatch[1]] ?? urlMatch[1], urlMatch[2], directory);
|
|
21
143
|
}
|
|
22
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Parse the `repository` field from `package.json` into a structured object.
|
|
146
|
+
*
|
|
147
|
+
* Supports all npm-specified formats:
|
|
148
|
+
* - **Object form**: `{ "type": "git", "url": "...", "directory": "..." }`
|
|
149
|
+
* - **GitHub shorthand**: `"owner/repo"` or `"github:owner/repo"`
|
|
150
|
+
* - **Platform shorthands**: `"gitlab:owner/repo"`, `"bitbucket:owner/repo"`
|
|
151
|
+
* - **Gist shorthand**: `"gist:<id>"`
|
|
152
|
+
* - **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`
|
|
153
|
+
*
|
|
154
|
+
* Returns `undefined` for `null`, `undefined`, arrays, or values that cannot
|
|
155
|
+
* be matched to any recognised format.
|
|
156
|
+
*
|
|
157
|
+
* @param repository - The `repository` field value from `package.json`.
|
|
158
|
+
* @returns A parsed {@link PackageRepository} object, or `undefined` if the
|
|
159
|
+
* input cannot be parsed.
|
|
160
|
+
* @example
|
|
161
|
+
* parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })
|
|
162
|
+
* // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',
|
|
163
|
+
* // repo: 'typescript', gistId: undefined, directory: undefined }
|
|
164
|
+
* @example
|
|
165
|
+
* parsePackageRepository('github:helpers4/typescript')
|
|
166
|
+
* // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',
|
|
167
|
+
* // repo: 'typescript', gistId: undefined, directory: undefined }
|
|
168
|
+
* @since next
|
|
169
|
+
*/
|
|
170
|
+
function parsePackageRepository(repository) {
|
|
171
|
+
if (repository === null || repository === void 0) return void 0;
|
|
172
|
+
if (typeof repository === "string") return parseRawUrl(repository, "git", void 0);
|
|
173
|
+
if (typeof repository === "object" && !Array.isArray(repository)) {
|
|
174
|
+
const obj = repository;
|
|
175
|
+
const rawUrl = obj["url"];
|
|
176
|
+
if (typeof rawUrl !== "string") return void 0;
|
|
177
|
+
return parseRawUrl(rawUrl, typeof obj["type"] === "string" ? obj["type"] : "git", typeof obj["directory"] === "string" ? obj["directory"] : void 0);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region helpers/url/withoutTrailingSlash.ts
|
|
182
|
+
/**
|
|
183
|
+
* Removes the trailing slash `/` from the given URL if it is present.
|
|
184
|
+
*
|
|
185
|
+
* This function is useful for ensuring that URLs are properly formatted
|
|
186
|
+
* without a trailing slash, which is often required in web development for
|
|
187
|
+
* consistency and to avoid issues with relative paths.
|
|
188
|
+
*
|
|
189
|
+
* @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
|
|
190
|
+
* @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
|
|
191
|
+
*
|
|
192
|
+
* @see https://radashi.js.org/reference/url/withoutTrailingSlash
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* withoutTrailingSlash('') // => ''
|
|
197
|
+
* withoutTrailingSlash('/') // => ''
|
|
198
|
+
* withoutTrailingSlash('no/slash/') // => 'no/slash'
|
|
199
|
+
* withoutTrailingSlash('already/has/slash') // => 'already/has/slash'
|
|
200
|
+
* withoutTrailingSlash(undefined) // => undefined
|
|
201
|
+
* withoutTrailingSlash(null) // => null
|
|
202
|
+
* ```
|
|
203
|
+
* @since 1.0.0
|
|
204
|
+
*/
|
|
23
205
|
function withoutTrailingSlash(url) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return url[url.length - 1] === "/" ? url.slice(0, -1) : url;
|
|
206
|
+
if (url === void 0 || url === null) return url;
|
|
207
|
+
return url.replace(/\/+$/, "");
|
|
28
208
|
}
|
|
29
|
-
|
|
30
|
-
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region helpers/url/withLeadingSlash.ts
|
|
211
|
+
/**
|
|
212
|
+
* Adds a leading slash `/` to the given URL if it is not already present.
|
|
213
|
+
*
|
|
214
|
+
* This function is useful for ensuring that URLs are properly formatted
|
|
215
|
+
* with a leading slash, which is often required in web development for
|
|
216
|
+
* consistency and to avoid issues with relative paths.
|
|
217
|
+
*
|
|
218
|
+
* @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
|
|
219
|
+
* @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
|
|
220
|
+
*
|
|
221
|
+
* @see https://radashi.js.org/reference/url/withLeadingSlash
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* withLeadingSlash('') // => '/'
|
|
226
|
+
* withLeadingSlash('no/slash') // => '/no/slash'
|
|
227
|
+
* withLeadingSlash('/already/has/slash') // => '/already/has/slash'
|
|
228
|
+
* withLeadingSlash(undefined) // => undefined
|
|
229
|
+
* withLeadingSlash(null) // => null
|
|
230
|
+
* ```
|
|
231
|
+
* @since 1.0.0
|
|
232
|
+
*/
|
|
31
233
|
function withLeadingSlash(url) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return url[0] === "/" ? url : "/" + url;
|
|
234
|
+
if (url === void 0 || url === null) return url;
|
|
235
|
+
return url[0] === "/" ? url : "/" + url;
|
|
36
236
|
}
|
|
37
|
-
|
|
38
|
-
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region helpers/url/relativeURLToAbsolute.ts
|
|
239
|
+
/**
|
|
240
|
+
* This file is part of helpers4.
|
|
241
|
+
* Copyright (C) 2025 baxyz
|
|
242
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
243
|
+
*/
|
|
244
|
+
/**
|
|
245
|
+
* Converts a relative URL to an absolute URL using the current document base URI.
|
|
246
|
+
* @param relativeUrl - The relative URL to convert
|
|
247
|
+
* @returns The absolute URL
|
|
248
|
+
* @since 1.0.0
|
|
249
|
+
*/
|
|
39
250
|
function relativeURLToAbsolute(relativeUrl) {
|
|
40
|
-
|
|
251
|
+
return withoutTrailingSlash(document.baseURI ?? window.location.origin) + cleanPath(withLeadingSlash(relativeUrl));
|
|
41
252
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region helpers/url/withTrailingSlash.ts
|
|
255
|
+
/**
|
|
256
|
+
* Adds a trailing slash `/` to the given URL if it is not already present.
|
|
257
|
+
*
|
|
258
|
+
* This function is useful for ensuring that URLs are properly formatted
|
|
259
|
+
* with a trailing slash, which is often required in web development for
|
|
260
|
+
* consistency and to avoid issues with relative paths.
|
|
261
|
+
*
|
|
262
|
+
* @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
|
|
263
|
+
* @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
|
|
264
|
+
*
|
|
265
|
+
* @see https://radashi.js.org/reference/url/withTrailingSlash
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* withTrailingSlash('') // => '/'
|
|
270
|
+
* withTrailingSlash('no/slash') // => 'no/slash/'
|
|
271
|
+
* withTrailingSlash('already/has/slash/') // => 'already/has/slash/'
|
|
272
|
+
* withTrailingSlash(undefined) // => undefined
|
|
273
|
+
* withTrailingSlash(null) // => null
|
|
274
|
+
* ```
|
|
275
|
+
* @since 1.0.0
|
|
276
|
+
*/
|
|
277
|
+
function withTrailingSlash(url) {
|
|
278
|
+
if (url === void 0 || url === null) return url;
|
|
279
|
+
return url[url.length - 1] === "/" ? url : url + "/";
|
|
61
280
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region helpers/url/withoutLeadingSlash.ts
|
|
283
|
+
/**
|
|
284
|
+
* Removes the leading slash `/` from the given URL if it is present.
|
|
285
|
+
*
|
|
286
|
+
* This function is useful for ensuring that URLs are properly formatted
|
|
287
|
+
* without a leading slash, which is often required in web development for
|
|
288
|
+
* consistency and to avoid issues with relative paths.
|
|
289
|
+
*
|
|
290
|
+
* @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
|
|
291
|
+
* @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
|
|
292
|
+
*
|
|
293
|
+
* @see https://radashi.js.org/reference/url/withoutLeadingSlash
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* withoutLeadingSlash('') // => ''
|
|
298
|
+
* withoutLeadingSlash('/') // => ''
|
|
299
|
+
* withoutLeadingSlash('/no/slash') // => 'no/slash'
|
|
300
|
+
* withoutLeadingSlash('already/has/slash') // => 'already/has/slash'
|
|
301
|
+
* withoutLeadingSlash(undefined) // => undefined
|
|
302
|
+
* withoutLeadingSlash(null) // => null
|
|
303
|
+
* ```
|
|
304
|
+
* @since 1.0.0
|
|
305
|
+
*/
|
|
306
|
+
function withoutLeadingSlash(url) {
|
|
307
|
+
if (url === void 0 || url === null) return url;
|
|
308
|
+
return url[0] === "/" ? url.slice(1) : url;
|
|
69
309
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
withLeadingSlash,
|
|
75
|
-
relativeURLToAbsolute,
|
|
76
|
-
onlyPath,
|
|
77
|
-
extractPureURI,
|
|
78
|
-
cleanPath
|
|
79
|
-
};
|
|
310
|
+
//#endregion
|
|
311
|
+
export { cleanPath, extractPureURI, onlyPath, parsePackageRepository, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
|
|
312
|
+
|
|
313
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/url/cleanPath.ts","../../../helpers/url/extractPureURI.ts","../../../helpers/url/onlyPath.ts","../../../helpers/url/parsePackageRepository.ts","../../../helpers/url/withoutTrailingSlash.ts","../../../helpers/url/withLeadingSlash.ts","../../../helpers/url/relativeURLToAbsolute.ts","../../../helpers/url/withTrailingSlash.ts","../../../helpers/url/withoutLeadingSlash.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clean an URL by removing duplicate slashes.\n * The protocol part of the URL is not modified.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The cleaned URL string, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * cleanPath('/path//to///resource') // => '/path/to/resource'\n * cleanPath('http://example.com//path//to///resource') // => 'http://example.com/path/to/resource'\n * cleanPath(undefined) // => undefined\n * cleanPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function cleanPath(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url.replace(/([^:]\\/)\\/+/g, '$1')\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\n\n/**\n * Extracts the pure URI from a URL by removing query parameters and fragments.\n *\n * @param url - The URL string to process\n * @returns The URI without query parameters and fragments, or the original value if undefined/null\n * @since 1.9.0\n */\nexport function extractPureURI(url: string): string;\nexport function extractPureURI(url: undefined): undefined;\nexport function extractPureURI(url: null): null;\nexport function extractPureURI(url: string | undefined | null): string | undefined | null {\n if (url === undefined || url === null) {\n return url;\n }\n\n // Find the first occurrence of ? or #\n const queryIndex = url.indexOf('?');\n const fragmentIndex = url.indexOf('#');\n\n let cutIndex = -1;\n\n if (queryIndex !== -1 && fragmentIndex !== -1) {\n // Both exist, take the earliest one\n cutIndex = Math.min(queryIndex, fragmentIndex);\n } else if (queryIndex !== -1) {\n // Only query exists\n cutIndex = queryIndex;\n } else if (fragmentIndex !== -1) {\n // Only fragment exists\n cutIndex = fragmentIndex;\n }\n\n // If no query or fragment found, return the original string\n if (cutIndex === -1) {\n return url;\n }\n\n // Return the substring up to the first ? or #\n return url.substring(0, cutIndex);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(url: string): string\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(url: null): null\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(url: undefined): undefined\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n const [path] = url.split(/[?#]/)\n return path\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Structured representation of a parsed `repository` field from `package.json`.\n *\n * @since next\n */\nexport interface PackageRepository {\n /**\n * VCS type (e.g. `'git'`, `'svn'`).\n * Defaults to `'git'` when using shorthand string forms.\n */\n readonly type: string;\n /**\n * Hosting platform.\n * Well-known values: `'github'`, `'gitlab'`, `'bitbucket'`, `'gist'`.\n * Falls back to the raw domain (e.g. `'codeberg.org'`) for unknown hosts.\n */\n readonly host: 'github' | 'gitlab' | 'bitbucket' | 'gist' | (string & {});\n /**\n * `<owner>/<repo>` slug.\n * `undefined` for gist shorthands (`gist:<id>`) and unrecognised URL shapes.\n */\n readonly slug: string | undefined;\n /**\n * Repository owner or organisation.\n * `undefined` for gist shorthands.\n */\n readonly owner: string | undefined;\n /**\n * Repository name.\n * `undefined` for gist shorthands.\n */\n readonly repo: string | undefined;\n /**\n * Gist identifier — only set when using the `gist:<id>` shorthand form.\n */\n readonly gistId: string | undefined;\n /**\n * Monorepo sub-directory from the `directory` field of the object form.\n * `undefined` when using shorthand string forms or when no `directory` is specified.\n */\n readonly directory: string | undefined;\n}\n\n/** Maps known GitHub/GitLab/Bitbucket domains to their platform name. */\nconst DOMAIN_TO_HOST: Record<string, string> = {\n 'github.com': 'github',\n 'gitlab.com': 'gitlab',\n 'bitbucket.org': 'bitbucket',\n};\n\n/** SCP-style SSH URL: `git@github.com:owner/repo.git` */\nconst RE_SSH_SCP = /^git@([\\w.-]+):([\\w.-]+\\/[\\w.-]+?)(?:\\.git)?(?:[#?].*)?$/;\n\n/**\n * URL-form remote: `git+https://…`, `https://…`, `git://…`, `git+ssh://git@…`\n * Captures: [1] domain, [2] owner/repo path\n */\nconst RE_URL =\n /^(?:git\\+(?:https?|ssh)|https?|git):\\/\\/(?:[^@/]+@)?([\\w.-]+)\\/([\\w.-]+\\/[\\w.-]+?)(?:\\.git)?(?:[#?].*)?$/;\n\nfunction makeOwnerRepoResult(\n type: string,\n host: string,\n rawPath: string,\n directory: string | undefined,\n): PackageRepository {\n const slashIdx = rawPath.indexOf('/');\n const owner = rawPath.slice(0, slashIdx);\n const repo = rawPath.slice(slashIdx + 1);\n return { type, host, slug: `${owner}/${repo}`, owner, repo, gistId: undefined, directory };\n}\n\nfunction parseRawUrl(\n raw: string,\n type: string,\n directory: string | undefined,\n): PackageRepository | undefined {\n // Shorthand prefix: \"github:owner/repo\", \"gitlab:owner/repo\", \"bitbucket:owner/repo\"\n const shorthandMatch = /^(github|gitlab|bitbucket):([\\w.-]+\\/[\\w.-]+)$/.exec(raw);\n if (shorthandMatch) {\n const host = shorthandMatch[1] as 'github' | 'gitlab' | 'bitbucket';\n const slug = shorthandMatch[2];\n const slashIdx = slug.indexOf('/');\n const owner = slug.slice(0, slashIdx);\n const repo = slug.slice(slashIdx + 1);\n return { type, host, slug, owner, repo, gistId: undefined, directory };\n }\n\n // Gist shorthand: \"gist:<id>\"\n const gistMatch = /^gist:([\\w-]+)$/.exec(raw);\n if (gistMatch) {\n return { type, host: 'gist', slug: undefined, owner: undefined, repo: undefined, gistId: gistMatch[1], directory };\n }\n\n // Bare GitHub shorthand: \"owner/repo\" (no colon prefix, no protocol)\n const bareMatch = /^([\\w.-]+)\\/([\\w.-]+)$/.exec(raw);\n if (bareMatch) {\n const owner = bareMatch[1];\n const repo = bareMatch[2];\n return { type, host: 'github', slug: `${owner}/${repo}`, owner, repo, gistId: undefined, directory };\n }\n\n // SCP-style SSH: git@github.com:owner/repo.git\n const sshMatch = RE_SSH_SCP.exec(raw);\n if (sshMatch) {\n const host = DOMAIN_TO_HOST[sshMatch[1]] ?? sshMatch[1];\n return makeOwnerRepoResult(type, host, sshMatch[2], directory);\n }\n\n // URL-form: https://, git+https://, git://, git+ssh://\n const urlMatch = RE_URL.exec(raw);\n if (urlMatch) {\n const host = DOMAIN_TO_HOST[urlMatch[1]] ?? urlMatch[1];\n return makeOwnerRepoResult(type, host, urlMatch[2], directory);\n }\n\n return undefined;\n}\n\n/**\n * Parse the `repository` field from `package.json` into a structured object.\n *\n * Supports all npm-specified formats:\n * - **Object form**: `{ \"type\": \"git\", \"url\": \"...\", \"directory\": \"...\" }`\n * - **GitHub shorthand**: `\"owner/repo\"` or `\"github:owner/repo\"`\n * - **Platform shorthands**: `\"gitlab:owner/repo\"`, `\"bitbucket:owner/repo\"`\n * - **Gist shorthand**: `\"gist:<id>\"`\n * - **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`\n *\n * Returns `undefined` for `null`, `undefined`, arrays, or values that cannot\n * be matched to any recognised format.\n *\n * @param repository - The `repository` field value from `package.json`.\n * @returns A parsed {@link PackageRepository} object, or `undefined` if the\n * input cannot be parsed.\n * @example\n * parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })\n * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',\n * // repo: 'typescript', gistId: undefined, directory: undefined }\n * @example\n * parsePackageRepository('github:helpers4/typescript')\n * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',\n * // repo: 'typescript', gistId: undefined, directory: undefined }\n * @since next\n */\nexport function parsePackageRepository(repository: unknown): PackageRepository | undefined {\n if (repository === null || repository === undefined) return undefined;\n\n if (typeof repository === 'string') {\n return parseRawUrl(repository, 'git', undefined);\n }\n\n if (typeof repository === 'object' && !Array.isArray(repository)) {\n const obj = repository as Record<string, unknown>;\n const rawUrl = obj['url'];\n if (typeof rawUrl !== 'string') return undefined;\n const type = typeof obj['type'] === 'string' ? (obj['type'] as string) : 'git';\n const directory = typeof obj['directory'] === 'string' ? (obj['directory'] as string) : undefined;\n return parseRawUrl(rawUrl, type, directory);\n }\n\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(url: string): string\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(url: undefined): undefined\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(url: null): null\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url.replace(/\\/+$/, '')\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: string): string\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: undefined): undefined\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: null): null\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[0] === '/' ? url : '/' + url\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\n\nimport { withoutTrailingSlash } from \"./withoutTrailingSlash\";\nimport { withLeadingSlash } from \"./withLeadingSlash\";\nimport { cleanPath } from \"./cleanPath\";\n\n/**\n * Converts a relative URL to an absolute URL using the current document base URI.\n * @param relativeUrl - The relative URL to convert\n * @returns The absolute URL\n * @since 1.0.0\n */\nexport function relativeURLToAbsolute(relativeUrl: string): string {\n return (\n withoutTrailingSlash(document.baseURI ?? window.location.origin) +\n cleanPath(withLeadingSlash(relativeUrl))\n );\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: string): string\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: undefined): undefined\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: null): null\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[url.length - 1] === '/' ? url : url + '/'\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: string): string\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: undefined): undefined\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: null): null\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[0] === '/' ? url.slice(1) : url\n}\n"],"mappings":"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"}
|