@helpers4/url 2.0.0-alpha.18 → 2.0.0-alpha.19

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
@@ -15,6 +15,7 @@ A set of helpers for working with URLs.
15
15
  - cleanPath
16
16
  - extractPureURI
17
17
  - onlyPath
18
+ - parsePackageRepository
18
19
  - relativeURLToAbsolute
19
20
  - withLeadingSlash
20
21
  - withTrailingSlash
package/lib/index.d.ts CHANGED
@@ -115,6 +115,81 @@ declare function onlyPath(url: null): null;
115
115
  */
116
116
  declare function onlyPath(url: undefined): undefined;
117
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
+
118
193
  /**
119
194
  * This file is part of helpers4.
120
195
  * Copyright (C) 2025 baxyz
@@ -434,4 +509,5 @@ declare function withoutTrailingSlash(url: undefined): undefined;
434
509
  */
435
510
  declare function withoutTrailingSlash(url: null): null;
436
511
 
437
- export { cleanPath, extractPureURI, onlyPath, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
512
+ export { cleanPath, extractPureURI, onlyPath, parsePackageRepository, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
513
+ export type { PackageRepository };
package/lib/index.js CHANGED
@@ -68,6 +68,116 @@ function onlyPath(url) {
68
68
  return path;
69
69
  }
70
70
  //#endregion
71
+ //#region helpers/url/parsePackageRepository.ts
72
+ /** Maps known GitHub/GitLab/Bitbucket domains to their platform name. */
73
+ var DOMAIN_TO_HOST = {
74
+ "github.com": "github",
75
+ "gitlab.com": "gitlab",
76
+ "bitbucket.org": "bitbucket"
77
+ };
78
+ /** SCP-style SSH URL: `git@github.com:owner/repo.git` */
79
+ var RE_SSH_SCP = /^git@([\w.-]+):([\w.-]+\/[\w.-]+?)(?:\.git)?(?:[#?].*)?$/;
80
+ /**
81
+ * URL-form remote: `git+https://…`, `https://…`, `git://…`, `git+ssh://git@…`
82
+ * Captures: [1] domain, [2] owner/repo path
83
+ */
84
+ var RE_URL = /^(?:git\+(?:https?|ssh)|https?|git):\/\/(?:[^@/]+@)?([\w.-]+)\/([\w.-]+\/[\w.-]+?)(?:\.git)?(?:[#?].*)?$/;
85
+ function makeOwnerRepoResult(type, host, rawPath, directory) {
86
+ const slashIdx = rawPath.indexOf("/");
87
+ const owner = rawPath.slice(0, slashIdx);
88
+ const repo = rawPath.slice(slashIdx + 1);
89
+ return {
90
+ type,
91
+ host,
92
+ slug: `${owner}/${repo}`,
93
+ owner,
94
+ repo,
95
+ gistId: void 0,
96
+ directory
97
+ };
98
+ }
99
+ function parseRawUrl(raw, type, directory) {
100
+ const shorthandMatch = /^(github|gitlab|bitbucket):([\w.-]+\/[\w.-]+)$/.exec(raw);
101
+ if (shorthandMatch) {
102
+ const host = shorthandMatch[1];
103
+ const slug = shorthandMatch[2];
104
+ const slashIdx = slug.indexOf("/");
105
+ return {
106
+ type,
107
+ host,
108
+ slug,
109
+ owner: slug.slice(0, slashIdx),
110
+ repo: slug.slice(slashIdx + 1),
111
+ gistId: void 0,
112
+ directory
113
+ };
114
+ }
115
+ const gistMatch = /^gist:([\w-]+)$/.exec(raw);
116
+ if (gistMatch) return {
117
+ type,
118
+ host: "gist",
119
+ slug: void 0,
120
+ owner: void 0,
121
+ repo: void 0,
122
+ gistId: gistMatch[1],
123
+ directory
124
+ };
125
+ const bareMatch = /^([\w.-]+)\/([\w.-]+)$/.exec(raw);
126
+ if (bareMatch) {
127
+ const owner = bareMatch[1];
128
+ const repo = bareMatch[2];
129
+ return {
130
+ type,
131
+ host: "github",
132
+ slug: `${owner}/${repo}`,
133
+ owner,
134
+ repo,
135
+ gistId: void 0,
136
+ directory
137
+ };
138
+ }
139
+ const sshMatch = RE_SSH_SCP.exec(raw);
140
+ if (sshMatch) return makeOwnerRepoResult(type, DOMAIN_TO_HOST[sshMatch[1]] ?? sshMatch[1], sshMatch[2], directory);
141
+ const urlMatch = RE_URL.exec(raw);
142
+ if (urlMatch) return makeOwnerRepoResult(type, DOMAIN_TO_HOST[urlMatch[1]] ?? urlMatch[1], urlMatch[2], directory);
143
+ }
144
+ /**
145
+ * Parse the `repository` field from `package.json` into a structured object.
146
+ *
147
+ * Supports all npm-specified formats:
148
+ * - **Object form**: `{ "type": "git", "url": "...", "directory": "..." }`
149
+ * - **GitHub shorthand**: `"owner/repo"` or `"github:owner/repo"`
150
+ * - **Platform shorthands**: `"gitlab:owner/repo"`, `"bitbucket:owner/repo"`
151
+ * - **Gist shorthand**: `"gist:<id>"`
152
+ * - **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`
153
+ *
154
+ * Returns `undefined` for `null`, `undefined`, arrays, or values that cannot
155
+ * be matched to any recognised format.
156
+ *
157
+ * @param repository - The `repository` field value from `package.json`.
158
+ * @returns A parsed {@link PackageRepository} object, or `undefined` if the
159
+ * input cannot be parsed.
160
+ * @example
161
+ * parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })
162
+ * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',
163
+ * // repo: 'typescript', gistId: undefined, directory: undefined }
164
+ * @example
165
+ * parsePackageRepository('github:helpers4/typescript')
166
+ * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',
167
+ * // repo: 'typescript', gistId: undefined, directory: undefined }
168
+ * @since next
169
+ */
170
+ function parsePackageRepository(repository) {
171
+ if (repository === null || repository === void 0) return void 0;
172
+ if (typeof repository === "string") return parseRawUrl(repository, "git", void 0);
173
+ if (typeof repository === "object" && !Array.isArray(repository)) {
174
+ const obj = repository;
175
+ const rawUrl = obj["url"];
176
+ if (typeof rawUrl !== "string") return void 0;
177
+ return parseRawUrl(rawUrl, typeof obj["type"] === "string" ? obj["type"] : "git", typeof obj["directory"] === "string" ? obj["directory"] : void 0);
178
+ }
179
+ }
180
+ //#endregion
71
181
  //#region helpers/url/withoutTrailingSlash.ts
72
182
  /**
73
183
  * Removes the trailing slash `/` from the given URL if it is present.
@@ -198,6 +308,6 @@ function withoutLeadingSlash(url) {
198
308
  return url[0] === "/" ? url.slice(1) : url;
199
309
  }
200
310
  //#endregion
201
- export { cleanPath, extractPureURI, onlyPath, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
311
+ export { cleanPath, extractPureURI, onlyPath, parsePackageRepository, relativeURLToAbsolute, withLeadingSlash, withTrailingSlash, withoutLeadingSlash, withoutTrailingSlash };
202
312
 
203
313
  //# sourceMappingURL=index.js.map
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 * @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.replace(/\\/+$/, '')\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: string): string\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: undefined): undefined\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: null): null\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[0] === '/' ? url : '/' + url\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\n\nimport { withoutTrailingSlash } from \"./withoutTrailingSlash\";\nimport { withLeadingSlash } from \"./withLeadingSlash\";\nimport { cleanPath } from \"./cleanPath\";\n\n/**\n * Converts a relative URL to an absolute URL using the current document base URI.\n * @param relativeUrl - The relative URL to convert\n * @returns The absolute URL\n * @since 1.0.0\n */\nexport function relativeURLToAbsolute(relativeUrl: string): string {\n return (\n withoutTrailingSlash(document.baseURI ?? window.location.origin) +\n cleanPath(withLeadingSlash(relativeUrl))\n );\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: string): string\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: undefined): undefined\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: null): null\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[url.length - 1] === '/' ? url : url + '/'\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: string): string\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: undefined): undefined\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: null): null\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[0] === '/' ? url.slice(1) : url\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;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,QAAQ,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;ACVhC,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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../helpers/url/cleanPath.ts","../../../helpers/url/extractPureURI.ts","../../../helpers/url/onlyPath.ts","../../../helpers/url/parsePackageRepository.ts","../../../helpers/url/withoutTrailingSlash.ts","../../../helpers/url/withLeadingSlash.ts","../../../helpers/url/relativeURLToAbsolute.ts","../../../helpers/url/withTrailingSlash.ts","../../../helpers/url/withoutLeadingSlash.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clean an URL by removing duplicate slashes.\n * The protocol part of the URL is not modified.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The cleaned URL string, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * cleanPath('/path//to///resource') // => '/path/to/resource'\n * cleanPath('http://example.com//path//to///resource') // => 'http://example.com/path/to/resource'\n * cleanPath(undefined) // => undefined\n * cleanPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function cleanPath(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url.replace(/([^:]\\/)\\/+/g, '$1')\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\n\n/**\n * Extracts the pure URI from a URL by removing query parameters and fragments.\n *\n * @param url - The URL string to process\n * @returns The URI without query parameters and fragments, or the original value if undefined/null\n * @since 1.9.0\n */\nexport function extractPureURI(url: string): string;\nexport function extractPureURI(url: undefined): undefined;\nexport function extractPureURI(url: null): null;\nexport function extractPureURI(url: string | undefined | null): string | undefined | null {\n if (url === undefined || url === null) {\n return url;\n }\n\n // Find the first occurrence of ? or #\n const queryIndex = url.indexOf('?');\n const fragmentIndex = url.indexOf('#');\n\n let cutIndex = -1;\n\n if (queryIndex !== -1 && fragmentIndex !== -1) {\n // Both exist, take the earliest one\n cutIndex = Math.min(queryIndex, fragmentIndex);\n } else if (queryIndex !== -1) {\n // Only query exists\n cutIndex = queryIndex;\n } else if (fragmentIndex !== -1) {\n // Only fragment exists\n cutIndex = fragmentIndex;\n }\n\n // If no query or fragment found, return the original string\n if (cutIndex === -1) {\n return url;\n }\n\n // Return the substring up to the first ? or #\n return url.substring(0, cutIndex);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(url: string): string\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(url: null): null\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(url: undefined): undefined\n\n/**\n * Extract only the path from an URI with optional query and fragments.\n *\n * For example, all these parameters will return `/path`:\n * - `/path`\n * - `/path?query=thing`\n * - `/path#fragment`\n * - `/path?query=thing#fragment`\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @example\n * ```ts\n * onlyPath('/path') // => '/path'\n * onlyPath('/path?query=thing') // => '/path'\n * onlyPath('/path#fragment') // => '/path'\n * onlyPath('/path?query=thing#fragment') // => '/path'\n * onlyPath(undefined) // => undefined\n * onlyPath(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function onlyPath(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n const [path] = url.split(/[?#]/)\n return path\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Structured representation of a parsed `repository` field from `package.json`.\n *\n * @since next\n */\nexport interface PackageRepository {\n /**\n * VCS type (e.g. `'git'`, `'svn'`).\n * Defaults to `'git'` when using shorthand string forms.\n */\n readonly type: string;\n /**\n * Hosting platform.\n * Well-known values: `'github'`, `'gitlab'`, `'bitbucket'`, `'gist'`.\n * Falls back to the raw domain (e.g. `'codeberg.org'`) for unknown hosts.\n */\n readonly host: 'github' | 'gitlab' | 'bitbucket' | 'gist' | (string & {});\n /**\n * `<owner>/<repo>` slug.\n * `undefined` for gist shorthands (`gist:<id>`) and unrecognised URL shapes.\n */\n readonly slug: string | undefined;\n /**\n * Repository owner or organisation.\n * `undefined` for gist shorthands.\n */\n readonly owner: string | undefined;\n /**\n * Repository name.\n * `undefined` for gist shorthands.\n */\n readonly repo: string | undefined;\n /**\n * Gist identifier — only set when using the `gist:<id>` shorthand form.\n */\n readonly gistId: string | undefined;\n /**\n * Monorepo sub-directory from the `directory` field of the object form.\n * `undefined` when using shorthand string forms or when no `directory` is specified.\n */\n readonly directory: string | undefined;\n}\n\n/** Maps known GitHub/GitLab/Bitbucket domains to their platform name. */\nconst DOMAIN_TO_HOST: Record<string, string> = {\n 'github.com': 'github',\n 'gitlab.com': 'gitlab',\n 'bitbucket.org': 'bitbucket',\n};\n\n/** SCP-style SSH URL: `git@github.com:owner/repo.git` */\nconst RE_SSH_SCP = /^git@([\\w.-]+):([\\w.-]+\\/[\\w.-]+?)(?:\\.git)?(?:[#?].*)?$/;\n\n/**\n * URL-form remote: `git+https://…`, `https://…`, `git://…`, `git+ssh://git@…`\n * Captures: [1] domain, [2] owner/repo path\n */\nconst RE_URL =\n /^(?:git\\+(?:https?|ssh)|https?|git):\\/\\/(?:[^@/]+@)?([\\w.-]+)\\/([\\w.-]+\\/[\\w.-]+?)(?:\\.git)?(?:[#?].*)?$/;\n\nfunction makeOwnerRepoResult(\n type: string,\n host: string,\n rawPath: string,\n directory: string | undefined,\n): PackageRepository {\n const slashIdx = rawPath.indexOf('/');\n const owner = rawPath.slice(0, slashIdx);\n const repo = rawPath.slice(slashIdx + 1);\n return { type, host, slug: `${owner}/${repo}`, owner, repo, gistId: undefined, directory };\n}\n\nfunction parseRawUrl(\n raw: string,\n type: string,\n directory: string | undefined,\n): PackageRepository | undefined {\n // Shorthand prefix: \"github:owner/repo\", \"gitlab:owner/repo\", \"bitbucket:owner/repo\"\n const shorthandMatch = /^(github|gitlab|bitbucket):([\\w.-]+\\/[\\w.-]+)$/.exec(raw);\n if (shorthandMatch) {\n const host = shorthandMatch[1] as 'github' | 'gitlab' | 'bitbucket';\n const slug = shorthandMatch[2];\n const slashIdx = slug.indexOf('/');\n const owner = slug.slice(0, slashIdx);\n const repo = slug.slice(slashIdx + 1);\n return { type, host, slug, owner, repo, gistId: undefined, directory };\n }\n\n // Gist shorthand: \"gist:<id>\"\n const gistMatch = /^gist:([\\w-]+)$/.exec(raw);\n if (gistMatch) {\n return { type, host: 'gist', slug: undefined, owner: undefined, repo: undefined, gistId: gistMatch[1], directory };\n }\n\n // Bare GitHub shorthand: \"owner/repo\" (no colon prefix, no protocol)\n const bareMatch = /^([\\w.-]+)\\/([\\w.-]+)$/.exec(raw);\n if (bareMatch) {\n const owner = bareMatch[1];\n const repo = bareMatch[2];\n return { type, host: 'github', slug: `${owner}/${repo}`, owner, repo, gistId: undefined, directory };\n }\n\n // SCP-style SSH: git@github.com:owner/repo.git\n const sshMatch = RE_SSH_SCP.exec(raw);\n if (sshMatch) {\n const host = DOMAIN_TO_HOST[sshMatch[1]] ?? sshMatch[1];\n return makeOwnerRepoResult(type, host, sshMatch[2], directory);\n }\n\n // URL-form: https://, git+https://, git://, git+ssh://\n const urlMatch = RE_URL.exec(raw);\n if (urlMatch) {\n const host = DOMAIN_TO_HOST[urlMatch[1]] ?? urlMatch[1];\n return makeOwnerRepoResult(type, host, urlMatch[2], directory);\n }\n\n return undefined;\n}\n\n/**\n * Parse the `repository` field from `package.json` into a structured object.\n *\n * Supports all npm-specified formats:\n * - **Object form**: `{ \"type\": \"git\", \"url\": \"...\", \"directory\": \"...\" }`\n * - **GitHub shorthand**: `\"owner/repo\"` or `\"github:owner/repo\"`\n * - **Platform shorthands**: `\"gitlab:owner/repo\"`, `\"bitbucket:owner/repo\"`\n * - **Gist shorthand**: `\"gist:<id>\"`\n * - **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`\n *\n * Returns `undefined` for `null`, `undefined`, arrays, or values that cannot\n * be matched to any recognised format.\n *\n * @param repository - The `repository` field value from `package.json`.\n * @returns A parsed {@link PackageRepository} object, or `undefined` if the\n * input cannot be parsed.\n * @example\n * parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })\n * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',\n * // repo: 'typescript', gistId: undefined, directory: undefined }\n * @example\n * parsePackageRepository('github:helpers4/typescript')\n * // => { type: 'git', host: 'github', slug: 'helpers4/typescript', owner: 'helpers4',\n * // repo: 'typescript', gistId: undefined, directory: undefined }\n * @since next\n */\nexport function parsePackageRepository(repository: unknown): PackageRepository | undefined {\n if (repository === null || repository === undefined) return undefined;\n\n if (typeof repository === 'string') {\n return parseRawUrl(repository, 'git', undefined);\n }\n\n if (typeof repository === 'object' && !Array.isArray(repository)) {\n const obj = repository as Record<string, unknown>;\n const rawUrl = obj['url'];\n if (typeof rawUrl !== 'string') return undefined;\n const type = typeof obj['type'] === 'string' ? (obj['type'] as string) : 'git';\n const directory = typeof obj['directory'] === 'string' ? (obj['directory'] as string) : undefined;\n return parseRawUrl(rawUrl, type, directory);\n }\n\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(url: string): string\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(url: undefined): undefined\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(url: null): null\n\n/**\n * Removes the trailing slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutTrailingSlash\n *\n * @example\n * ```ts\n * withoutTrailingSlash('') // => ''\n * withoutTrailingSlash('/') // => ''\n * withoutTrailingSlash('no/slash/') // => 'no/slash'\n * withoutTrailingSlash('already/has/slash') // => 'already/has/slash'\n * withoutTrailingSlash(undefined) // => undefined\n * withoutTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutTrailingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url.replace(/\\/+$/, '')\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: string): string\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: undefined): undefined\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(url: null): null\n\n/**\n * Adds a leading slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withLeadingSlash\n *\n * @example\n * ```ts\n * withLeadingSlash('') // => '/'\n * withLeadingSlash('no/slash') // => '/no/slash'\n * withLeadingSlash('/already/has/slash') // => '/already/has/slash'\n * withLeadingSlash(undefined) // => undefined\n * withLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withLeadingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[0] === '/' ? url : '/' + url\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\n\nimport { withoutTrailingSlash } from \"./withoutTrailingSlash\";\nimport { withLeadingSlash } from \"./withLeadingSlash\";\nimport { cleanPath } from \"./cleanPath\";\n\n/**\n * Converts a relative URL to an absolute URL using the current document base URI.\n * @param relativeUrl - The relative URL to convert\n * @returns The absolute URL\n * @since 1.0.0\n */\nexport function relativeURLToAbsolute(relativeUrl: string): string {\n return (\n withoutTrailingSlash(document.baseURI ?? window.location.origin) +\n cleanPath(withLeadingSlash(relativeUrl))\n );\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: string): string\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: undefined): undefined\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(url: null): null\n\n/**\n * Adds a trailing slash `/` to the given URL if it is not already present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * with a trailing slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withTrailingSlash\n *\n * @example\n * ```ts\n * withTrailingSlash('') // => '/'\n * withTrailingSlash('no/slash') // => 'no/slash/'\n * withTrailingSlash('already/has/slash/') // => 'already/has/slash/'\n * withTrailingSlash(undefined) // => undefined\n * withTrailingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withTrailingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[url.length - 1] === '/' ? url : url + '/'\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: string): string\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: undefined): undefined\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(url: null): null\n\n/**\n * Removes the leading slash `/` from the given URL if it is present.\n *\n * This function is useful for ensuring that URLs are properly formatted\n * without a leading slash, which is often required in web development for\n * consistency and to avoid issues with relative paths.\n *\n * @param url - The URL string to be processed. Can be `string`, `undefined`, or `null`.\n * @returns The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`.\n *\n * @see https://radashi.js.org/reference/url/withoutLeadingSlash\n *\n * @example\n * ```ts\n * withoutLeadingSlash('') // => ''\n * withoutLeadingSlash('/') // => ''\n * withoutLeadingSlash('/no/slash') // => 'no/slash'\n * withoutLeadingSlash('already/has/slash') // => 'already/has/slash'\n * withoutLeadingSlash(undefined) // => undefined\n * withoutLeadingSlash(null) // => null\n * ```\n * @since 1.0.0\n */\nexport function withoutLeadingSlash(\n url: string | undefined | null,\n): string | undefined | null {\n if (url === undefined || url === null) {\n return url\n }\n return url[0] === '/' ? url.slice(1) : url\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;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;;;;;AC7DT,IAAM,iBAAyC;CAC7C,cAAc;CACd,cAAc;CACd,iBAAiB;CAClB;;AAGD,IAAM,aAAa;;;;;AAMnB,IAAM,SACJ;AAEF,SAAS,oBACP,MACA,MACA,SACA,WACmB;CACnB,MAAM,WAAW,QAAQ,QAAQ,IAAI;CACrC,MAAM,QAAQ,QAAQ,MAAM,GAAG,SAAS;CACxC,MAAM,OAAO,QAAQ,MAAM,WAAW,EAAE;AACxC,QAAO;EAAE;EAAM;EAAM,MAAM,GAAG,MAAM,GAAG;EAAQ;EAAO;EAAM,QAAQ,KAAA;EAAW;EAAW;;AAG5F,SAAS,YACP,KACA,MACA,WAC+B;CAE/B,MAAM,iBAAiB,iDAAiD,KAAK,IAAI;AACjF,KAAI,gBAAgB;EAClB,MAAM,OAAO,eAAe;EAC5B,MAAM,OAAO,eAAe;EAC5B,MAAM,WAAW,KAAK,QAAQ,IAAI;AAGlC,SAAO;GAAE;GAAM;GAAM;GAAM,OAFb,KAAK,MAAM,GAAG,SAAS;GAEH,MADrB,KAAK,MAAM,WAAW,EAAE;GACG,QAAQ,KAAA;GAAW;GAAW;;CAIxE,MAAM,YAAY,kBAAkB,KAAK,IAAI;AAC7C,KAAI,UACF,QAAO;EAAE;EAAM,MAAM;EAAQ,MAAM,KAAA;EAAW,OAAO,KAAA;EAAW,MAAM,KAAA;EAAW,QAAQ,UAAU;EAAI;EAAW;CAIpH,MAAM,YAAY,yBAAyB,KAAK,IAAI;AACpD,KAAI,WAAW;EACb,MAAM,QAAQ,UAAU;EACxB,MAAM,OAAO,UAAU;AACvB,SAAO;GAAE;GAAM,MAAM;GAAU,MAAM,GAAG,MAAM,GAAG;GAAQ;GAAO;GAAM,QAAQ,KAAA;GAAW;GAAW;;CAItG,MAAM,WAAW,WAAW,KAAK,IAAI;AACrC,KAAI,SAEF,QAAO,oBAAoB,MADd,eAAe,SAAS,OAAO,SAAS,IACd,SAAS,IAAI,UAAU;CAIhE,MAAM,WAAW,OAAO,KAAK,IAAI;AACjC,KAAI,SAEF,QAAO,oBAAoB,MADd,eAAe,SAAS,OAAO,SAAS,IACd,SAAS,IAAI,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgClE,SAAgB,uBAAuB,YAAoD;AACzF,KAAI,eAAe,QAAQ,eAAe,KAAA,EAAW,QAAO,KAAA;AAE5D,KAAI,OAAO,eAAe,SACxB,QAAO,YAAY,YAAY,OAAO,KAAA,EAAU;AAGlD,KAAI,OAAO,eAAe,YAAY,CAAC,MAAM,QAAQ,WAAW,EAAE;EAChE,MAAM,MAAM;EACZ,MAAM,SAAS,IAAI;AACnB,MAAI,OAAO,WAAW,SAAU,QAAO,KAAA;AAGvC,SAAO,YAAY,QAFN,OAAO,IAAI,YAAY,WAAY,IAAI,UAAqB,OACvD,OAAO,IAAI,iBAAiB,WAAY,IAAI,eAA0B,KAAA,EAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5D/C,SAAgB,qBACd,KAC2B;AAC3B,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAC/B,QAAO;AAET,QAAO,IAAI,QAAQ,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;ACVhC,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/llms.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  # @helpers4/url
2
2
 
3
3
  > Tree-shakable TypeScript utility functions for the `url` domain.
4
- > Package: `@helpers4/url` — Version: 2.0.0-alpha.18
4
+ > Package: `@helpers4/url` — Version: 2.0.0-alpha.19
5
5
  > License: LGPL-3.0-or-later
6
6
 
7
7
  ## Installation
@@ -25,6 +25,7 @@ import { cleanPath, extractPureURI, onlyPath, ... } from '@helpers4/url';
25
25
  | `cleanPath` | Clean an URL by removing duplicate slashes. The protocol part of the URL is not modified. |
26
26
  | `extractPureURI` | Extracts the pure URI from a URL by removing query parameters and fragments. |
27
27
  | `onlyPath` | Extract only the path from an URI with optional query and fragments. For example, all these paramet |
28
+ | `parsePackageRepository` | Parse the `repository` field from `package.json` into a structured object. Supports all npm-specifi |
28
29
  | `relativeURLToAbsolute` | Converts a relative URL to an absolute URL using the current document base URI. |
29
30
  | `withLeadingSlash` | Adds a leading slash `/` to the given URL if it is not already present. This function is useful for |
30
31
  | `withoutLeadingSlash` | Removes the leading slash `/` from the given URL if it is present. This function is useful for ensu |
@@ -195,6 +196,62 @@ onlyPath('/path?query=thing#fragment')
195
196
 
196
197
  ---
197
198
 
199
+ ### `parsePackageRepository`
200
+
201
+ Parse the `repository` field from `package.json` into a structured object.
202
+
203
+ Supports all npm-specified formats:
204
+ - **Object form**: `{ "type": "git", "url": "...", "directory": "..." }`
205
+ - **GitHub shorthand**: `"owner/repo"` or `"github:owner/repo"`
206
+ - **Platform shorthands**: `"gitlab:owner/repo"`, `"bitbucket:owner/repo"`
207
+ - **Gist shorthand**: `"gist:<id>"`
208
+ - **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`
209
+
210
+ Returns `undefined` for `null`, `undefined`, arrays, or values that cannot
211
+ be matched to any recognised format.
212
+
213
+ ```typescript
214
+ import { parsePackageRepository } from '@helpers4/url';
215
+
216
+ parsePackageRepository(repository: unknown): PackageRepository | undefined
217
+ ```
218
+
219
+ **Parameters:**
220
+
221
+ - `repository: unknown` — The `repository` field value from `package.json`.
222
+
223
+ **Returns:** `PackageRepository | undefined` — A parsed PackageRepository object, or `undefined` if the
224
+ input cannot be parsed.
225
+
226
+ **Examples:**
227
+
228
+ *Parse the npm canonical object form*
229
+
230
+ Parses the full object form written by npm publish.
231
+
232
+ ```typescript
233
+ parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })
234
+ // => { type: 'git', host: 'github', slug: 'helpers4/typescript',
235
+ // owner: 'helpers4', repo: 'typescript', gistId: undefined, directory: undefined }
236
+ ```
237
+
238
+ *Parse npm shorthand forms*
239
+
240
+ npm accepts "owner/repo", "github:owner/repo", "gitlab:owner/repo" etc. as shorthand.
241
+
242
+ ```typescript
243
+ parsePackageRepository('helpers4/typescript')
244
+ // => { host: 'github', slug: 'helpers4/typescript', owner: 'helpers4', repo: 'typescript', ... }
245
+
246
+ parsePackageRepository('gitlab:myorg/myproject')
247
+ // => { host: 'gitlab', slug: 'myorg/myproject', owner: 'myorg', repo: 'myproject', ... }
248
+
249
+ parsePackageRepository('gist:11081aaa281')
250
+ // => { host: 'gist', gistId: '11081aaa281', slug: undefined, owner: undefined, ... }
251
+ ```
252
+
253
+ ---
254
+
198
255
  ### `relativeURLToAbsolute`
199
256
 
200
257
  Converts a relative URL to an absolute URL using the current document base URI.
package/meta/api.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "category": "url",
3
- "version": "2.0.0-alpha.18",
3
+ "version": "2.0.0-alpha.19",
4
4
  "functions": [
5
5
  {
6
6
  "name": "cleanPath",
@@ -165,6 +165,49 @@
165
165
  ],
166
166
  "sourceFile": "onlyPath.ts"
167
167
  },
168
+ {
169
+ "name": "parsePackageRepository",
170
+ "kind": "function",
171
+ "description": "Parse the `repository` field from `package.json` into a structured object.\n\nSupports all npm-specified formats:\n- **Object form**: `{ \"type\": \"git\", \"url\": \"...\", \"directory\": \"...\" }`\n- **GitHub shorthand**: `\"owner/repo\"` or `\"github:owner/repo\"`\n- **Platform shorthands**: `\"gitlab:owner/repo\"`, `\"bitbucket:owner/repo\"`\n- **Gist shorthand**: `\"gist:<id>\"`\n- **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`\n\nReturns `undefined` for `null`, `undefined`, arrays, or values that cannot\nbe matched to any recognised format.",
172
+ "since": "next",
173
+ "signatures": [
174
+ {
175
+ "signature": "parsePackageRepository(repository: unknown): PackageRepository | undefined",
176
+ "description": "Parse the `repository` field from `package.json` into a structured object.\n\nSupports all npm-specified formats:\n- **Object form**: `{ \"type\": \"git\", \"url\": \"...\", \"directory\": \"...\" }`\n- **GitHub shorthand**: `\"owner/repo\"` or `\"github:owner/repo\"`\n- **Platform shorthands**: `\"gitlab:owner/repo\"`, `\"bitbucket:owner/repo\"`\n- **Gist shorthand**: `\"gist:<id>\"`\n- **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`\n\nReturns `undefined` for `null`, `undefined`, arrays, or values that cannot\nbe matched to any recognised format.",
177
+ "params": [
178
+ {
179
+ "name": "repository",
180
+ "type": "unknown",
181
+ "description": "The `repository` field value from `package.json`."
182
+ }
183
+ ],
184
+ "returns": {
185
+ "type": "PackageRepository | undefined",
186
+ "description": "A parsed PackageRepository object, or `undefined` if the\n input cannot be parsed."
187
+ }
188
+ }
189
+ ],
190
+ "examples": [
191
+ {
192
+ "title": "Parse the npm canonical object form",
193
+ "description": "Parses the full object form written by npm publish.",
194
+ "code": "parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })\n// => { type: 'git', host: 'github', slug: 'helpers4/typescript',\n// owner: 'helpers4', repo: 'typescript', gistId: undefined, directory: undefined }"
195
+ },
196
+ {
197
+ "title": "Parse npm shorthand forms",
198
+ "description": "npm accepts \"owner/repo\", \"github:owner/repo\", \"gitlab:owner/repo\" etc. as shorthand.",
199
+ "code": "parsePackageRepository('helpers4/typescript')\n// => { host: 'github', slug: 'helpers4/typescript', owner: 'helpers4', repo: 'typescript', ... }\n\nparsePackageRepository('gitlab:myorg/myproject')\n// => { host: 'gitlab', slug: 'myorg/myproject', owner: 'myorg', repo: 'myproject', ... }\n\nparsePackageRepository('gist:11081aaa281')\n// => { host: 'gist', gistId: '11081aaa281', slug: undefined, owner: undefined, ... }"
200
+ }
201
+ ],
202
+ "sourceFile": "parsePackageRepository.ts",
203
+ "relatedTypes": [
204
+ {
205
+ "name": "PackageRepository",
206
+ "description": "Structured representation of a parsed `repository` field from `package.json`.",
207
+ "typeDefinition": "interface PackageRepository {\n directory: string | undefined;\n gistId: string | undefined;\n host: string & object | \"github\" | \"gitlab\" | \"bitbucket\" | \"gist\";\n owner: string | undefined;\n repo: string | undefined;\n slug: string | undefined;\n type: string;\n}"
208
+ }
209
+ ]
210
+ },
168
211
  {
169
212
  "name": "relativeURLToAbsolute",
170
213
  "kind": "function",
@@ -41,6 +41,21 @@
41
41
  }
