"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm-registry-client/lib/star.js" (8 Mar 2017, 1402 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 module.exports = star
    2 
    3 var assert = require('assert')
    4 
    5 function star (uri, params, cb) {
    6   assert(typeof uri === 'string', 'must pass registry URI to star')
    7   assert(params && typeof params === 'object', 'must pass params to star')
    8   assert(typeof cb === 'function', 'must pass callback to star')
    9 
   10   var starred = !!params.starred
   11 
   12   var auth = params.auth
   13   assert(auth && typeof auth === 'object', 'must pass auth to star')
   14   if (!(auth.token || (auth.password && auth.username && auth.email))) {
   15     var er = new Error('Must be logged in to star/unstar packages')
   16     er.code = 'ENEEDAUTH'
   17     return cb(er)
   18   }
   19 
   20   var client = this
   21   this.request(uri + '?write=true', { auth: auth }, function (er, fullData) {
   22     if (er) return cb(er)
   23 
   24     client.whoami(uri, params, function (er, username) {
   25       if (er) return cb(er)
   26 
   27       var data = {
   28         _id: fullData._id,
   29         _rev: fullData._rev,
   30         users: fullData.users || {}
   31       }
   32 
   33       if (starred) {
   34         client.log.info('starring', data._id)
   35         data.users[username] = true
   36         client.log.verbose('starring', data)
   37       } else {
   38         delete data.users[username]
   39         client.log.info('unstarring', data._id)
   40         client.log.verbose('unstarring', data)
   41       }
   42 
   43       var options = {
   44         method: 'PUT',
   45         body: data,
   46         auth: auth
   47       }
   48       return client.request(uri, options, cb)
   49     })
   50   })
   51 }