@helpers4/url 2.0.0-alpha.7 → 2.0.0-alpha.9

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.d.ts CHANGED
@@ -17,6 +17,7 @@
17
17
  * cleanPath(undefined) // => undefined
18
18
  * cleanPath(null) // => null
19
19
  * ```
20
+ * @since 1.0.0
20
21
  */
21
22
  declare function cleanPath(url: string | undefined | null): string | undefined | null;
22
23
 
@@ -30,6 +31,7 @@ declare function cleanPath(url: string | undefined | null): string | undefined |
30
31
  *
31
32
  * @param url - The URL string to process
32
33
  * @returns The URI without query parameters and fragments, or the original value if undefined/null
34
+ * @since 1.9.0
33
35
  */
34
36
  declare function extractPureURI(url: string): string;
35
37
  declare function extractPureURI(url: undefined): undefined;
@@ -61,6 +63,7 @@ declare function extractPureURI(url: null): null;
61
63
  * onlyPath(undefined) // => undefined
62
64
  * onlyPath(null) // => null
63
65
  * ```
66
+ * @since 1.0.0
64
67
  */
65
68
  declare function onlyPath(url: string): string;
66
69
  /**
@@ -84,6 +87,7 @@ declare function onlyPath(url: string): string;
84
87
  * onlyPath(undefined) // => undefined
85
88
  * onlyPath(null) // => null
86
89
  * ```
90
+ * @since 1.0.0
87
91
  */
88
92
  declare function onlyPath(url: null): null;
89
93
  /**
@@ -107,6 +111,7 @@ declare function onlyPath(url: null): null;
107
111
  * onlyPath(undefined) // => undefined
108
112
  * onlyPath(null) // => null
109
113
  * ```
114
+ * @since 1.0.0
110
115
  */
111
116
  declare function onlyPath(url: undefined): undefined;
112
117
 
@@ -115,6 +120,12 @@ declare function onlyPath(url: undefined): undefined;
115
120
  * Copyright (C) 2025 baxyz
116
121
  * SPDX-License-Identifier: LGPL-3.0-or-later
117
122
  */
123
+ /**
124
+ * Converts a relative URL to an absolute URL using the current document base URI.
125
+ * @param relativeUrl - The relative URL to convert
126
+ * @returns The absolute URL
127
+ * @since 1.0.0
128
+ */
118
129
  declare function relativeURLToAbsolute(relativeUrl: string): string;
119
130
 
120
131
  /**
@@ -142,6 +153,7 @@ declare function relativeURLToAbsolute(relativeUrl: string): string;
142
153
  * withLeadingSlash(undefined) // => undefined
143
154
  * withLeadingSlash(null) // => null
144
155
  * ```
156
+ * @since 1.0.0
145
157
  */
146
158
  declare function withLeadingSlash(url: string): string;
147
159
  /**
@@ -164,6 +176,7 @@ declare function withLeadingSlash(url: string): string;
164
176
  * withLeadingSlash(undefined) // => undefined
165
177
  * withLeadingSlash(null) // => null
166
178
  * ```
179
+ * @since 1.0.0
167
180
  */
168
181
  declare function withLeadingSlash(url: undefined): undefined;
169
182
  /**
@@ -186,6 +199,7 @@ declare function withLeadingSlash(url: undefined): undefined;
186
199
  * withLeadingSlash(undefined) // => undefined
187
200
  * withLeadingSlash(null) // => null
188
201
  * ```
202
+ * @since 1.0.0
189
203
  */
190
204
  declare function withLeadingSlash(url: null): null;
191
205
 
@@ -214,6 +228,7 @@ declare function withLeadingSlash(url: null): null;
214
228
  * withTrailingSlash(undefined) // => undefined
215
229
  * withTrailingSlash(null) // => null
216
230
  * ```
231
+ * @since 1.0.0
217
232
  */
218
233
  declare function withTrailingSlash(url: string): string;
219
234
  /**
@@ -236,6 +251,7 @@ declare function withTrailingSlash(url: string): string;
236
251
  * withTrailingSlash(undefined) // => undefined
237
252
  * withTrailingSlash(null) // => null
238
253
  * ```
