packument

2.0.0 • Public • Published

packument

Fetch package metadata from the npm registry. Supports scopes and private registries. If you only need the metadata of a specific version, use packument-package.

npm node Test Standard

example

const packument = require('packument')

packument('levelup', (err, result) => {
  if (err) throw err
  console.log(result.versions['2.0.2'].dependencies)
})

packument(name[, opts], callback)

Callback receives an error if any, a packument and response headers. Options:

  • headers: custom headers (you can override any)
  • keepAlive: shortcut for headers: { connection: 'keep-alive' }
  • full: if true, fetch full metadata rather than an abbreviated document.

packument = packument.factory(opts)

Preconfigure the function. For example, to always fetch full metadata:

const packument = require('packument').factory({ full: true })

packument('levelup', (err, result) => {
  if (err) throw err
  console.log(result._rev)
})

Combine it with an in-memory cache:

const memoize = require('thunky-with-args')
const packument = memoize(require('packument').factory({ full: true }))

packument('levelup', (err, result) => {
  // It will make only one request
})

packument('levelup', (err, result) => {
  // Subsequent calls for the same package are cached
})

Reuse that cache in other modules:

const memoize = require('thunky-with-args')
const packument = memoize(require('packument'))
const getPackage = require('packument-package').factory(packument)

getPackage('levelup', '~2.0.0', function (err, pkg) {
  if (err) throw err
  console.log(pkg.version)
})

install

With npm do:

npm install packument

license

MIT © Vincent Weevers

Dependencies (3)

Dev Dependencies (3)

Package Sidebar

Install

npm i packument

Weekly Downloads

2,754

Version

2.0.0

License

MIT

Unpacked Size

5.91 kB

Total Files

4

Last publish

Collaborators

  • vweevers