summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/hosted-git-info/git-host.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/hosted-git-info/git-host.js')
-rw-r--r--deps/npm/node_modules/hosted-git-info/git-host.js31
1 files changed, 23 insertions, 8 deletions
diff --git a/deps/npm/node_modules/hosted-git-info/git-host.js b/deps/npm/node_modules/hosted-git-info/git-host.js
index 4c6641bbf7..6b97531ad6 100644
--- a/deps/npm/node_modules/hosted-git-info/git-host.js
+++ b/deps/npm/node_modules/hosted-git-info/git-host.js
@@ -1,6 +1,5 @@
'use strict'
var gitHosts = require('./git-host-info.js')
-var extend = Object.assign || require('util')._extend
var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) {
var gitHostInfo = this
@@ -23,18 +22,25 @@ GitHost.prototype.hash = function () {
GitHost.prototype._fill = function (template, 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
Object.keys(this).forEach(function (key) {
if (self[key] != null && vars[key] == null) vars[key] = self[key]
})
var rawAuth = vars.auth
var rawComittish = vars.committish
+ var rawFragment = vars.fragment
+ var rawPath = vars.path
Object.keys(vars).forEach(function (key) {
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) {
vars['#committish'] = ''
vars['/tree/committish'] = ''
@@ -67,8 +73,19 @@ GitHost.prototype.sshurl = function (opts) {
return this._fill(this.sshurltemplate, opts)
}
-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)
+ }
}
GitHost.prototype.docs = function (opts) {
@@ -100,9 +117,7 @@ GitHost.prototype.tarball = function (opts) {
}
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))
}
GitHost.prototype.getDefaultRepresentation = function () {