hosted-git-info
Advanced tools
Comparing version 2.5.0 to 2.6.0
@@ -39,2 +39,3 @@ 'use strict' | ||
'browsetemplate': 'https://{domain}/{project}{/committish}', | ||
'browsefiletemplate': 'https://{domain}/{project}{/committish}{#path}', | ||
'docstemplate': 'https://{domain}/{project}{/committish}', | ||
@@ -44,3 +45,6 @@ 'httpstemplate': 'git+https://{domain}/{project}.git{#committish}', | ||
'pathtemplate': '{project}{#committish}', | ||
'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz' | ||
'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz', | ||
'hashformat': function (fragment) { | ||
return 'file-' + formatHashFragment(fragment) | ||
} | ||
} | ||
@@ -53,2 +57,3 @@ } | ||
'browsetemplate': 'https://{domain}/{user}/{project}{/tree/committish}', | ||
'browsefiletemplate': 'https://{domain}/{user}/{project}/{treepath}/{committish}/{path}{#fragment}', | ||
'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#readme', | ||
@@ -59,3 +64,4 @@ 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{project}.git{#committish}', | ||
'pathtemplate': '{user}/{project}{#committish}', | ||
'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git|[/])?$/ | ||
'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git|[/])?$/, | ||
'hashformat': formatHashFragment | ||
} | ||
@@ -73,1 +79,5 @@ | ||
}) | ||
function formatHashFragment (fragment) { | ||
return fragment.toLowerCase().replace(/^\W+|\/|\W+$/g, '').replace(/\W+/g, '-') | ||
} |
'use strict' | ||
var gitHosts = require('./git-host-info.js') | ||
var extend = Object.assign || require('util')._extend | ||
@@ -26,4 +25,5 @@ var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) { | ||
if (!template) return | ||
var vars = extend({}, opts) | ||
opts = extend(extend({}, this.opts), opts) | ||
var vars = Object.assign({}, opts) | ||
vars.path = vars.path ? vars.path.replace(/^[/]+/g, '') : '' | ||
opts = Object.assign({}, this.opts, opts) | ||
var self = this | ||
@@ -35,2 +35,4 @@ Object.keys(this).forEach(function (key) { | ||
var rawComittish = vars.committish | ||
var rawFragment = vars.fragment | ||
var rawPath = vars.path | ||
Object.keys(vars).forEach(function (key) { | ||
@@ -40,2 +42,6 @@ vars[key] = encodeURIComponent(vars[key]) | ||
vars['auth@'] = rawAuth ? rawAuth + '@' : '' | ||
vars['#fragment'] = rawFragment ? '#' + this.hashformat(rawFragment) : '' | ||
vars.fragment = vars.fragment ? vars.fragment : '' | ||
vars['#path'] = rawPath ? '#' + this.hashformat(rawPath) : '' | ||
vars['/path'] = vars.path ? '/' + vars.path : '' | ||
if (opts.noCommittish) { | ||
@@ -73,4 +79,15 @@ vars['#committish'] = '' | ||
GitHost.prototype.browse = function (opts) { | ||
return this._fill(this.browsetemplate, opts) | ||
GitHost.prototype.browse = function (P, F, opts) { | ||
if (typeof P === 'string') { | ||
if (typeof F !== 'string') { | ||
opts = F | ||
F = null | ||
} | ||
return this._fill(this.browsefiletemplate, Object.assign({ | ||
fragment: F, | ||
path: P | ||
}, opts)) | ||
} else { | ||
return this._fill(this.browsetemplate, P) | ||
} | ||
} | ||
@@ -107,5 +124,3 @@ | ||
GitHost.prototype.file = function (P, opts) { | ||
return this._fill(this.filetemplate, extend({ | ||
path: P.replace(/^[/]+/g, '') | ||
}, opts)) | ||
return this._fill(this.filetemplate, Object.assign({ path: P }, opts)) | ||
} | ||
@@ -112,0 +127,0 @@ |
{ | ||
"name": "hosted-git-info", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab", | ||
@@ -16,2 +16,5 @@ "main": "index.js", | ||
], | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"author": "Rebecca Turner <me@re-becca.org> (http://re-becca.org)", | ||
@@ -24,6 +27,11 @@ "license": "ISC", | ||
"scripts": { | ||
"test": "standard && tap -J --coverage test/*.js" | ||
"prerelease": "npm t", | ||
"postrelease": "npm publish && git push --follow-tags", | ||
"pretest": "standard", | ||
"release": "standard-version -s", | ||
"test": "tap -J --nyc-arg=--all --coverage test" | ||
}, | ||
"devDependencies": { | ||
"standard": "^9.0.2", | ||
"standard-version": "^4.3.0", | ||
"tap": "^10.3.0" | ||
@@ -30,0 +38,0 @@ }, |
@@ -80,5 +80,7 @@ # hosted-git-info | ||
* info.browse(opts) | ||
* info.browse(path, fragment, opts) | ||
eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0` | ||
eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0`, | ||
`https://github.com/npm/hosted-git-info/tree/v1.2.0/package.json`, | ||
`https://github.com/npm/hosted-git-info/tree/v1.2.0/REAMDE.md#supported-hosts` | ||
@@ -133,2 +135,1 @@ * info.bugs(opts) | ||
additional hosts welcome. | ||
18091
7
297
134
3