@helpers4/url 1.0.1 → 2.0.0-alpha.10

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/lib/index.js ADDED
@@ -0,0 +1,203 @@
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");
26
+ }
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);
39
+ }
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/withoutTrailingSlash.ts
72
+ /**
73
+ * Removes the trailing slash `/` from the given URL if it is present.
74
+ *
75
+ * This function is useful for ensuring that URLs are properly formatted
76
+ * without a trailing slash, which is often required in web development for
77
+ * consistency and to avoid issues with relative paths.
78
+ *
79
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
80
+ * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
81
+ *
82
+ * @see https://radashi.js.org/reference/url/withoutTrailingSlash
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * withoutTrailingSlash('') // => ''
87
+ * withoutTrailingSlash('/') // => ''
88
+ * withoutTrailingSlash('no/slash/') // => 'no/slash'
89
+ * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'
90
+ * withoutTrailingSlash(undefined) // => undefined
91
+ * withoutTrailingSlash(null) // => null
92
+ * ```
93
+ * @since 1.0.0
94
+ */
95
+ function withoutTrailingSlash(url) {
96
+ if (url === void 0 || url === null) return url;
97
+ return url[url.length - 1] === "/" ? url.slice(0, -1) : url;
98
+ }
99
+ //#endregion
100
+ //#region helpers/url/withLeadingSlash.ts
101
+ /**
102
+ * Adds a leading slash `/` to the given URL if it is not already present.
103
+ *
104
+ * This function is useful for ensuring that URLs are properly formatted
105
+ * with a leading slash, which is often required in web development for
106
+ * consistency and to avoid issues with relative paths.
107
+ *
108
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
109
+ * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
110
+ *
111
+ * @see https://radashi.js.org/reference/url/withLeadingSlash
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * withLeadingSlash('') // => '/'
116
+ * withLeadingSlash('no/slash') // => '/no/slash'
117
+ * withLeadingSlash('/already/has/slash') // => '/already/has/slash'
118
+ * withLeadingSlash(undefined) // => undefined
119
+ * withLeadingSlash(null) // => null
120
+ * ```
121
+ * @since 1.0.0
122
+ */
123
+ function withLeadingSlash(url) {
124
+ if (url === void 0 || url === null) return url;
125
+ return url[0] === "/" ? url : "/" + url;
126
+ }
127
+ //#endregion
128
+ //#region helpers/url/relativeURLToAbsolute.ts
129
+ /**
130
+ * This file is part of helpers4.
131
+ * Copyright (C) 2025 baxyz
132
+ * SPDX-License-Identifier: LGPL-3.0-or-later
133
+ */
134
+ /**
135
+ * Converts a relative URL to an absolute URL using the current document base URI.
136
+ * @param relativeUrl - The relative URL to convert
137
+ * @returns The absolute URL
138
+ * @since 1.0.0
139
+ */
140
+ function relativeURLToAbsolute(relativeUrl) {
141
+ return withoutTrailingSlash(document.baseURI ?? window.location.origin) + cleanPath(withLeadingSlash(relativeUrl));
142
+ }
143
+ //#endregion
144
+ //#region helpers/url/withTrailingSlash.ts
145
+ /**
146
+ * Adds a trailing slash `/` to the given URL if it is not already present.
147
+ *
148
+ * This function is useful for ensuring that URLs are properly formatted
149
+ * with a trailing slash, which is often required in web development for
150
+ * consistency and to avoid issues with relative paths.
151
+ *
152
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
153
+ * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
154
+ *
155
+ * @see https://radashi.js.org/reference/url/withTrailingSlash
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * withTrailingSlash('') // => '/'
160
+ * withTrailingSlash('no/slash') // => 'no/slash/'
161
+ * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'
162
+ * withTrailingSlash(undefined) // => undefined
163
+ * withTrailingSlash(null) // => null
164
+ * ```
165
+ * @since 1.0.0
166
+ */
167
+ function withTrailingSlash(url) {
168
+ if (url === void 0 || url === null) return url;
169
+ return url[url.length - 1] === "/" ? url : url + "/";
170
+ }
171
+ //#endregion
172
+ //#region helpers/url/withoutLeadingSlash.ts
173
+ /**
174
+ * Removes the leading slash `/` from the given URL if it is present.
175
+ *
176
+ * This function is useful for ensuring that URLs are properly formatted
177
+ * without a leading slash, which is often required in web development for
178
+ * consistency and to avoid issues with relative paths.
179
+ *
180
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
181
+ * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
182
+ *
183
+ * @see https://radashi.js.org/reference/url/withoutLeadingSlash
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * withoutLeadingSlash('') // => ''
188
+ * withoutLeadingSlash('/') // => ''
189
+ * withoutLeadingSlash('/no/slash') // => 'no/slash'
190
+ * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'
191
+ * withoutLeadingSlash(undefined) // => undefined
192
+ * withoutLeadingSlash(null) // => null
193
+ * ```
194
+ * @since 1.0.0
195
+ */
196
+ function withoutLeadingSlash(url) {
197
+ if (url === void 0 || url === null) return url;
198
+ return url[0] === "/" ? url.slice(1) : url;
199
+ }
200
+ //#endregion
201
+ export { cleanPath, extractPureURI, onlyPath, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
202
+
203
+ //# sourceMappingURL=index.js.map
@@ -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/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 * 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[url.length - 1] === '/' ? url.slice(0, -1) : 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 * 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":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,UACd,KAC2B;AAC3B,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;AAET,QAAO,IAAI,QAAQ,gBAAgB,KAAK;;;;ACP1C,SAAgB,eAAe,KAA2D;AACxF,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;CAIT,MAAM,aAAa,IAAI,QAAQ,IAAI;CACnC,MAAM,gBAAgB,IAAI,QAAQ,IAAI;CAEtC,IAAI,WAAW;AAEf,KAAI,eAAe,MAAM,kBAAkB,GAEzC,YAAW,KAAK,IAAI,YAAY,cAAc;UACrC,eAAe,GAExB,YAAW;UACF,kBAAkB,GAE3B,YAAW;AAIb,KAAI,aAAa,GACf,QAAO;AAIT,QAAO,IAAI,UAAU,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;ACuDnC,SAAgB,SACd,KAC2B;AAC3B,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;CAET,MAAM,CAAC,QAAQ,IAAI,MAAM,OAAO;AAChC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;ACPT,SAAgB,qBACd,KAC2B;AAC3B,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;AAET,QAAO,IAAI,IAAI,SAAS,OAAO,MAAM,IAAI,MAAM,GAAG,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;ACV1D,SAAgB,iBACd,KAC2B;AAC3B,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;AAET,QAAO,IAAI,OAAO,MAAM,MAAM,MAAM;;;;;;;;;;;;;;;ACrFtC,SAAgB,sBAAsB,aAA6B;AAC/D,QACI,qBAAqB,SAAS,WAAW,OAAO,SAAS,OAAO,GAChE,UAAU,iBAAiB,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;AC4EhD,SAAgB,kBACd,KAC2B;AAC3B,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;AAET,QAAO,IAAI,IAAI,SAAS,OAAO,MAAM,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;ACFnD,SAAgB,oBACd,KAC2B;AAC3B,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;AAET,QAAO,IAAI,OAAO,MAAM,IAAI,MAAM,EAAE,GAAG"}