Skip to content

Commit 60abaea

Browse files
committed
feat: give these objects a name
It's much less friendly to use this library (and those that depend on it, like npm-package-arg) when it's not clear whether the returned value is a member of a class (which likely has some useful methods) or just an object full of data that the user is expected to know what to do with. This is especially vexing since some of this sort of data is saved to various lock and config files, so _sometimes_ a thing that looks suspiciously like a GitHost object actually is just a plain old JS object.
1 parent a5a91ac commit 60abaea

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

git-host.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ var extend = Object.assign || function _extend (target, source) {
1717
return target
1818
}
1919

20-
var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) {
20+
module.exports = GitHost
21+
function GitHost (type, user, auth, project, committish, defaultRepresentation, opts) {
2122
var gitHostInfo = this
2223
gitHostInfo.type = type
2324
Object.keys(gitHosts[type]).forEach(function (key) {
@@ -30,7 +31,6 @@ var GitHost = module.exports = function (type, user, auth, project, committish,
3031
gitHostInfo.default = defaultRepresentation
3132
gitHostInfo.opts = opts || {}
3233
}
33-
GitHost.prototype = {}
3434

3535
GitHost.prototype.hash = function () {
3636
return this.committish ? '#' + this.committish : ''

test/basic.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ var HostedGit = require('../index')
33
var test = require('tap').test
44

55
test('basic', function (t) {
6+
const h = HostedGit.fromUrl('github:user/project')
7+
t.is(h.constructor, HostedGit)
8+
t.is(h.constructor.name, 'GitHost')
69
t.is(HostedGit.fromUrl('https://google.com'), undefined, 'null on failure')
710
t.is(HostedGit.fromUrl('https://github.com/abc/def').getDefaultRepresentation(), 'https', 'match https urls')
811
t.is(HostedGit.fromUrl('https://github.com/abc/def/').getDefaultRepresentation(), 'https', 'match URLs with a trailing slash')

0 commit comments

Comments
 (0)