index.js 406 B

1234567891011121314151617
  1. module.exports = function (pkg) {
  2. var m;
  3. if (m = match(JSON.stringify(pkg.repository))) {
  4. return m;
  5. }
  6. else if (m = match(JSON.stringify(pkg))) {
  7. return m;
  8. }
  9. return undefined;
  10. };
  11. function match (str) {
  12. var m = /\bgithub.com[:\/]([^\/"]+)\/([^\/"]+)/.exec(str);
  13. if (m) {
  14. return 'https://github.com/' + m[1] + '/' + m[2].replace(/\.git$/, '');
  15. }
  16. }