Skip to content

Commit

Permalink
feat: give these objects a name
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
isaacs committed Aug 4, 2019
1 parent a5a91ac commit 60abaea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions git-host.js
Expand Up @@ -17,7 +17,8 @@ var extend = Object.assign || function _extend (target, source) {
return target
}

var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) {
module.exports = GitHost
function GitHost (type, user, auth, project, committish, defaultRepresentation, opts) {
var gitHostInfo = this
gitHostInfo.type = type
Object.keys(gitHosts[type]).forEach(function (key) {
Expand All @@ -30,7 +31,6 @@ var GitHost = module.exports = function (type, user, auth, project, committish,
gitHostInfo.default = defaultRepresentation
gitHostInfo.opts = opts || {}
}
GitHost.prototype = {}

GitHost.prototype.hash = function () {
return this.committish ? '#' + this.committish : ''
Expand Down
3 changes: 3 additions & 0 deletions test/basic.js
Expand Up @@ -3,6 +3,9 @@ var HostedGit = require('../index')
var test = require('tap').test

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

0 comments on commit 60abaea

Please sign in to comment.