Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 902727e

Browse files
committed
src: npm-registry-client complies with 'standard'
1 parent 11fdb66 commit 902727e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1982
-2022
lines changed

index.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@
22

33
module.exports = RegClient
44

5-
var join = require("path").join
6-
, fs = require("graceful-fs")
5+
var join = require('path').join
6+
var fs = require('graceful-fs')
77

88
var npmlog
99
try {
10-
npmlog = require("npmlog")
11-
}
12-
catch (er) {
10+
npmlog = require('npmlog')
11+
} catch (er) {
1312
npmlog = {
14-
error : noop,
15-
warn : noop,
16-
info : noop,
17-
verbose : noop,
18-
silly : noop,
19-
http : noop,
20-
pause : noop,
21-
resume : noop
13+
error: noop,
14+
warn: noop,
15+
info: noop,
16+
verbose: noop,
17+
silly: noop,
18+
http: noop,
19+
pause: noop,
20+
resume: noop
2221
}
2322
}
2423

@@ -36,20 +35,20 @@ function RegClient (config) {
3635
if (this.config.ssl.strict === undefined) this.config.ssl.strict = true
3736

3837
this.config.retry = this.config.retry || {}
39-
if (typeof this.config.retry.retries !== "number") this.config.retry.retries = 2
40-
if (typeof this.config.retry.factor !== "number") this.config.retry.factor = 10
41-
if (typeof this.config.retry.minTimeout !== "number") this.config.retry.minTimeout = 10000
42-
if (typeof this.config.retry.maxTimeout !== "number") this.config.retry.maxTimeout = 60000
38+
if (typeof this.config.retry.retries !== 'number') this.config.retry.retries = 2
39+
if (typeof this.config.retry.factor !== 'number') this.config.retry.factor = 10
40+
if (typeof this.config.retry.minTimeout !== 'number') this.config.retry.minTimeout = 10000
41+
if (typeof this.config.retry.maxTimeout !== 'number') this.config.retry.maxTimeout = 60000
4342

44-
this.config.userAgent = this.config.userAgent || "node/" + process.version
45-
this.config.defaultTag = this.config.defaultTag || "latest"
43+
this.config.userAgent = this.config.userAgent || 'node/' + process.version
44+
this.config.defaultTag = this.config.defaultTag || 'latest'
4645

4746
this.log = this.config.log || npmlog
4847
delete this.config.log
4948

5049
var client = this
51-
fs.readdirSync(join(__dirname, "lib")).forEach(function (f) {
52-
var entry = join(__dirname, "lib", f)
50+
fs.readdirSync(join(__dirname, 'lib')).forEach(function (f) {
51+
var entry = join(__dirname, 'lib', f)
5352

5453
// lib/group-name/operation.js -> client.groupName.operation
5554
var stat = fs.statSync(entry)
@@ -62,14 +61,14 @@ function RegClient (config) {
6261
// keep client.groupName.operation from stomping client.operation
6362
client[groupName] = Object.create(client)
6463
}
65-
var name = f.replace(/\.js$/, "").replace(/-([a-z])/, dashToCamel)
64+
var name = f.replace(/\.js$/, '').replace(/-([a-z])/, dashToCamel)
6665
client[groupName][name] = require(join(entry, f))
6766
})
6867
return
6968
}
7069

7170
if (!f.match(/\.js$/)) return
72-
var name = f.replace(/\.js$/, "").replace(/-([a-z])/, dashToCamel)
71+
var name = f.replace(/\.js$/, '').replace(/-([a-z])/, dashToCamel)
7372
client[name] = require(entry)
7473
})
7574
}

lib/access.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
module.exports = access
22

3-
var assert = require("assert")
3+
var assert = require('assert')
44

55
function access (uri, params, cb) {
6-
assert(typeof uri === "string", "must pass registry URI to access")
7-
assert(params && typeof params === "object", "must pass params to access")
8-
assert(typeof cb === "function", "muss pass callback to access")
6+
assert(typeof uri === 'string', 'must pass registry URI to access')
7+
assert(params && typeof params === 'object', 'must pass params to access')
8+
assert(typeof cb === 'function', 'muss pass callback to access')
99

10-
assert(typeof params.level === "string", "must pass level to access")
10+
assert(typeof params.level === 'string', 'must pass level to access')
1111
assert(
12-
["public", "restricted"].indexOf(params.level) !== -1,
12+
['public', 'restricted'].indexOf(params.level) !== -1,
1313
"access level must be either 'public' or 'restricted'"
1414
)
1515
assert(
16-
params.auth && typeof params.auth === "object",
17-
"must pass auth to access"
16+
params.auth && typeof params.auth === 'object',
17+
'must pass auth to access'
1818
)
1919

2020
var body = {
21-
access : params.level
21+
access: params.level
2222
}
2323

2424
var options = {
25-
method : "POST",
26-
body : JSON.stringify(body),
27-
auth : params.auth
25+
method: 'POST',
26+
body: JSON.stringify(body),
27+
auth: params.auth
2828
}
2929
this.request(uri, options, cb)
3030
}

