UNPKG

680 BJavaScriptView Raw
1'use strict';
2
3const hostedGitInfo = require(`hosted-git-info`);
4const parseRepositoryURL = require(`@hutson/parse-repository-url`);
5
6module.exports = packageData => {
7 if (!packageData ||
8 !packageData.repository ||
9 (typeof packageData.repository !== 'string' && !packageData.repository.url)) {
10 throw new Error(`No valid "repository" data found in package metadata. Please see https://docs.npmjs.com/files/package.json#repository for proper syntax.`);
11 }
12
13 const repositoryURL = typeof packageData.repository === 'string' ? packageData.repository : packageData.repository.url;
14
15 return hostedGitInfo.fromUrl(repositoryURL) || parseRepositoryURL(repositoryURL);
16};