"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = componentIdToPackageName;

function _npmRegistryName() {
  const data = _interopRequireDefault(require("./npm-registry-name"));

  _npmRegistryName = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../../constants");

  _constants = function () {
    return data;
  };

  return data;
}

function _bitId() {
  const data = _interopRequireDefault(require("../../bit-id/bit-id"));

  _bitId = function () {
    return data;
  };

  return data;
}

/**
 * convert a component name to a valid npm package name
 */
function componentIdToPackageName(id, bindingPrefix, withPrefix = true) {
  const nameWithoutPrefix = `${id.toStringWithoutVersion().replace(/\//g, _constants().NODE_PATH_COMPONENT_SEPARATOR)}`;
  if (!withPrefix) return nameWithoutPrefix;
  const registryPrefix = bindingPrefix || (0, _npmRegistryName().default)();
  return `${registryPrefix}/${nameWithoutPrefix}`;
}