@helpers4/url 2.0.0-alpha.2 → 2.0.0-alpha.6

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 CHANGED
@@ -1,79 +1,191 @@
1
- // helpers/url/withTrailingSlash.ts
2
- function withTrailingSlash(url) {
3
- if (url === undefined || url === null) {
4
- return url;
5
- }
6
- return url[url.length - 1] === "/" ? url : url + "/";
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
+ */
22
+ function cleanPath(url) {
23
+ if (url === void 0 || url === null) return url;
24
+ return url.replace(/([^:]\/)\/+/g, "$1");
7
25
  }
8
- // helpers/url/withoutLeadingSlash.ts
9
- function withoutLeadingSlash(url) {
10
- if (url === undefined || url === null) {
11
- return url;
12
- }
13
- return url[0] === "/" ? url.slice(1) : url;
26
+ //#endregion
27
+ //#region helpers/url/extractPureURI.ts
28
+ function extractPureURI(url) {
29
+ if (url === void 0 || url === null) return url;
30
+ const queryIndex = url.indexOf("?");
31
+ const fragmentIndex = url.indexOf("#");
32
+ let cutIndex = -1;
33
+ if (queryIndex !== -1 && fragmentIndex !== -1) cutIndex = Math.min(queryIndex, fragmentIndex);
34
+ else if (queryIndex !== -1) cutIndex = queryIndex;
35
+ else if (fragmentIndex !== -1) cutIndex = fragmentIndex;
36
+ if (cutIndex === -1) return url;
37
+ return url.substring(0, cutIndex);
14
38
  }
15
- // helpers/url/cleanPath.ts
16
- function cleanPath(url) {
17
- if (url === undefined || url === null) {
18
- return url;
19
- }
20
- return url.replace(/([^:]\/)\/+/g, "$1");
39
+ //#endregion
40
+ //#region helpers/url/onlyPath.ts
41
+ /**
42
+ * Extract only the path from an URI with optional query and fragments.
43
+ *
44
+ * For example, all these parameters will return `/path`:
45
+ * - `/path`
46
+ * - `/path?query=thing`
47
+ * - `/path#fragment`
48
+ * - `/path?query=thing#fragment`
49
+ *
50
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
51
+ * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * onlyPath('/path') // => '/path'
56
+ * onlyPath('/path?query=thing') // => '/path'
57
+ * onlyPath('/path#fragment') // => '/path'
58
+ * onlyPath('/path?query=thing#fragment') // => '/path'
59
+ * onlyPath(undefined) // => undefined
60
+ * onlyPath(null) // => null
61
+ * ```
62
+ */
63
+ function onlyPath(url) {
64
+ if (url === void 0 || url === null) return url;
65
+ const [path] = url.split(/[?#]/);
66
+ return path;
21
67
  }
22
- // helpers/url/withoutTrailingSlash.ts
68
+ //#endregion
69
+ //#region helpers/url/withoutTrailingSlash.ts
70
+ /**
71
+ * Removes the trailing slash `/` from the given URL if it is present.
72
+ *
73
+ * This function is useful for ensuring that URLs are properly formatted
74
+ * without a trailing slash, which is often required in web development for
75
+ * consistency and to avoid issues with relative paths.
76
+ *
77
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
78
+ * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
79
+ *
80
+ * @see https://radashi.js.org/reference/url/withoutTrailingSlash
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * withoutTrailingSlash('') // => ''
85
+ * withoutTrailingSlash('/') // => ''
86
+ * withoutTrailingSlash('no/slash/') // => 'no/slash'
87
+ * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'
88
+ * withoutTrailingSlash(undefined) // => undefined
89
+ * withoutTrailingSlash(null) // => null
90
+ * ```
91
+ */
23
92
  function withoutTrailingSlash(url) {
24
- if (url === undefined || url === null) {
25
- return url;
26
- }
27
- return url[url.length - 1] === "/" ? url.slice(0, -1) : url;
93
+ if (url === void 0 || url === null) return url;
94
+ return url[url.length - 1] === "/" ? url.slice(0, -1) : url;
28
95
  }
29
-
30
- // helpers/url/withLeadingSlash.ts
96
+ //#endregion
97
+ //#region helpers/url/withLeadingSlash.ts
98
+ /**
99
+ * Adds a leading slash `/` to the given URL if it is not already present.
100
+ *
101
+ * This function is useful for ensuring that URLs are properly formatted
102
+ * with a leading slash, which is often required in web development for
103
+ * consistency and to avoid issues with relative paths.
104
+ *
105
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
106
+ * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
107
+ *
108
+ * @see https://radashi.js.org/reference/url/withLeadingSlash
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * withLeadingSlash('') // => '/'
113
+ * withLeadingSlash('no/slash') // => '/no/slash'
114
+ * withLeadingSlash('/already/has/slash') // => '/already/has/slash'
115
+ * withLeadingSlash(undefined) // => undefined
116
+ * withLeadingSlash(null) // => null
117
+ * ```
118
+ */
31
119
  function withLeadingSlash(url) {
32
- if (url === undefined || url === null) {
33
- return url;
34
- }
35
- return url[0] === "/" ? url : "/" + url;
120
+ if (url === void 0 || url === null) return url;
121
+ return url[0] === "/" ? url : "/" + url;
36
122
  }
37
-
38
- // helpers/url/relativeURLToAbsolute.ts
123
+ //#endregion
124
+ //#region helpers/url/relativeURLToAbsolute.ts
125
+ /**
126
+ * This file is part of helpers4.
127
+ * Copyright (C) 2025 baxyz
128
+ * SPDX-License-Identifier: LGPL-3.0-or-later
129
+ */
39
130
  function relativeURLToAbsolute(relativeUrl) {
40
- return withoutTrailingSlash(document.baseURI ?? window.location.origin) + cleanPath(withLeadingSlash(relativeUrl));
131
+ return withoutTrailingSlash(document.baseURI ?? window.location.origin) + cleanPath(withLeadingSlash(relativeUrl));
41
132
  }
42
- // helpers/url/extractPureURI.ts
43
- function extractPureURI(url) {
44
- if (url === undefined || url === null) {
45
- return url;
46
- }
47
- const queryIndex = url.indexOf("?");
48
- const fragmentIndex = url.indexOf("#");
49
- let cutIndex = -1;
50
- if (queryIndex !== -1 && fragmentIndex !== -1) {
51
- cutIndex = Math.min(queryIndex, fragmentIndex);
52
- } else if (queryIndex !== -1) {
53
- cutIndex = queryIndex;
54
- } else if (fragmentIndex !== -1) {
55
- cutIndex = fragmentIndex;
56
- }
57
- if (cutIndex === -1) {
58
- return url;
59
- }
60
- return url.substring(0, cutIndex);
133
+ //#endregion
134
+ //#region helpers/url/withTrailingSlash.ts
135
+ /**
136
+ * Adds a trailing slash `/` to the given URL if it is not already present.
137
+ *
138
+ * This function is useful for ensuring that URLs are properly formatted
139
+ * with a trailing slash, which is often required in web development for
140
+ * consistency and to avoid issues with relative paths.
141
+ *
142
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
143
+ * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
144
+ *
145
+ * @see https://radashi.js.org/reference/url/withTrailingSlash
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * withTrailingSlash('') // => '/'
150
+ * withTrailingSlash('no/slash') // => 'no/slash/'
151
+ * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'
152
+ * withTrailingSlash(undefined) // => undefined
153
+ * withTrailingSlash(null) // => null
154
+ * ```
155
+ */
156
+ function withTrailingSlash(url) {
157
+ if (url === void 0 || url === null) return url;
158
+ return url[url.length - 1] === "/" ? url : url + "/";
61
159
  }
62
- // helpers/url/onlyPath.ts
63
- function onlyPath(url) {
64
- if (url === undefined || url === null) {
65
- return url;
66
- }
67
- const [path] = url.split(/[?#]/);
68
- return path;
160
+ //#endregion
161
+ //#region helpers/url/withoutLeadingSlash.ts
162
+ /**
163
+ * Removes the leading slash `/` from the given URL if it is present.
164
+ *
165
+ * This function is useful for ensuring that URLs are properly formatted
166
+ * without a leading slash, which is often required in web development for
167
+ * consistency and to avoid issues with relative paths.
168
+ *
169
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
170
+ * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
171
+ *
172
+ * @see https://radashi.js.org/reference/url/withoutLeadingSlash
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * withoutLeadingSlash('') // => ''
177
+ * withoutLeadingSlash('/') // => ''
178
+ * withoutLeadingSlash('/no/slash') // => 'no/slash'
179
+ * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'
180
+ * withoutLeadingSlash(undefined) // => undefined
181
+ * withoutLeadingSlash(null) // => null
182
+ * ```
183
+ */
184
+ function withoutLeadingSlash(url) {
185
+ if (url === void 0 || url === null) return url;
186
+ return url[0] === "/" ? url.slice(1) : url;
69
187
  }
70
- export {
71
- withoutTrailingSlash,
72
- withoutLeadingSlash,
73
- withTrailingSlash,
74
- withLeadingSlash,
75
- relativeURLToAbsolute,
76
- onlyPath,
77
- extractPureURI,
78
- cleanPath
79
- };
188
+ //#endregion
189
+ export { cleanPath, extractPureURI, onlyPath, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
190
+
191
+ //# 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 */\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"}
package/package.json CHANGED
@@ -1,40 +1,49 @@
1
1
  {
2
2
  "name": "@helpers4/url",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.6",
4
4
  "description": "A set of helpers in TS/JS, compatible with tree-shaking, for url.",
5
5
  "author": "baxyz <baxy@etik.com>",
6
- "license": "AGPL-3.0",
6
+ "license": "LGPL-3.0",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/helpers4/helpers4.git"
9
+ "url": "git+https://github.com/helpers4/typescript.git"
10
10
  },
11
11
  "type": "module",
12
+ "sideEffects": false,
12
13
  "main": "lib/index.js",
13
14
  "types": "lib/index.d.ts",
14
15
  "exports": {
15
16
  ".": {
16
17
  "types": "./lib/index.d.ts",
17
18
  "import": "./lib/index.js"
18
- }
19
+ },
20
+ "./examples.json": "./examples.json",
21
+ "./api.json": "./api.json",
22
+ "./package.json": "./package.json"
19
23
  },
20
24
  "keywords": [
21
25
  "helpers",
22
26
  "url",
23
- "withTrailingSlash",
24
- "withoutLeadingSlash",
25
27
  "cleanPath",
26
- "relativeURLToAbsolute",
27
- "withLeadingSlash",
28
28
  "extractPureURI",
29
29
  "onlyPath",
30
+ "relativeURLToAbsolute",
31
+ "withLeadingSlash",
32
+ "withTrailingSlash",
33
+ "withoutLeadingSlash",
30
34
  "withoutTrailingSlash"
31
35
  ],
32
36
  "files": [
33
37
  "lib/index.js",
34
38
  "lib/index.d.ts",
35
39
  "lib/index.js.map",
40
+ "examples.json",
41
+ "api.json",
36
42
  "LICENSE.md",
37
43
  "package.json",
38
44
  "README.md"
39
- ]
40
- }
45
+ ],
46
+ "engines": {
47
+ "node": ">=18.0.0"
48
+ }
49
+ }