index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. // src/index.ts
  19. var src_exports = {};
  20. __export(src_exports, {
  21. default: () => src_default
  22. });
  23. module.exports = __toCommonJS(src_exports);
  24. function src_default(pkgName, pkgVersion, opts) {
  25. let registry;
  26. if (opts == null ? void 0 : opts.registry) {
  27. registry = opts.registry.endsWith("/") ? opts.registry : `${opts.registry}/`;
  28. } else {
  29. registry = "https://registry.npmjs.org/";
  30. }
  31. const scopelessName = getScopelessName(pkgName);
  32. return `${registry}${pkgName}/-/${scopelessName}-${removeBuildMetadataFromVersion(pkgVersion)}.tgz`;
  33. }
  34. function removeBuildMetadataFromVersion(version) {
  35. const plusPos = version.indexOf("+");
  36. if (plusPos === -1)
  37. return version;
  38. return version.substring(0, plusPos);
  39. }
  40. function getScopelessName(name) {
  41. if (name[0] !== "@") {
  42. return name;
  43. }
  44. return name.split("/")[1];
  45. }
  46. //# sourceMappingURL=index.js.map