node/deps/npm/node_modules/npm-registry-client/lib/whoami.js
Forrest L Norvell f5b35dbda4 deps: upgrade npm to 2.3.0
* Windows improvements: no more uid is undefined errors, use `%COMSPEC%`
  when set in preference to hardcoded `cmd`, improved handling of Git
  remotes.
* Add caching based on Last-Modified / If-Modified-Since headers in
  addition to Etag-based cache validation.

PR-URL: https://github.com/iojs/io.js/pull/573
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-01-23 23:19:27 +01:00

22 lines
666 B
JavaScript

module.exports = whoami
var url = require("url")
, assert = require("assert")
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")
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) {
if (er) return cb(er)
cb(null, userdata.username)
})
}