-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 1018 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* is-missing <https://github.com/tunnckoCore/is-missing>
*
* Copyright (c) 2015 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/
'use strict'
var got = require('gh-got')
var fmt = require('util').format
var is = require('assertit').is
var re = require('github-short-url-regex')
var npmjs = 'https://www.npmjs.com/package/'
module.exports = function isMissing (name, opts, callback) {
is.string(name)
if (!callback && typeof opts === 'function') {
callback = opts
opts = {}
}
opts = is.kindof.object(opts) ? opts : {}
is.function(callback)
var user = ''
var regex = re()
if (regex.test(name)) {
var match = regex.exec(name)
user = match[1]
name = match[2]
}
var url = user.length
? fmt('repos/%s/%s', user, name)
: name
opts.endpoint = user.length ? false : npmjs
got.get(url, opts, function _callback (err) {
if (err && err.code === 404) {
callback(null, true)
return
}
callback(null, false)
})
}