254
+ * @since 1.0.0
239
255
  */
240
256
  declare function withTrailingSlash(url: undefined): undefined;
241
257
  /**
@@ -258,6 +274,7 @@ declare function withTrailingSlash(url: undefined): undefined;
258
274
  * withTrailingSlash(undefined) // => undefined
259
275
  * withTrailingSlash(null) // => null
260
276
  * ```
277
+ * @since 1.0.0
261
278
  */
262
279
  declare function withTrailingSlash(url: null): null;
263
280
 
@@ -287,6 +304,7 @@ declare function withTrailingSlash(url: null): null;
287
304
  * withoutLeadingSlash(undefined) // => undefined
288
305
  * withoutLeadingSlash(null) // => null
289
306
  * ```
307
+ * @since 1.0.0
290
308
  */
291
309
  declare function withoutLeadingSlash(url: string): string;
292
310
  /**
@@ -310,6 +328,7 @@ declare function withoutLeadingSlash(url: string): string;
310
328
  * withoutLeadingSlash(undefined) // => undefined
311
329
  * withoutLeadingSlash(null) // => null
312
330
  * ```
331
+ * @since 1.0.0
313
332
  */
314
333
  declare function withoutLeadingSlash(url: undefined): undefined;
315
334
  /**
@@ -333,6 +352,7 @@ declare function withoutLeadingSlash(url: undefined): undefined;
333
352
  * withoutLeadingSlash(undefined) // => undefined
334
353
  * withoutLeadingSlash(null) // => null
335
354
  * ```
355
+ * @since 1.0.0
336
356
  */
337
357
  declare function withoutLeadingSlash(url: null): null;
338
358
 
@@ -362,6 +382,7 @@ declare function withoutLeadingSlash(url: null): null;
362
382
  * withoutTrailingSlash(undefined) // => undefined
363
383
  * withoutTrailingSlash(null) // => null
364
384
  * ```
385
+ * @since 1.0.0
365
386
  */
366
387
  declare function withoutTrailingSlash(url: string): string;
367
388
  /**
@@ -385,6 +406,7 @@ declare function withoutTrailingSlash(url: string): string;
385
406
  * withoutTrailingSlash(undefined) // => undefined
386
407
  * withoutTrailingSlash(null) // => null
387
408
  * ```
409
+ * @since 1.0.0
388
410
  */
389
411
  declare function withoutTrailingSlash(url: undefined): undefined;
390
412
  /**
@@ -408,6 +430,7 @@ declare function withoutTrailingSlash(url: undefined): undefined;
408
430
  * withoutTrailingSlash(undefined) // => undefined
409
431
  * withoutTrailingSlash(null) // => null
410
432
  * ```
433
+ * @since 1.0.0
411
434
  */
412
435
  declare function withoutTrailingSlash(url: null): null;
413
436
 
package/lib/index.js CHANGED
@@ -18,6 +18,7 @@
18
18
  * cleanPath(undefined) // => undefined
19
19
  * cleanPath(null) // => null
20
20
  * ```
21
+ * @since 1.0.0
21
22
  */
22
23
  function cleanPath(url) {
23
24
  if (url === void 0 || url === null) return url;
@@ -59,6 +60,7 @@ function extractPureURI(url) {
59
60
  * onlyPath(undefined) // => undefined
60
61
  * onlyPath(null) // => null
61
62
  * ```
63
+ * @since 1.0.0
62
64
  */
