"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_string = require('../../../primordials/string.js');

//#region src/eco/npm/pnpm/parse-pnpm-package-id-v5.ts
/**
* @file `parsePnpmPackageIdV5(pkgId)` — extracts `{ name, version }` from a
*   pnpm v5 package key. Spec forms handled:
*
*   - `/name/version` → unscoped
*   - `/@scope/name/version` → scoped
*   - `/name/version_peer-suffix` → peer-dep suffix stripped Returns `{ name:
*     pkgId, version: '0.0.0' }` for unparseable input — matches socket-btm's
*     smol-manifest leniency.
*/
function parsePnpmPackageIdV5(pkgId) {
	const withoutSlash = pkgId[0] === "/" ? require_primordials_string.StringPrototypeSlice(pkgId, 1) : pkgId;
	const underscoreIdx = require_primordials_string.StringPrototypeIndexOf(withoutSlash, "_");
	const withoutPeerSuffix = underscoreIdx !== -1 ? require_primordials_string.StringPrototypeSlice(withoutSlash, 0, underscoreIdx) : withoutSlash;
	if (withoutPeerSuffix[0] === "@") {
		const parts = require_primordials_string.StringPrototypeSplit(withoutPeerSuffix, "/");
		if (parts.length < 2) return {
			name: withoutPeerSuffix,
			version: "0.0.0"
		};
		return {
			name: `${parts[0]}/${parts[1]}`,
			version: parts[2] ?? "0.0.0"
		};
	}
	const parts = require_primordials_string.StringPrototypeSplit(withoutPeerSuffix, "/");
	return {
		name: parts[0] ?? withoutPeerSuffix,
		version: parts[1] ?? "0.0.0"
	};
}

//#endregion
exports.parsePnpmPackageIdV5 = parsePnpmPackageIdV5;