UNPKG

npm-reinstall

Version:
29 lines (28 loc) 892 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Extract package info (name & version) from `packageWithVersion`. * * @export * @param {string} packageWithVersion Package name with version * @returns {PackageInfo} */ function extractPackageInfo(packageWithVersion) { var lastAtIndex = packageWithVersion.lastIndexOf('@'); /* * Skip when no package version or it's scoped package without version */ if (lastAtIndex === 0 || lastAtIndex === -1) { return { name: packageWithVersion, version: null }; } var packageName = packageWithVersion.substring(0, lastAtIndex); var packageVersion = packageWithVersion.substring(lastAtIndex + 1); return { name: packageName, version: packageVersion }; } exports.default = extractPackageInfo;