"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_primordials_string = require('../primordials/string.js');
const require_strings_predicates = require('../strings/predicates.js');
const require_objects_predicates = require('../objects/predicates.js');
let src_external_npm_package_arg = require("../external/npm-package-arg");
src_external_npm_package_arg = require_runtime.__toESM(src_external_npm_package_arg);

//#region src/packages/specs.ts
/**
* @file Package spec parsing and GitHub URL utilities.
*/
/**
* Extract user and project from GitHub repository URL.
*
* @example
*   ;```typescript
*   getRepoUrlDetails('https://github.com/lodash/lodash.git')
*   // { user: 'lodash', project: 'lodash' }
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function getRepoUrlDetails(repoUrl = "") {
	const match = /^(?:[a-z][a-z+]*:\/\/)(?:[^/@]+@)?github\.com\/([^?#]+)(?:[?#]|$)/i.exec(repoUrl);
	if (!match || !match[1]) return {
		user: "",
		project: ""
	};
	const userAndRepo = match[1].split("/");
	const user = userAndRepo[0] || "";
	const rawProject = userAndRepo[1] ?? "";
	return {
		user,
		project: require_primordials_string.StringPrototypeEndsWith(rawProject, ".git") ? rawProject.slice(0, -4) : rawProject
	};
}
/**
* Generate GitHub API URL for a tag reference.
*
* @example
*   ;```typescript
*   gitHubTagRefUrl('lodash', 'lodash', 'v4.17.21')
*   // 'https://api.github.com/repos/lodash/lodash/git/ref/tags/v4.17.21'
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function gitHubTagRefUrl(user, project, tag) {
	return `https://api.github.com/repos/${user}/${project}/git/ref/tags/${tag}`;
}
/**
* Generate GitHub tarball download URL for a commit SHA.
*
* @example
*   ;```typescript
*   gitHubTgzUrl('lodash', 'lodash', 'abc123')
*   // 'https://github.com/lodash/lodash/archive/abc123.tar.gz'
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function gitHubTgzUrl(user, project, sha) {
	return `https://github.com/${user}/${project}/archive/${sha}.tar.gz`;
}
/**
* Check if a package specifier is a GitHub tarball URL.
*
* @example
*   ;```typescript
*   isGitHubTgzSpec('https://github.com/user/repo/archive/abc123.tar.gz') // true
*   isGitHubTgzSpec('lodash@4.17.21') // false
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function isGitHubTgzSpec(spec, where) {
	let parsedSpec;
	if (/* @__PURE__ */ require_objects_predicates.isPlainObject(spec)) parsedSpec = spec;
	else parsedSpec = (0, src_external_npm_package_arg.default)(spec, where);
	const typedSpec = parsedSpec;
	return typedSpec.type === "remote" && !!typedSpec.saveSpec?.endsWith(".tar.gz");
}
/**
* Check if a package specifier is a GitHub URL with committish.
*
* @example
*   ;```typescript
*   isGitHubUrlSpec('github:user/repo#v1.0.0') // true
*   isGitHubUrlSpec('lodash@4.17.21') // false
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function isGitHubUrlSpec(spec, where) {
	let parsedSpec;
	if (/* @__PURE__ */ require_objects_predicates.isPlainObject(spec)) parsedSpec = spec;
	else parsedSpec = (0, src_external_npm_package_arg.default)(spec, where);
	const typedSpec = parsedSpec;
	return typedSpec.type === "git" && typedSpec.hosted?.domain === "github.com" && /* @__PURE__ */ require_strings_predicates.isNonEmptyString(typedSpec.gitCommittish);
}

//#endregion
exports.getRepoUrlDetails = getRepoUrlDetails;
exports.gitHubTagRefUrl = gitHubTagRefUrl;
exports.gitHubTgzUrl = gitHubTgzUrl;
exports.isGitHubTgzSpec = isGitHubTgzSpec;
exports.isGitHubUrlSpec = isGitHubUrlSpec;