node/deps/npm/node_modules/npm-registry-client/lib/whoami.js

22 lines
666 B
JavaScript
Raw Normal View History

2014-09-25 05:41:07 +08:00
module.exports = whoami
var url = require("url")
, assert = require("assert")
2014-09-25 05:41:07 +08:00
function whoami (uri, params, cb) {
assert(typeof uri === "string", "must pass registry URI to whoami")
assert(params && typeof params === "object", "must pass params to whoami")
assert(typeof cb === "function", "must pass callback to whoami")
2014-09-25 05:41:07 +08:00
var auth = params.auth
assert(auth && typeof auth === "object", "must pass auth to whoami")
if (auth.username) return process.nextTick(cb.bind(this, null, auth.username))
this.request(url.resolve(uri, "-/whoami"), { auth : auth }, function (er, userdata) {
2014-09-25 05:41:07 +08:00
if (er) return cb(er)
cb(null, userdata.username)
})
}