Welcome to mirror list, hosted at ThFree Co, Russian Federation.

stars.js « lib « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c09ca6003ea146f17e479ef313bf0f528a90b39a (plain)
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
const log = require('npmlog')
const fetch = require('npm-registry-fetch')

const npm = require('./npm.js')
const output = require('./utils/output.js')
const getIdentity = require('./utils/get-identity.js')
const usageUtil = require('./utils/usage.js')
const completion = require('./utils/completion/none.js')

const usage = usageUtil('stars', 'npm stars [<user>]')

const cmd = (args, cb) => stars(args).then(() => cb()).catch(cb)

const stars = (args) => {
  return stars_(args).catch(er => {
    if (er.code === 'ENEEDAUTH')
      log.warn('stars', 'auth is required to look up your username')

    throw er
  })
}

const stars_ = async ([user = getIdentity(npm.flatOptions)]) => {
  const { rows } = await fetch.json('/-/_view/starredByUser', {
    ...npm.flatOptions,
    query: { key: `"${await user}"` },
  })

  if (rows.length === 0)
    log.warn('stars', 'user has not starred any packages')

  for (const row of rows)
    output(row.value)
}

module.exports = Object.assign(cmd, { usage, completion })