42
42
  ]
43
43
  },
44
+ {
45
+ "name": "parsePackageRepository",
46
+ "examples": [
47
+ {
48
+ "title": "Parse the npm canonical object form",
49
+ "description": "Parses the full object form written by npm publish.",
50
+ "code": "parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })\n// => { type: 'git', host: 'github', slug: 'helpers4/typescript',\n// owner: 'helpers4', repo: 'typescript', gistId: undefined, directory: undefined }"
51
+ },
52
+ {
53
+ "title": "Parse npm shorthand forms",
54
+ "description": "npm accepts \"owner/repo\", \"github:owner/repo\", \"gitlab:owner/repo\" etc. as shorthand.",
55
+ "code": "parsePackageRepository('helpers4/typescript')\n// => { host: 'github', slug: 'helpers4/typescript', owner: 'helpers4', repo: 'typescript', ... }\n\nparsePackageRepository('gitlab:myorg/myproject')\n// => { host: 'gitlab', slug: 'myorg/myproject', owner: 'myorg', repo: 'myproject', ... }\n\nparsePackageRepository('gist:11081aaa281')\n// => { host: 'gist', gistId: '11081aaa281', slug: undefined, owner: undefined, ... }"
56
+ }
57
+ ]
58
+ },
44
59
  {
45
60
  "name": "relativeURLToAbsolute",
46
61
  "examples": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helpers4/url",
3
- "version": "2.0.0-alpha.18",
3
+ "version": "2.0.0-alpha.19",
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",
@@ -30,6 +30,7 @@
30
30
  "cleanPath",
31
31
  "extractPureURI",
32
32
  "onlyPath",
33
+ "parsePackageRepository",
33
34
  "relativeURLToAbsolute",
34
35
  "withLeadingSlash",
35
36
  "withTrailingSlash",