Skip to content

vweevers/packument

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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