lib/adduser.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
module.exports = adduser
22

3-
var url = require("url")
4-
var assert = require("assert")
3+
var url = require('url')
4+
var assert = require('assert')
55

66
function adduser (uri, params, cb) {
7-
assert(typeof uri === "string", "must pass registry URI to adduser")
7+
assert(typeof uri === 'string', 'must pass registry URI to adduser')
88
assert(
9-
params && typeof params === "object",
10-
"must pass params to adduser"
9+
params && typeof params === 'object',
10+
'must pass params to adduser'
1111
)
12-
assert(typeof cb === "function", "must pass callback to adduser")
12+
assert(typeof cb === 'function', 'must pass callback to adduser')
1313

14-
assert(params.auth && typeof params.auth, "must pass auth to adduser")
14+
assert(params.auth && typeof params.auth, 'must pass auth to adduser')
1515
var auth = params.auth
16-
assert(typeof auth.username === "string", "must include username in auth")
17-
assert(typeof auth.password === "string", "must include password in auth")
18-
assert(typeof auth.email === "string", "must include email in auth")
16+
assert(typeof auth.username === 'string', 'must include username in auth')
17+
assert(typeof auth.password === 'string', 'must include password in auth')
18+
assert(typeof auth.email === 'string', 'must include email in auth')
1919

2020
// normalize registry URL
21-
if (uri.slice(-1) !== "/") uri += "/"
21+
if (uri.slice(-1) !== '/') uri += '/'
2222

2323
var username = auth.username.trim()
2424
var password = auth.password.trim()
2525
var email = auth.email.trim()
2626

2727
// validation
28-
if (!username) return cb(new Error("No username supplied."))
29-
if (!password) return cb(new Error("No password supplied."))
30-
if (!email) return cb(new Error("No email address supplied."))
28+
if (!username) return cb(new Error('No username supplied.'))
29+
if (!password) return cb(new Error('No password supplied.'))
30+
if (!email) return cb(new Error('No email address supplied.'))
3131
if (!email.match(/^[^@]+@[^\.]+\.[^\.]+/)) {
32-
return cb(new Error("Please use a real email address."))
32+
return cb(new Error('Please use a real email address.'))
3333
}
3434

3535
var userobj = {
36-
_id : "org.couchdb.user:"+username,
37-
name : username,
38-
password : password,
39-
email : email,
40-
type : "user",
41-
roles : [],
42-
date : new Date().toISOString()
36+
_id: 'org.couchdb.user:' + username,
37+
name: username,
38+
password: password,
39+
email: email,
40+
type: 'user',
41+
roles: [],
42+
date: new Date().toISOString()
4343
}
4444

4545
var token = this.config.couchToken
@@ -48,22 +48,22 @@ function adduser (uri, params, cb) {
4848
cb = done.call(this, token, cb)
4949

5050
var logObj = Object.keys(userobj).map(function (k) {
51-
if (k === "password") return [k, "XXXXX"]
51+
if (k === 'password') return [k, 'XXXXX']
5252
return [k, userobj[k]]
5353
}).reduce(function (s, kv) {
5454
s[kv[0]] = kv[1]
5555
return s
5656
}, {})
5757

58-
this.log.verbose("adduser", "before first PUT", logObj)
58+
this.log.verbose('adduser', 'before first PUT', logObj)
5959

6060
var client = this
6161

62-
uri = url.resolve(uri, "-/user/org.couchdb.user:" + encodeURIComponent(username))
62+
uri = url.resolve(uri, '-/user/org.couchdb.user:' + encodeURIComponent(username))
6363
var options = {
64-
method : "PUT",
65-
body : userobj,
66-
auth : auth
64+
method: 'PUT',
65+
body: userobj,
66+
auth: auth
6767
}
6868
this.request(
6969
uri,
@@ -73,21 +73,21 @@ function adduser (uri, params, cb) {
7373
return cb(error, data, json, response)
7474
}
7575

76-
client.log.verbose("adduser", "update existing user")
76+
client.log.verbose('adduser', 'update existing user')
7777
return client.request(
78-
uri+"?write=true",
79-
{ body : userobj, auth : auth },
78+
uri + '?write=true',
79+
{ body: userobj, auth: auth },
8080
function (er, data, json, response) {
8181
if (er || data.error) {
8282
return cb(er, data, json, response)
8383
}
8484
Object.keys(data).forEach(function (k) {
85-
if (!userobj[k] || k === "roles") {
85+
if (!userobj[k] || k === 'roles') {
8686
userobj[k] = data[k]
8787
}
8888
})
89-
client.log.verbose("adduser", "userobj", logObj)
90-
client.request(uri+"/-rev/"+userobj._rev, options, cb)
89+
client.log.verbose('adduser', 'userobj', logObj)
90+
client.request(uri + '/-rev/' + userobj._rev, options, cb)
9191
}
9292
)
9393
}
@@ -107,19 +107,19 @@ function adduser (uri, params, cb) {
107107
}
108108
}
109109

110-
client.log.verbose("adduser", "back", [error, data, json])
110+
client.log.verbose('adduser', 'back', [error, data, json])
111111
if (!error) {
112112
error = new Error(
113-
(response && response.statusCode || "") + " " +
114-
"Could not create user\n" + JSON.stringify(data)
113+
(response && response.statusCode || '') + ' ' +
114+
'Could not create user\n' + JSON.stringify(data)
115115
)
116116
}
117117

118118
if (response && (response.statusCode === 401 || response.statusCode === 403)) {
119-
client.log.warn("adduser", "Incorrect username or password\n" +
120-
"You can reset your account by visiting:\n" +
121-
"\n" +
122-
" https://npmjs.org/forgot\n")
119+
client.log.warn('adduser', 'Incorrect username or password\n' +
120+
'You can reset your account by visiting:\n' +
121+
'\n' +
122+
' https://npmjs.org/forgot\n')
123123
}
124124

125125
return cb(error)

lib/attempt.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
var retry = require("retry")
1+
var retry = require('retry')
22

33
module.exports = attempt
44

5-
function attempt(cb) {
5+
function attempt (cb) {
66
// Tuned to spread 3 attempts over about a minute.
77
// See formula at <https://github.com/tim-kos/node-retry>.
88
var operation = retry.operation(this.config.retry)
99

1010
var client = this
1111
operation.attempt(function (currentAttempt) {
12-
client.log.info("attempt", "registry request try #"+currentAttempt+
13-
" at "+(new Date()).toLocaleTimeString())
12+
client.log.info(
13+
'attempt',
14+
'registry request try #' + currentAttempt +
15+
' at ' + (new Date()).toLocaleTimeString()
16+
)
1417

1518
cb(operation)
1619
})

lib/authify.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module.exports = authify
22

33
function authify (authed, parsed, headers, credentials) {
44
if (credentials && credentials.token) {
5-
this.log.verbose("request", "using bearer token for auth")
6-
headers.authorization = "Bearer " + credentials.token
5+
this.log.verbose('request', 'using bearer token for auth')
6+
headers.authorization = 'Bearer ' + credentials.token
77

88
return null
99
}
@@ -12,11 +12,10 @@ function authify (authed, parsed, headers, credentials) {
1212
if (credentials && credentials.username && credentials.password) {
1313
var username = encodeURIComponent(credentials.username)
1414
var password = encodeURIComponent(credentials.password)
15-
parsed.auth = username + ":" + password
16-
}
17-
else {
15+
parsed.auth = username + ':' + password
16+
} else {
1817
return new Error(
19-
"This request requires auth credentials. Run `npm login` and repeat the request."
18+
'This request requires auth credentials. Run `npm login` and repeat the request.'
2019
)
2120
}
2221
}

lib/deprecate.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
module.exports = deprecate
22

3-
var assert = require("assert")
4-
var url = require("url")
5-
var semver = require("semver")
3+
var assert = require('assert')
4+
var url = require('url')
5+
var semver = require('semver')
66

77
function deprecate (uri, params, cb) {
8-
assert(typeof uri === "string", "must pass registry URI to deprecate")
9-
assert(params && typeof params === "object", "must pass params to deprecate")
10-
assert(typeof cb === "function", "must pass callback to deprecate")
8+
assert(typeof uri === 'string', 'must pass registry URI to deprecate')
9+
assert(params && typeof params === 'object', 'must pass params to deprecate')
10+
assert(typeof cb === 'function', 'must pass callback to deprecate')
1111

12-
assert(typeof params.version === "string", "must pass version to deprecate")
13-
assert(typeof params.message === "string", "must pass message to deprecate")
12+
assert(typeof params.version === 'string', 'must pass version to deprecate')
13+
assert(typeof params.message === 'string', 'must pass message to deprecate')
1414
assert(
15-
params.auth && typeof params.auth === "object",
16-
"must pass auth to deprecate"
15+
params.auth && typeof params.auth === 'object',
16+
'must pass auth to deprecate'
1717
)
1818

1919
var version = params.version
2020
var message = params.message
2121
var auth = params.auth
2222

2323
if (semver.validRange(version) === null) {
24-
return cb(new Error("invalid version range: "+version))
24+
return cb(new Error('invalid version range: ' + version))
2525
}
2626

27-
this.get(uri + "?write=true", { auth : auth }, function (er, data) {
27+
this.get(uri + '?write=true', { auth: auth }, function (er, data) {
2828
if (er) return cb(er)
2929
// filter all the versions that match
3030
Object.keys(data.versions).filter(function (v) {
@@ -34,9 +34,9 @@ function deprecate (uri, params, cb) {
3434
})
3535
// now update the doc on the registry
3636
var options = {
37-
method : "PUT",
38-
body : data,
39-
auth : auth
37+
method: 'PUT',
38+
body: data,
39+
auth: auth
4040
}
4141
this.request(url.resolve(uri, data._id), options, cb)
4242
}.bind(this))

0 commit comments

Comments
 (0)