"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/npm/extract-package-name-from-path.ts
/**
* @file `extractPackageNameFromPath(pkgPath)` — given an npm v2/v3 lockfile
*   entry key like `node_modules/a/node_modules/b`, returns the final package
*   name (`b`), preserving scoped-package boundaries (`@scope/name` stays
*   joined). Windows-generated lockfiles may use `\\` separators; the impl
*   normalizes first so both forms are handled. Behavior matches socket-btm's
*   smol-manifest internal `extractPackageNameFromPath`.
*/
const NODE_MODULES_PREFIX = "node_modules/";
function extractPackageNameFromPath(pkgPath) {
	const normalized = require_primordials_string.StringPrototypeReplaceAll(pkgPath, "\\", "/");
	const lastNmIdx = require_primordials_string.StringPrototypeLastIndexOf(normalized, NODE_MODULES_PREFIX);
	if (lastNmIdx === -1) return normalized;
	const withoutPrefix = require_primordials_string.StringPrototypeSlice(normalized, lastNmIdx + 13);
	if (withoutPrefix[0] === "@") {
		const parts = require_primordials_string.StringPrototypeSplit(withoutPrefix, "/");
		if (parts.length < 2) return withoutPrefix;
		return `${parts[0]}/${parts[1]}`;
	}
	const firstSlash = require_primordials_string.StringPrototypeIndexOf(withoutPrefix, "/");
	if (firstSlash === -1) return withoutPrefix;
	return require_primordials_string.StringPrototypeSlice(withoutPrefix, 0, firstSlash);
}

//#endregion
exports.extractPackageNameFromPath = extractPackageNameFromPath;