'use strict';

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

var _npmRegistryName;

function _load_npmRegistryName() {
  return _npmRegistryName = _interopRequireDefault(require('./npm-registry-name'));
}

var _constants;

function _load_constants() {
  return _constants = require('../../constants');
}

var _bitId;

function _load_bitId() {
  return _bitId = _interopRequireDefault(require('../../bit-id/bit-id'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * convert a component name to a valid npm package name
 */
function componentIdToPackageName(id, bindingPrefix) {
  var withPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;

  var nameWithoutPrefix = `${id.toStringWithoutVersion().replace(/\//g, (_constants || _load_constants()).NODE_PATH_COMPONENT_SEPARATOR)}`;
  if (!withPrefix) return nameWithoutPrefix;
  var registryPrefix = bindingPrefix || (0, (_npmRegistryName || _load_npmRegistryName()).default)();
  return `${registryPrefix}/${nameWithoutPrefix}`;
}