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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,16 +9,17 @@ A set of helpers for working with URLs.
9
9
 
10
10
  ## Documentation
11
11
 
12
- [https://helpers4.js.org/url](https://helpers4.js.org/url)
12
+ [https://helpers4.dev/typescript/categories/url/](https://helpers4.dev/typescript/categories/url/)
13
13
 
14
14
  <!-- AUTOMATIC-METHODS -->
15
- - withTrailingSlash
16
- - withoutLeadingSlash
17
15
  - cleanPath
18
- - relativeURLToAbsolute
19
- - withLeadingSlash
20
16
  - extractPureURI
21
17
  - onlyPath
18
+ - parsePackageRepository
19
+ - relativeURLToAbsolute
20
+ - withLeadingSlash
21
+ - withTrailingSlash
22
+ - withoutLeadingSlash
22
23
  - withoutTrailingSlash
23
24
  <!-- /AUTOMATIC-METHODS -->
24
25
 
@@ -26,8 +27,10 @@ A set of helpers for working with URLs.
26
27
 
27
28
  <!-- AUTOMATIC-SIBLINGS -->
28
29
  - [array](../array)
30
+ - [commit](../commit)
29
31
  - [date](../date)
30
32
  - [function](../function)
33
+ - [math](../math)
31
34
  - [number](../number)
32
35
  - [object](../object)
33
36
  - [observable](../observable)
@@ -43,14 +46,16 @@ A set of helpers for working with URLs.
43
46
  | Name | Package | Source Code | Description |
44
47
  |------|---------|-------------|-------------|
45
48
  | array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
46
- | date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | date utilities |
49
+ | commit | [@helpers4/commit](https://www.npmjs.com/package/@helpers4/commit) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/commit) | Conventional Commits parsing and analysis |
50
+ | date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | Date and time utility functions |
47
51
  | function | [@helpers4/function](https://www.npmjs.com/package/@helpers4/function) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/function) | Function utilities and type guards |
48
- | number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | number utilities |
52
+ | math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) | Mathematical utility functions and calculations |
53
+ | number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | Number utility functions and validation |
49
54
  | object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
50
55
  | observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
51
56
  | promise | [@helpers4/promise](https://www.npmjs.com/package/@helpers4/promise) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/promise) | Promise utilities and error handling |
52
57
  | string | [@helpers4/string](https://www.npmjs.com/package/@helpers4/string) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/string) | String manipulation and formatting utilities |
53
- | type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) | type utilities |
58
+ | type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) | Type checking and validation utilities |
54
59
  | url | [@helpers4/url](https://www.npmjs.com/package/@helpers4/url) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/url) | URL parsing and manipulation utilities |
55
60
  | version | [@helpers4/version](https://www.npmjs.com/package/@helpers4/version) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/version) | Version string manipulation utilities |
56
61
  <!-- /AUTOMATIC-CATEGORIES-TABLE -->
package/lib/index.d.ts CHANGED
@@ -1,8 +1,513 @@
1
- export declare function withTrailingSlash(url: string): string /** * Adds a trailing slash `/` to the given URL if it is not already present. * * This function is useful for ensuring that URLs are properly formatted * with a trailing slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withTrailingSlash * * @example * ```ts * withTrailingSlash('') // => '/' * withTrailingSlash('no/slash') // => 'no/slash/' * withTrailingSlash('already/has/slash/') // => 'already/has/slash/' * withTrailingSlash(undefined) // => undefined * withTrailingSlash(null) // => null * ``` */ export function withTrailingSlash(url: undefined): undefined /** * Adds a trailing slash `/` to the given URL if it is not already present. * * This function is useful for ensuring that URLs are properly formatted * with a trailing slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withTrailingSlash * * @example * ```ts * withTrailingSlash('') // => '/' * withTrailingSlash('no/slash') // => 'no/slash/' * withTrailingSlash('already/has/slash/') // => 'already/has/slash/' * withTrailingSlash(undefined) // => undefined * withTrailingSlash(null) // => null * ``` */ export function withTrailingSlash(url: null): null /** * Adds a trailing slash `/` to the given URL if it is not already present. * * This function is useful for ensuring that URLs are properly formatted * with a trailing slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withTrailingSlash * * @example * ```ts * withTrailingSlash('') // => '/' * withTrailingSlash('no/slash') // => 'no/slash/' * withTrailingSlash('already/has/slash/') // => 'already/has/slash/' * withTrailingSlash(undefined) // => undefined * withTrailingSlash(null) // => null * ``` */ export function withTrailingSlash( url: string | undefined | null, ): string | undefined | null;
2
- export declare function withoutLeadingSlash(url: string): string /** * Removes the leading slash `/` from the given URL if it is present. * * This function is useful for ensuring that URLs are properly formatted * without a leading slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withoutLeadingSlash * * @example * ```ts * withoutLeadingSlash('') // => '' * withoutLeadingSlash('/') // => '' * withoutLeadingSlash('/no/slash') // => 'no/slash' * withoutLeadingSlash('already/has/slash') // => 'already/has/slash' * withoutLeadingSlash(undefined) // => undefined * withoutLeadingSlash(null) // => null * ``` */ export function withoutLeadingSlash(url: undefined): undefined /** * Removes the leading slash `/` from the given URL if it is present. * * This function is useful for ensuring that URLs are properly formatted * without a leading slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withoutLeadingSlash * * @example * ```ts * withoutLeadingSlash('') // => '' * withoutLeadingSlash('/') // => '' * withoutLeadingSlash('/no/slash') // => 'no/slash' * withoutLeadingSlash('already/has/slash') // => 'already/has/slash' * withoutLeadingSlash(undefined) // => undefined * withoutLeadingSlash(null) // => null * ``` */ export function withoutLeadingSlash(url: null): null /** * Removes the leading slash `/` from the given URL if it is present. * * This function is useful for ensuring that URLs are properly formatted * without a leading slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withoutLeadingSlash * * @example * ```ts * withoutLeadingSlash('') // => '' * withoutLeadingSlash('/') // => '' * withoutLeadingSlash('/no/slash') // => 'no/slash' * withoutLeadingSlash('already/has/slash') // => 'already/has/slash' * withoutLeadingSlash(undefined) // => undefined * withoutLeadingSlash(null) // => null * ``` */ export function withoutLeadingSlash( url: string | undefined | null, ): string | undefined | null;
3
- export declare function cleanPath(url: string | undefined | null,): string | undefined | null;
4
- export declare function relativeURLToAbsolute(relativeUrl: string): string;
5
- export declare function withLeadingSlash(url: string): string /** * Adds a leading slash `/` to the given URL if it is not already present. * * This function is useful for ensuring that URLs are properly formatted * with a leading slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withLeadingSlash * * @example * ```ts * withLeadingSlash('') // => '/' * withLeadingSlash('no/slash') // => '/no/slash' * withLeadingSlash('/already/has/slash') // => '/already/has/slash' * withLeadingSlash(undefined) // => undefined * withLeadingSlash(null) // => null * ``` */ export function withLeadingSlash(url: undefined): undefined /** * Adds a leading slash `/` to the given URL if it is not already present. * * This function is useful for ensuring that URLs are properly formatted * with a leading slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withLeadingSlash * * @example * ```ts * withLeadingSlash('') // => '/' * withLeadingSlash('no/slash') // => '/no/slash' * withLeadingSlash('/already/has/slash') // => '/already/has/slash' * withLeadingSlash(undefined) // => undefined * withLeadingSlash(null) // => null * ``` */ export function withLeadingSlash(url: null): null /** * Adds a leading slash `/` to the given URL if it is not already present. * * This function is useful for ensuring that URLs are properly formatted * with a leading slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withLeadingSlash * * @example * ```ts * withLeadingSlash('') // => '/' * withLeadingSlash('no/slash') // => '/no/slash' * withLeadingSlash('/already/has/slash') // => '/already/has/slash' * withLeadingSlash(undefined) // => undefined * withLeadingSlash(null) // => null * ``` */ export function withLeadingSlash( url: string | undefined | null, ): string | undefined | null;
6
- export declare function extractPureURI(url: string): string; export function extractPureURI(url: undefined): undefined; export function extractPureURI(url: null): null; export function extractPureURI(url: string | undefined | null): string | undefined | null;
7
- export declare function onlyPath(url: string): string /** * Extract only the path from an URI with optional query and fragments. * * For example, all these parameters will return `/path`: * - `/path` * - `/path?query=thing` * - `/path#fragment` * - `/path?query=thing#fragment` * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @example * ```ts * onlyPath('/path') // => '/path' * onlyPath('/path?query=thing') // => '/path' * onlyPath('/path#fragment') // => '/path' * onlyPath('/path?query=thing#fragment') // => '/path' * onlyPath(undefined) // => undefined * onlyPath(null) // => null * ``` */ export function onlyPath(url: null): null /** * Extract only the path from an URI with optional query and fragments. * * For example, all these parameters will return `/path`: * - `/path` * - `/path?query=thing` * - `/path#fragment` * - `/path?query=thing#fragment` * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @example * ```ts * onlyPath('/path') // => '/path' * onlyPath('/path?query=thing') // => '/path' * onlyPath('/path#fragment') // => '/path' * onlyPath('/path?query=thing#fragment') // => '/path' * onlyPath(undefined) // => undefined * onlyPath(null) // => null * ``` */ export function onlyPath(url: undefined): undefined /** * Extract only the path from an URI with optional query and fragments. * * For example, all these parameters will return `/path`: * - `/path` * - `/path?query=thing` * - `/path#fragment` * - `/path?query=thing#fragment` * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @example * ```ts * onlyPath('/path') // => '/path' * onlyPath('/path?query=thing') // => '/path' * onlyPath('/path#fragment') // => '/path' * onlyPath('/path?query=thing#fragment') // => '/path' * onlyPath(undefined) // => undefined * onlyPath(null) // => null * ``` */ export function onlyPath( url: string | undefined | null, ): string | undefined | null;
8
- export declare function withoutTrailingSlash(url: string): string /** * Removes the trailing slash `/` from the given URL if it is present. * * This function is useful for ensuring that URLs are properly formatted * without a trailing slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withoutTrailingSlash * * @example * ```ts * withoutTrailingSlash('') // => '' * withoutTrailingSlash('/') // => '' * withoutTrailingSlash('no/slash/') // => 'no/slash' * withoutTrailingSlash('already/has/slash') // => 'already/has/slash' * withoutTrailingSlash(undefined) // => undefined * withoutTrailingSlash(null) // => null * ``` */ export function withoutTrailingSlash(url: undefined): undefined /** * Removes the trailing slash `/` from the given URL if it is present. * * This function is useful for ensuring that URLs are properly formatted * without a trailing slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withoutTrailingSlash * * @example * ```ts * withoutTrailingSlash('') // => '' * withoutTrailingSlash('/') // => '' * withoutTrailingSlash('no/slash/') // => 'no/slash' * withoutTrailingSlash('already/has/slash') // => 'already/has/slash' * withoutTrailingSlash(undefined) // => undefined * withoutTrailingSlash(null) // => null * ``` */ export function withoutTrailingSlash(url: null): null /** * Removes the trailing slash `/` from the given URL if it is present. * * This function is useful for ensuring that URLs are properly formatted * without a trailing slash, which is often required in web development for * consistency and to avoid issues with relative paths. * * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`. * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`. * * @see https://radashi.js.org/reference/url/withoutTrailingSlash * * @example * ```ts * withoutTrailingSlash('') // => '' * withoutTrailingSlash('/') // => '' * withoutTrailingSlash('no/slash/') // => 'no/slash' * withoutTrailingSlash('already/has/slash') // => 'already/has/slash' * withoutTrailingSlash(undefined) // => undefined * withoutTrailingSlash(null) // => null * ``` */ export function withoutTrailingSlash( url: string | undefined | null, ): string | undefined | null;
1
+ /**
2
+ * This file is part of helpers4.
3
+ * Copyright (C) 2025 baxyz
4
+ * SPDX-License-Identifier: LGPL-3.0-or-later
5
+ */
6
+ /**
7
+ * Clean an URL by removing duplicate slashes.
8
+ * The protocol part of the URL is not modified.
9
+ *
10
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
11
+ * @returns The cleaned URL string, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * cleanPath('/path//to///resource') // => '/path/to/resource'
16
+ * cleanPath('http://example.com//path//to///resource') // => 'http://example.com/path/to/resource'
17
+ * cleanPath(undefined) // => undefined
18
+ * cleanPath(null) // => null
19
+ * ```
20
+ * @since 1.0.0
21
+ */
22
+ declare function cleanPath(url: string | undefined | null): string | undefined | null;
23
+
24
+ /**
25
+ * This file is part of helpers4.
26
+ * Copyright (C) 2025 baxyz
27
+ * SPDX-License-Identifier: LGPL-3.0-or-later
28
+ */
29
+ /**
30
+ * Extracts the pure URI from a URL by removing query parameters and fragments.
31
+ *
32
+ * @param url - The URL string to process
33
+ * @returns The URI without query parameters and fragments, or the original value if undefined/null
34
+ * @since 1.9.0
35
+ */
36
+ declare function extractPureURI(url: string): string;
37
+ declare function extractPureURI(url: undefined): undefined;
38
+ declare function extractPureURI(url: null): null;
39
+
40
+ /**
41
+ * This file is part of helpers4.
42
+ * Copyright (C) 2025 baxyz
43
+ * SPDX-License-Identifier: LGPL-3.0-or-later
44
+ */
45
+ /**
46
+ * Extract only the path from an URI with optional query and fragments.
47
+ *
48
+ * For example, all these parameters will return `/path`:
49
+ * - `/path`
50
+ * - `/path?query=thing`
51
+ * - `/path#fragment`
52
+ * - `/path?query=thing#fragment`
53
+ *
54
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
55
+ * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * onlyPath('/path') // => '/path'
60
+ * onlyPath('/path?query=thing') // => '/path'
61
+ * onlyPath('/path#fragment') // => '/path'
62
+ * onlyPath('/path?query=thing#fragment') // => '/path'
63
+ * onlyPath(undefined) // => undefined
64
+ * onlyPath(null) // => null
65
+ * ```
66
+ * @since 1.0.0
67
+ */
68
+ declare function onlyPath(url: string): string;
69
+ /**
70
+ * Extract only the path from an URI with optional query and fragments.
71
+ *
72
+ * For example, all these parameters will return `/path`:
73
+ * - `/path`
74
+ * - `/path?query=thing`
75
+ * - `/path#fragment`
76
+ * - `/path?query=thing#fragment`
77
+ *
78
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
79
+ * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * onlyPath('/path') // => '/path'
84
+ * onlyPath('/path?query=thing') // => '/path'
85
+ * onlyPath('/path#fragment') // => '/path'
86
+ * onlyPath('/path?query=thing#fragment') // => '/path'
87
+ * onlyPath(undefined) // => undefined
88
+ * onlyPath(null) // => null
89
+ * ```
90
+ * @since 1.0.0
91
+ */
92
+ declare function onlyPath(url: null): null;
93
+ /**
94
+ * Extract only the path from an URI with optional query and fragments.
95
+ *
96
+ * For example, all these parameters will return `/path`:
97
+ * - `/path`
98
+ * - `/path?query=thing`
99
+ * - `/path#fragment`
100
+ * - `/path?query=thing#fragment`
101
+ *
102
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
103
+ * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * onlyPath('/path') // => '/path'
108
+ * onlyPath('/path?query=thing') // => '/path'
109
+ * onlyPath('/path#fragment') // => '/path'
110
+ * onlyPath('/path?query=thing#fragment') // => '/path'
111
+ * onlyPath(undefined) // => undefined
112
+ * onlyPath(null) // => null
113
+ * ```
114
+ * @since 1.0.0
115
+ */
116
+ declare function onlyPath(url: undefined): undefined;
117
+
118
+ /**
119
+ * This file is part of helpers4.
120
+ * Copyright (C) 2025 baxyz
121
+ * SPDX-License-Identifier: LGPL-3.0-or-later
122
+ */
123
+ /**
124
+ * Structured representation of a parsed `repository` field from `package.json`.
125
+ *
126
+ * @since next
127
+ */
128
+ interface PackageRepository {
129
+ /**
130
+ * VCS type (e.g. `'git'`, `'svn'`).
131
+ * Defaults to `'git'` when using shorthand string forms.
132
+ */
133
+ readonly type: string;
134
+ /**
135
+ * Hosting platform.
136
+ * Well-known values: `'github'`, `'gitlab'`, `'bitbucket'`, `'gist'`.
137
+ * Falls back to the raw domain (e.g. `'codeberg.org'`) for unknown hosts.
138
+ */
139
+ readonly host: 'github' | 'gitlab' | 'bitbucket' | 'gist' | (string & {});
140
+ /**
141
+ * `<owner>/<repo>` slug.
142
+ * `undefined` for gist shorthands (`gist:<id>`) and unrecognised URL shapes.
143
+ */
144
+ readonly slug: string | undefined;
145
+ /**
146
+ * Repository owner or organisation.
147
+ * `undefined` for gist shorthands.
148
+ */
149
+ readonly owner: string | undefined;
150
+ /**
151
+ * Repository name.
152
+ * `undefined` for gist shorthands.
153
+ */
154
+ readonly repo: string | undefined;
155
+ /**
156
+ * Gist identifier — only set when using the `gist:<id>` shorthand form.
157
+ */
158
+ readonly gistId: string | undefined;
159
+ /**
160
+ * Monorepo sub-directory from the `directory` field of the object form.
161
+ * `undefined` when using shorthand string forms or when no `directory` is specified.
162
+ */
163
+ readonly directory: string | undefined;
164
+ }
165
+ /**
166
+ * Parse the `repository` field from `package.json` into a structured object.
167
+ *
168
+ * Supports all npm-specified formats:
169
+ * - **Object form**: `{ "type": "git", "url": "...", "directory": "..." }`
170
+ * - **GitHub shorthand**: `"owner/repo"` or `"github:owner/repo"`
171
+ * - **Platform shorthands**: `"gitlab:owner/repo"`, `"bitbucket:owner/repo"`
172
+ * - **Gist shorthand**: `"gist:<id>"`
173
+ * - **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`
174
+ *
175
+ * Returns `undefined` for `null`, `undefined`, arrays, or values that cannot
176
+ * be matched to any recognised format.
177
+ *
178
+ * @param repository - The `repository` field value from `package.json`.
179
+ * @returns A parsed {@link PackageRepository} object, or `undefined` if the
180
+ * input cannot be parsed.
181
+ * @example
182
+ * parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })
183
+ * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',
184
+ * // repo: 'typescript', gistId: undefined, directory: undefined }
185
+ * @example
186
+ * parsePackageRepository('github:helpers4/typescript')
187
+ * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',
188
+ * // repo: 'typescript', gistId: undefined, directory: undefined }
189
+ * @since next
190
+ */
191
+ declare function parsePackageRepository(repository: unknown): PackageRepository | undefined;
192
+
193
+ /**
194
+ * This file is part of helpers4.
195
+ * Copyright (C) 2025 baxyz
196
+ * SPDX-License-Identifier: LGPL-3.0-or-later
197
+ */
198
+ /**
199
+ * Converts a relative URL to an absolute URL using the current document base URI.
200
+ * @param relativeUrl - The relative URL to convert
201
+ * @returns The absolute URL
202
+ * @since 1.0.0
203
+ */
204
+ declare function relativeURLToAbsolute(relativeUrl: string): string;
205
+
206
+ /**
207
+ * This file is part of helpers4.
208
+ * Copyright (C) 2025 baxyz
209
+ * SPDX-License-Identifier: LGPL-3.0-or-later
210
+ */
211
+ /**
212
+ * Adds a leading slash `/` to the given URL if it is not already present.
213
+ *
214
+ * This function is useful for ensuring that URLs are properly formatted
215
+ * with a leading slash, which is often required in web development for
216
+ * consistency and to avoid issues with relative paths.
217
+ *
218
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
219
+ * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
220
+ *
221
+ * @see https://radashi.js.org/reference/url/withLeadingSlash
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * withLeadingSlash('') // => '/'
226
+ * withLeadingSlash('no/slash') // => '/no/slash'
227
+ * withLeadingSlash('/already/has/slash') // => '/already/has/slash'
228
+ * withLeadingSlash(undefined) // => undefined
229
+ * withLeadingSlash(null) // => null
230
+ * ```
231
+ * @since 1.0.0
232
+ */
233
+ declare function withLeadingSlash(url: string): string;
234
+ /**
235
+ * Adds a leading slash `/` to the given URL if it is not already present.
236
+ *
237
+ * This function is useful for ensuring that URLs are properly formatted
238
+ * with a leading slash, which is often required in web development for
239
+ * consistency and to avoid issues with relative paths.
240
+ *
241
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
242
+ * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
243
+ *
244
+ * @see https://radashi.js.org/reference/url/withLeadingSlash
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * withLeadingSlash('') // => '/'
249
+ * withLeadingSlash('no/slash') // => '/no/slash'
250
+ * withLeadingSlash('/already/has/slash') // => '/already/has/slash'
251
+ * withLeadingSlash(undefined) // => undefined
252
+ * withLeadingSlash(null) // => null
253
+ * ```
254
+ * @since 1.0.0
255
+ */
256
+ declare function withLeadingSlash(url: undefined): undefined;
257
+ /**
258
+ * Adds a leading slash `/` to the given URL if it is not already present.
259
+ *
260
+ * This function is useful for ensuring that URLs are properly formatted
261
+ * with a leading slash, which is often required in web development for
262
+ * consistency and to avoid issues with relative paths.
263
+ *
264
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
265
+ * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
266
+ *
267
+ * @see https://radashi.js.org/reference/url/withLeadingSlash
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * withLeadingSlash('') // => '/'
272
+ * withLeadingSlash('no/slash') // => '/no/slash'
273
+ * withLeadingSlash('/already/has/slash') // => '/already/has/slash'
274
+ * withLeadingSlash(undefined) // => undefined
275
+ * withLeadingSlash(null) // => null
276
+ * ```
277
+ * @since 1.0.0
278
+ */
279
+ declare function withLeadingSlash(url: null): null;
280
+
281
+ /**
282
+ * This file is part of helpers4.
283
+ * Copyright (C) 2025 baxyz
284
+ * SPDX-License-Identifier: LGPL-3.0-or-later
285
+ */
286
+ /**
287
+ * Adds a trailing slash `/` to the given URL if it is not already present.
288
+ *
289
+ * This function is useful for ensuring that URLs are properly formatted
290
+ * with a trailing slash, which is often required in web development for
291
+ * consistency and to avoid issues with relative paths.
292
+ *
293
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
294
+ * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
295
+ *
296
+ * @see https://radashi.js.org/reference/url/withTrailingSlash
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * withTrailingSlash('') // => '/'
301
+ * withTrailingSlash('no/slash') // => 'no/slash/'
302
+ * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'
303
+ * withTrailingSlash(undefined) // => undefined
304
+ * withTrailingSlash(null) // => null
305
+ * ```
306
+ * @since 1.0.0
307
+ */
308
+ declare function withTrailingSlash(url: string): string;
309
+ /**
310
+ * Adds a trailing slash `/` to the given URL if it is not already present.
311
+ *
312
+ * This function is useful for ensuring that URLs are properly formatted
313
+ * with a trailing slash, which is often required in web development for
314
+ * consistency and to avoid issues with relative paths.
315
+ *
316
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
317
+ * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
318
+ *
319
+ * @see https://radashi.js.org/reference/url/withTrailingSlash
320
+ *
321
+ * @example
322
+ * ```ts
323
+ * withTrailingSlash('') // => '/'
324
+ * withTrailingSlash('no/slash') // => 'no/slash/'
325
+ * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'
326
+ * withTrailingSlash(undefined) // => undefined
327
+ * withTrailingSlash(null) // => null
328
+ * ```
329
+ * @since 1.0.0
330
+ */
331
+ declare function withTrailingSlash(url: undefined): undefined;
332
+ /**
333
+ * Adds a trailing slash `/` to the given URL if it is not already present.
334
+ *
335
+ * This function is useful for ensuring that URLs are properly formatted
336
+ * with a trailing slash, which is often required in web development for
337
+ * consistency and to avoid issues with relative paths.
338
+ *
339
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
340
+ * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
341
+ *
342
+ * @see https://radashi.js.org/reference/url/withTrailingSlash
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * withTrailingSlash('') // => '/'
347
+ * withTrailingSlash('no/slash') // => 'no/slash/'
348
+ * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'
349
+ * withTrailingSlash(undefined) // => undefined
350
+ * withTrailingSlash(null) // => null
351
+ * ```
352
+ * @since 1.0.0
353
+ */
354
+ declare function withTrailingSlash(url: null): null;
355
+
356
+ /**
357
+ * This file is part of helpers4.
358
+ * Copyright (C) 2025 baxyz
359
+ * SPDX-License-Identifier: LGPL-3.0-or-later
360
+ */
361
+ /**
362
+ * Removes the leading slash `/` from the given URL if it is present.
363
+ *
364
+ * This function is useful for ensuring that URLs are properly formatted
365
+ * without a leading slash, which is often required in web development for
366
+ * consistency and to avoid issues with relative paths.
367
+ *
368
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
369
+ * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
370
+ *
371
+ * @see https://radashi.js.org/reference/url/withoutLeadingSlash
372
+ *
373
+ * @example
374
+ * ```ts
375
+ * withoutLeadingSlash('') // => ''
376
+ * withoutLeadingSlash('/') // => ''
377
+ * withoutLeadingSlash('/no/slash') // => 'no/slash'
378
+ * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'
379
+ * withoutLeadingSlash(undefined) // => undefined
380
+ * withoutLeadingSlash(null) // => null
381
+ * ```
382
+ * @since 1.0.0
383
+ */
384
+ declare function withoutLeadingSlash(url: string): string;
385
+ /**
386
+ * Removes the leading slash `/` from the given URL if it is present.
387
+ *
388
+ * This function is useful for ensuring that URLs are properly formatted
389
+ * without a leading slash, which is often required in web development for
390
+ * consistency and to avoid issues with relative paths.
391
+ *
392
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
393
+ * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
394
+ *
395
+ * @see https://radashi.js.org/reference/url/withoutLeadingSlash
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * withoutLeadingSlash('') // => ''
400
+ * withoutLeadingSlash('/') // => ''
401
+ * withoutLeadingSlash('/no/slash') // => 'no/slash'
402
+ * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'
403
+ * withoutLeadingSlash(undefined) // => undefined
404
+ * withoutLeadingSlash(null) // => null
405
+ * ```
406
+ * @since 1.0.0
407
+ */
408
+ declare function withoutLeadingSlash(url: undefined): undefined;
409
+ /**
410
+ * Removes the leading slash `/` from the given URL if it is present.
411
+ *
412
+ * This function is useful for ensuring that URLs are properly formatted
413
+ * without a leading slash, which is often required in web development for
414
+ * consistency and to avoid issues with relative paths.
415
+ *
416
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
417
+ * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
418
+ *
419
+ * @see https://radashi.js.org/reference/url/withoutLeadingSlash
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * withoutLeadingSlash('') // => ''
424
+ * withoutLeadingSlash('/') // => ''
425
+ * withoutLeadingSlash('/no/slash') // => 'no/slash'
426
+ * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'
427
+ * withoutLeadingSlash(undefined) // => undefined
428
+ * withoutLeadingSlash(null) // => null
429
+ * ```
430
+ * @since 1.0.0
431
+ */
432
+ declare function withoutLeadingSlash(url: null): null;
433
+
434
+ /**
435
+ * This file is part of helpers4.
436
+ * Copyright (C) 2025 baxyz
437
+ * SPDX-License-Identifier: LGPL-3.0-or-later
438
+ */
439
+ /**
440
+ * Removes the trailing slash `/` from the given URL if it is present.
441
+ *
442
+ * This function is useful for ensuring that URLs are properly formatted
443
+ * without a trailing slash, which is often required in web development for
444
+ * consistency and to avoid issues with relative paths.
445
+ *
446
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
447
+ * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
448
+ *
449
+ * @see https://radashi.js.org/reference/url/withoutTrailingSlash
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * withoutTrailingSlash('') // => ''
454
+ * withoutTrailingSlash('/') // => ''
455
+ * withoutTrailingSlash('no/slash/') // => 'no/slash'
456
+ * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'
457
+ * withoutTrailingSlash(undefined) // => undefined
458
+ * withoutTrailingSlash(null) // => null
459
+ * ```
460
+ * @since 1.0.0
461
+ */
462
+ declare function withoutTrailingSlash(url: string): string;
463
+ /**
464
+ * Removes the trailing slash `/` from the given URL if it is present.
465
+ *
466
+ * This function is useful for ensuring that URLs are properly formatted
467
+ * without a trailing slash, which is often required in web development for
468
+ * consistency and to avoid issues with relative paths.
469
+ *
470
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
471
+ * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
472
+ *
473
+ * @see https://radashi.js.org/reference/url/withoutTrailingSlash
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * withoutTrailingSlash('') // => ''
478
+ * withoutTrailingSlash('/') // => ''
479
+ * withoutTrailingSlash('no/slash/') // => 'no/slash'
480
+ * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'
481
+ * withoutTrailingSlash(undefined) // => undefined
482
+ * withoutTrailingSlash(null) // => null
483
+ * ```
484
+ * @since 1.0.0
485
+ */
486
+ declare function withoutTrailingSlash(url: undefined): undefined;
487
+ /**
488
+ * Removes the trailing slash `/` from the given URL if it is present.
489
+ *
490
+ * This function is useful for ensuring that URLs are properly formatted
491
+ * without a trailing slash, which is often required in web development for
492
+ * consistency and to avoid issues with relative paths.
493
+ *
494
+ * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.
495
+ * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.
496
+ *
497
+ * @see https://radashi.js.org/reference/url/withoutTrailingSlash
498
+ *
499
+ * @example
500
+ * ```ts
501
+ * withoutTrailingSlash('') // => ''
502
+ * withoutTrailingSlash('/') // => ''
503
+ * withoutTrailingSlash('no/slash/') // => 'no/slash'
504
+ * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'
505
+ * withoutTrailingSlash(undefined) // => undefined
506
+ * withoutTrailingSlash(null) // => null
507
+ * ```
508
+ * @since 1.0.0
509
+ */
510
+ declare function withoutTrailingSlash(url: null): null;
511
+
512
+ export { cleanPath, extractPureURI, onlyPath, parsePackageRepository, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
513
+ export type { PackageRepository };