63
65
  function onlyPath(url) {
64
66
  if (url === void 0 || url === null) return url;
@@ -88,6 +90,7 @@ function onlyPath(url) {
88
90
  * withoutTrailingSlash(undefined) // => undefined
89
91
  * withoutTrailingSlash(null) // => null
90
92
  * ```
93
+ * @since 1.0.0
91
94
  */
92
95
  function withoutTrailingSlash(url) {
93
96
  if (url === void 0 || url === null) return url;
@@ -115,6 +118,7 @@ function withoutTrailingSlash(url) {
115
118
  * withLeadingSlash(undefined) // => undefined
116
119
  * withLeadingSlash(null) // => null
117
120
  * ```
121
+ * @since 1.0.0
118
122
  */
119
123
  function withLeadingSlash(url) {
120
124
  if (url === void 0 || url === null) return url;
@@ -127,6 +131,12 @@ function withLeadingSlash(url) {
127
131
  * Copyright (C) 2025 baxyz
128
132
  * SPDX-License-Identifier: LGPL-3.0-or-later
129
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
+ */
130
140
  function relativeURLToAbsolute(relativeUrl) {
131
141
  return withoutTrailingSlash(document.baseURI ?? window.location.origin) + cleanPath(withLeadingSlash(relativeUrl));
132
142
  }
@@ -152,6 +162,7 @@ function relativeURLToAbsolute(relativeUrl) {
152
162
  * withTrailingSlash(undefined) // => undefined
153
163
  * withTrailingSlash(null) // => null
154
164
  * ```
165
+ * @since 1.0.0
155
166
  */
156
167
  function withTrailingSlash(url) {
157
168
  if (url === void 0 || url === null) return url;
@@ -180,6 +191,7 @@ function withTrailingSlash(url) {
180
191
  * withoutLeadingSlash(undefined) // => undefined
181
192
  * withoutLeadingSlash(null) // => null
182
193
  * ```
194
+ * @since 1.0.0
183
195
  */
184
196
  function withoutLeadingSlash(url) {
185
197
  if (url === void 0 || url === null) return url;
package/lib/index.js.map CHANGED
@@ -1 +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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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 */\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":";;;;;;;;;;;;;;;;;;;;;AAqBA,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;;;;;;;;;;;;;;;;;;;;;;;;;;ACoDnC,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;;;;;;;;;ACvFtC,SAAgB,sBAAsB,aAA6B;AAC/D,QACI,qBAAqB,SAAS,WAAW,OAAO,SAAS,OAAO,GAChE,UAAU,iBAAiB,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AC8EhD,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"}
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"}
package/meta/api.json ADDED
@@ -0,0 +1,449 @@
1
+ {
2
+ "category": "url",
3
+ "version": "2.0.0-alpha.9",
4
+ "functions": [
5
+ {
6
+ "name": "cleanPath",
7
+ "kind": "function",
8
+ "description": "Clean an URL by removing duplicate slashes.\nThe protocol part of the URL is not modified.",
9
+ "since": "1.0.0",
10
+ "signatures": [
11
+ {
12
+ "signature": "cleanPath(url: string | null | undefined): string | null | undefined",
13
+ "description": "Clean an URL by removing duplicate slashes.\nThe protocol part of the URL is not modified.",
14
+ "params": [
15
+ {
16
+ "name": "url",
17
+ "type": "string | null | undefined",
18
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
19
+ }
20
+ ],
21
+ "returns": {
22
+ "type": "string | null | undefined",
23
+ "description": "The cleaned URL string, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
24
+ }
25
+ }
26
+ ],
27
+ "examples": [
28
+ {
29
+ "title": "Remove duplicate slashes",
30
+ "description": "Cleans an URL by removing duplicate slashes while preserving the protocol.",
31
+ "code": "cleanPath('/path//to///resource')\n// => '/path/to/resource'"
32
+ },
33
+ {
34
+ "title": "Preserve protocol",
35
+ "description": "The double slash after the protocol (http://) is not modified.",
36
+ "code": "cleanPath('http://example.com//path')\n// => 'http://example.com/path'"
37
+ },
38
+ {
39
+ "title": "Handle null and undefined",
40
+ "description": "Returns null for null input and undefined for undefined input.",
41
+ "code": "cleanPath(null) // => null\ncleanPath(undefined) // => undefined"
42
+ }
43
+ ],
44
+ "sourceFile": "cleanPath.ts"
45
+ },
46
+ {
47
+ "name": "extractPureURI",
48
+ "kind": "function",
49
+ "description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
50
+ "since": "1.9.0",
51
+ "signatures": [
52
+ {
53
+ "signature": "extractPureURI(url: string): string",
54
+ "description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
55
+ "params": [
56
+ {
57
+ "name": "url",
58
+ "type": "string",
59
+ "description": "The URL string to process"
60
+ }
61
+ ],
62
+ "returns": {
63
+ "type": "string",
64
+ "description": "The URI without query parameters and fragments, or the original value if undefined/null"
65
+ }
66
+ },
67
+ {
68
+ "signature": "extractPureURI(url: undefined): undefined",
69
+ "description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
70
+ "params": [
71
+ {
72
+ "name": "url",
73
+ "type": "undefined",
74
+ "description": "The URL string to process"
75
+ }
76
+ ],
77
+ "returns": {
78
+ "type": "undefined",
79
+ "description": "The URI without query parameters and fragments, or the original value if undefined/null"
80
+ }
81
+ },
82
+ {
83
+ "signature": "extractPureURI(url: null): null",
84
+ "description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
85
+ "params": [
86
+ {
87
+ "name": "url",
88
+ "type": "null",
89
+ "description": "The URL string to process"
90
+ }
91
+ ],
92
+ "returns": {
93
+ "type": "null",
94
+ "description": "The URI without query parameters and fragments, or the original value if undefined/null"
95
+ }
96
+ }
97
+ ],
98
+ "examples": [
99
+ {
100
+ "title": "Remove query parameters and fragments",
101
+ "description": "Strips everything after ? or # from the URL.",
102
+ "code": "extractPureURI('https://example.com/path?query=1#section')\n// => 'https://example.com/path'"
103
+ }
104
+ ],
105
+ "sourceFile": "extractPureURI.ts"
106
+ },
107
+ {
108
+ "name": "onlyPath",
109
+ "kind": "function",
110
+ "description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
111
+ "since": "1.0.0",
112
+ "signatures": [
113
+ {
114
+ "signature": "onlyPath(url: string): string",
115
+ "description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
116
+ "params": [
117
+ {
118
+ "name": "url",
119
+ "type": "string",
120
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
121
+ }
122
+ ],
123
+ "returns": {
124
+ "type": "string",
125
+ "description": "The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
126
+ }
127
+ },
128
+ {
129
+ "signature": "onlyPath(url: null): null",
130
+ "description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
131
+ "params": [
132
+ {
133
+ "name": "url",
134
+ "type": "null",
135
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
136
+ }
137
+ ],
138
+ "returns": {
139
+ "type": "null",
140
+ "description": "The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
141
+ }
142
+ },
143
+ {
144
+ "signature": "onlyPath(url: undefined): undefined",
145
+ "description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
146
+ "params": [
147
+ {
148
+ "name": "url",
149
+ "type": "undefined",
150
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
151
+ }
152
+ ],
153
+ "returns": {
154
+ "type": "undefined",
155
+ "description": "The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
156
+ }
157
+ }
158
+ ],
159
+ "examples": [
160
+ {
161
+ "title": "Extract the path from a URL",
162
+ "description": "Strips query parameters and fragments from a URL path.",
163
+ "code": "onlyPath('/path?query=thing#fragment')\n// => '/path'"
164
+ }
165
+ ],
166
+ "sourceFile": "onlyPath.ts"
167
+ },
168
+ {
169
+ "name": "relativeURLToAbsolute",
170
+ "kind": "function",
171
+ "description": "Converts a relative URL to an absolute URL using the current document base URI.",
172
+ "since": "1.0.0",
173
+ "signatures": [
174
+ {
175
+ "signature": "relativeURLToAbsolute(relativeUrl: string): string",
176
+ "description": "Converts a relative URL to an absolute URL using the current document base URI.",
177
+ "params": [
178
+ {
179
+ "name": "relativeUrl",
180
+ "type": "string",
181
+ "description": "The relative URL to convert"
182
+ }
183
+ ],
184
+ "returns": {
185
+ "type": "string",
186
+ "description": "The absolute URL"
187
+ }
188
+ }
189
+ ],
190
+ "examples": [
191
+ {
192
+ "title": "Convert a relative URL to absolute",
193
+ "description": "Prepends the base URI to a relative path, cleaning duplicate slashes.",
194
+ "code": "relativeURLToAbsolute('/api/data')\n// => 'http://localhost/api/data' (depends on document.baseURI)"
195
+ }
196
+ ],
197
+ "sourceFile": "relativeURLToAbsolute.ts"
198
+ },
199
+ {
200
+ "name": "withLeadingSlash",
201
+ "kind": "function",
202
+ "description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
203
+ "since": "1.0.0",
204
+ "signatures": [
205
+ {
206
+ "signature": "withLeadingSlash(url: string): string",
207
+ "description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
208
+ "params": [
209
+ {
210
+ "name": "url",
211
+ "type": "string",
212
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
213
+ }
214
+ ],
215
+ "returns": {
216
+ "type": "string",
217
+ "description": "The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
218
+ }
219
+ },
220
+ {
221
+ "signature": "withLeadingSlash(url: undefined): undefined",
222
+ "description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
223
+ "params": [
224
+ {
225
+ "name": "url",
226
+ "type": "undefined",
227
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
228
+ }
229
+ ],
230
+ "returns": {
231
+ "type": "undefined",
232
+ "description": "The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
233
+ }
234
+ },
235
+ {
236
+ "signature": "withLeadingSlash(url: null): null",
237
+ "description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
238
+ "params": [
239
+ {
240
+ "name": "url",
241
+ "type": "null",
242
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
243
+ }
244
+ ],
245
+ "returns": {
246
+ "type": "null",
247
+ "description": "The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
248
+ }
249
+ }
250
+ ],
251
+ "examples": [
252
+ {
253
+ "title": "Add a leading slash",
254
+ "description": "Ensures the URL starts with a forward slash.",
255
+ "code": "withLeadingSlash('path/to/resource')\n// => '/path/to/resource'"
256
+ },
257
+ {
258
+ "title": "Already has leading slash",
259
+ "description": "Does not add a duplicate slash.",
260
+ "code": "withLeadingSlash('/already/has/slash')\n// => '/already/has/slash'"
261
+ }
262
+ ],
263
+ "sourceFile": "withLeadingSlash.ts"
264
+ },
265
+ {
266
+ "name": "withoutLeadingSlash",
267
+ "kind": "function",
268
+ "description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
269
+ "since": "1.0.0",
270
+ "signatures": [
271
+ {
272
+ "signature": "withoutLeadingSlash(url: string): string",
273
+ "description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
274
+ "params": [
275
+ {
276
+ "name": "url",
277
+ "type": "string",
278
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
279
+ }
280
+ ],
281
+ "returns": {
282
+ "type": "string",
283
+ "description": "The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
284
+ }
285
+ },
286
+ {
287
+ "signature": "withoutLeadingSlash(url: undefined): undefined",
288
+ "description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
289
+ "params": [
290
+ {
291
+ "name": "url",
292
+ "type": "undefined",
293
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
294
+ }
295
+ ],
296
+ "returns": {
297
+ "type": "undefined",
298
+ "description": "The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
299
+ }
300
+ },
301
+ {
302
+ "signature": "withoutLeadingSlash(url: null): null",
303
+ "description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
304
+ "params": [
305
+ {
306
+ "name": "url",
307
+ "type": "null",
308
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
309
+ }
310
+ ],
311
+ "returns": {
312
+ "type": "null",
313
+ "description": "The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
314
+ }
315
+ }
316
+ ],
317
+ "examples": [
318
+ {
319
+ "title": "Remove leading slash",
320
+ "description": "Strips the leading slash from a URL path.",
321
+ "code": "withoutLeadingSlash('/path/to/resource')\n// => 'path/to/resource'"
322
+ }
323
+ ],
324
+ "sourceFile": "withoutLeadingSlash.ts"
325
+ },
326
+ {
327
+ "name": "withoutTrailingSlash",
328
+ "kind": "function",
329
+ "description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
330
+ "since": "1.0.0",
331
+ "signatures": [
332
+ {
333
+ "signature": "withoutTrailingSlash(url: string): string",
334
+ "description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
335
+ "params": [
336
+ {
337
+ "name": "url",
338
+ "type": "string",
339
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
340
+ }
341
+ ],
342
+ "returns": {
343
+ "type": "string",
344
+ "description": "The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
345
+ }
346
+ },
347
+ {
348
+ "signature": "withoutTrailingSlash(url: undefined): undefined",
349
+ "description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
350
+ "params": [
351
+ {
352
+ "name": "url",
353
+ "type": "undefined",
354
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
355
+ }
356
+ ],
357
+ "returns": {
358
+ "type": "undefined",
359
+ "description": "The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
360
+ }
361
+ },
362
+ {
363
+ "signature": "withoutTrailingSlash(url: null): null",
364
+ "description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
365
+ "params": [
366
+ {
367
+ "name": "url",
368
+ "type": "null",
369
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
370
+ }
371
+ ],
372
+ "returns": {
373
+ "type": "null",
374
+ "description": "The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
375
+ }
376
+ }
377
+ ],
378
+ "examples": [
379
+ {
380
+ "title": "Remove trailing slash",
381
+ "description": "Strips the trailing slash from a URL path.",
382
+ "code": "withoutTrailingSlash('path/to/resource/')\n// => 'path/to/resource'"
383
+ }
384
+ ],
385
+ "sourceFile": "withoutTrailingSlash.ts"
386
+ },
387
+ {
388
+ "name": "withTrailingSlash",
389
+ "kind": "function",
390
+ "description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
391
+ "since": "1.0.0",
392
+ "signatures": [
393
+ {
394
+ "signature": "withTrailingSlash(url: string): string",
395
+ "description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
396
+ "params": [
397
+ {
398
+ "name": "url",
399
+ "type": "string",
400
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
401
+ }
402
+ ],
403
+ "returns": {
404
+ "type": "string",
405
+ "description": "The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
406
+ }
407
+ },
408
+ {
409
+ "signature": "withTrailingSlash(url: undefined): undefined",
410
+ "description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
411
+ "params": [
412
+ {
413
+ "name": "url",
414
+ "type": "undefined",
415
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
416
+ }
417
+ ],
418
+ "returns": {
419
+ "type": "undefined",
420
+ "description": "The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
421
+ }
422
+ },
423
+ {
424
+ "signature": "withTrailingSlash(url: null): null",
425
+ "description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
426
+ "params": [
427
+ {
428
+ "name": "url",
429
+ "type": "null",
430
+ "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
431
+ }
432
+ ],
433
+ "returns": {
434
+ "type": "null",
435
+ "description": "The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
436
+ }
437
+ }
438
+ ],
439
+ "examples": [
440
+ {
441
+ "title": "Add a trailing slash",
442
+ "description": "Ensures the URL ends with a forward slash.",
443
+ "code": "withTrailingSlash('path/to/resource')\n// => 'path/to/resource/'"
444
+ }
445
+ ],
446
+ "sourceFile": "withTrailingSlash.ts"
447
+ }
448
+ ]
449
+ }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "category": "url",
3
- "helpers": [
3
+ "functions": [
4
4
  {
5
- "helper": "cleanPath",
5
+ "name": "cleanPath",
6
6
  "examples": [
7
7
  {
8
8
  "title": "Remove duplicate slashes",
@@ -22,7 +22,7 @@
22
22
  ]
23
23
  },
24
24
  {
25
- "helper": "extractPureURI",
25
+ "name": "extractPureURI",
26
26
  "examples": [
27
27
  {
28
28
  "title": "Remove query parameters and fragments",
@@ -32,7 +32,7 @@
32
32
  ]
33
33
  },
34
34
  {
35
- "helper": "onlyPath",
35
+ "name": "onlyPath",
36
36
  "examples": [
37
37
  {
38
38
  "title": "Extract the path from a URL",
@@ -42,7 +42,7 @@
42
42
  ]
43
43
  },
44
44
  {
45
- "helper": "relativeURLToAbsolute",
45
+ "name": "relativeURLToAbsolute",
46
46
  "examples": [
47
47
  {
48
48
  "title": "Convert a relative URL to absolute",
@@ -52,7 +52,7 @@
52
52
  ]
53
53
  },
54
54
  {
55
- "helper": "withLeadingSlash",
55
+ "name": "withLeadingSlash",
56
56
  "examples": [
57
57
  {
58
58
  "title": "Add a leading slash",
@@ -67,17 +67,7 @@
67
67
  ]
68
68
  },
69
69
  {
70
- "helper": "withTrailingSlash",
71
- "examples": [
72
- {
73
- "title": "Add a trailing slash",
74
- "description": "Ensures the URL ends with a forward slash.",
75
- "code": "withTrailingSlash('path/to/resource')\n// => 'path/to/resource/'"
76
- }
77
- ]
78
- },
79
- {
80
- "helper": "withoutLeadingSlash",
70
+ "name": "withoutLeadingSlash",
81
71
  "examples": [
82
72
  {
83
73
  "title": "Remove leading slash",
@@ -87,7 +77,7 @@
87
77
  ]
88
78
  },
89
79
  {
90
- "helper": "withoutTrailingSlash",
80
+ "name": "withoutTrailingSlash",
91
81
  "examples": [
92
82
  {
93
83
  "title": "Remove trailing slash",
@@ -95,6 +85,16 @@
95
85
  "code": "withoutTrailingSlash('path/to/resource/')\n// => 'path/to/resource'"
96
86
  }
97
87
  ]
88
+ },
89
+ {
90
+ "name": "withTrailingSlash",
91
+ "examples": [
92
+ {
93
+ "title": "Add a trailing slash",
94
+ "description": "Ensures the URL ends with a forward slash.",
95
+ "code": "withTrailingSlash('path/to/resource')\n// => 'path/to/resource/'"
96
+ }
97
+ ]
98
98
  }
99
99
  ]
100
100
  }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@helpers4/url",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.9",
4
4
  "description": "A set of helpers in TS/JS, compatible with tree-shaking, for url.",
5
5
  "author": "baxyz <baxy@etik.com>",
6
6
  "license": "LGPL-3.0",
7
+ "homepage": "https://helpers4.dev/typescript/categories/url/",
7
8
  "repository": {
8
9
  "type": "git",
9
10
  "url": "git+https://github.com/helpers4/typescript.git"
@@ -17,9 +18,9 @@
17
18
  "types": "./lib/index.d.ts",
18
19
  "import": "./lib/index.js"
19
20
  },
20
- "./examples.json": "./examples.json",
21
- "./api.json": "./api.json",
22
- "./licenses.json": "./licenses.json",
21
+ "./meta/api.json": "./meta/api.json",
22
+ "./meta/examples.json": "./meta/examples.json",
23
+ "./meta/licenses.json": "./meta/licenses.json",
23
24
  "./package.json": "./package.json"
24
25
  },
25
26
  "keywords": [
@@ -38,9 +39,7 @@
38
39
  "lib/index.js",
39
40
  "lib/index.d.ts",
40
41
  "lib/index.js.map",
41
- "examples.json",
42
- "api.json",
43
- "licenses.json",
42
+ "meta/",
44
43
  "LICENSE.md",
45
44
  "package.json",
46
45
  "README.md"
@@ -48,4 +47,4 @@
48
47
  "engines": {
49
48
  "node": ">=18.0.0"
50
49
  }
51
- }
50
+ }
package/api.json DELETED
@@ -1,135 +0,0 @@
1
- {
2
- "category": "url",
3
- "members": [
4
- {
5
- "name": "cleanPath",
6
- "kind": "function",
7
- "description": "Clean an URL by removing duplicate slashes.\nThe protocol part of the URL is not modified.",
8
- "signature": "cleanPath(url: string | null | undefined): string | null | undefined",
9
- "params": [
10
- {
11
- "name": "url",
12
- "type": "string | null | undefined",
13
- "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
14
- }
15
- ],
16
- "returns": "string | null | undefined",
17
- "examples": [
18
- "```ts\ncleanPath('/path//to///resource') // => '/path/to/resource'\ncleanPath('http://example.com//path//to///resource') // => 'http://example.com/path/to/resource'\ncleanPath(undefined) // => undefined\ncleanPath(null) // => null\n```"
19
- ]
20
- },
21
- {
22
- "name": "extractPureURI",
23
- "kind": "function",
24
- "description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
25
- "signature": "extractPureURI(url: string): string",
26
- "params": [
27
- {
28
- "name": "url",
29
- "type": "string",
30
- "description": "The URL string to process"
31
- }
32
- ],
33
- "returns": "string"
34
- },
35
- {
36
- "name": "onlyPath",
37
- "kind": "function",
38
- "description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
39
- "signature": "onlyPath(url: string): string",
40
- "params": [
41
- {
42
- "name": "url",
43
- "type": "string",
44
- "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
45
- }
46
- ],
47
- "returns": "string",
48
- "examples": [
49
- "```ts\nonlyPath('/path') // => '/path'\nonlyPath('/path?query=thing') // => '/path'\nonlyPath('/path#fragment') // => '/path'\nonlyPath('/path?query=thing#fragment') // => '/path'\nonlyPath(undefined) // => undefined\nonlyPath(null) // => null\n```"
50
- ]
51
- },
52
- {
53
- "name": "relativeURLToAbsolute",
54
- "kind": "function",
55
- "description": "",
56
- "signature": "relativeURLToAbsolute(relativeUrl: string): string",
57
- "params": [
58
- {
59
- "name": "relativeUrl",
60
- "type": "string",
61
- "description": ""
62
- }
63
- ],
64
- "returns": "string"
65
- },
66
- {
67
- "name": "withLeadingSlash",
68
- "kind": "function",
69
- "description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
70
- "signature": "withLeadingSlash(url: string): string",
71
- "params": [
72
- {
73
- "name": "url",
74
- "type": "string",
75
- "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
76
- }
77
- ],
78
- "returns": "string",
79
- "examples": [
80
- "```ts\nwithLeadingSlash('') // => '/'\nwithLeadingSlash('no/slash') // => '/no/slash'\nwithLeadingSlash('/already/has/slash') // => '/already/has/slash'\nwithLeadingSlash(undefined) // => undefined\nwithLeadingSlash(null) // => null\n```"
81
- ]
82
- },
83
- {
84
- "name": "withoutLeadingSlash",
85
- "kind": "function",
86
- "description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
87
- "signature": "withoutLeadingSlash(url: string): string",
88
- "params": [
89
- {
90
- "name": "url",
91
- "type": "string",
92
- "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
93
- }
94
- ],
95
- "returns": "string",
96
- "examples": [
97
- "```ts\nwithoutLeadingSlash('') // => ''\nwithoutLeadingSlash('/') // => ''\nwithoutLeadingSlash('/no/slash') // => 'no/slash'\nwithoutLeadingSlash('already/has/slash') // => 'already/has/slash'\nwithoutLeadingSlash(undefined) // => undefined\nwithoutLeadingSlash(null) // => null\n```"
98
- ]
99
- },
100
- {
101
- "name": "withoutTrailingSlash",
102
- "kind": "function",
103
- "description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
104
- "signature": "withoutTrailingSlash(url: string): string",
105
- "params": [
106
- {
107
- "name": "url",
108
- "type": "string",
109
- "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
110
- }
111
- ],
112
- "returns": "string",
113
- "examples": [
114
- "```ts\nwithoutTrailingSlash('') // => ''\nwithoutTrailingSlash('/') // => ''\nwithoutTrailingSlash('no/slash/') // => 'no/slash'\nwithoutTrailingSlash('already/has/slash') // => 'already/has/slash'\nwithoutTrailingSlash(undefined) // => undefined\nwithoutTrailingSlash(null) // => null\n```"
115
- ]
116
- },
117
- {
118
- "name": "withTrailingSlash",
119
- "kind": "function",
120
- "description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
121
- "signature": "withTrailingSlash(url: string): string",
122
- "params": [
123
- {
124
- "name": "url",
125
- "type": "string",
126
- "description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
127
- }
128
- ],
129
- "returns": "string",
130
- "examples": [
131
- "```ts\nwithTrailingSlash('') // => '/'\nwithTrailingSlash('no/slash') // => 'no/slash/'\nwithTrailingSlash('already/has/slash/') // => 'already/has/slash/'\nwithTrailingSlash(undefined) // => undefined\nwithTrailingSlash(null) // => null\n```"
132
- ]
133
- }
134
- ]
135
- }
File without changes