packument-package

2.0.0 • Public • Published

packument-package

Fetch package metadata of a version from the npm registry. If you need metadata of all versions, use packument.

npm node Test Standard

example

const getPackage = require('packument-package')

// Defaults to latest
getPackage('levelup', function (err, pkg) {
  if (err) throw err
  console.log(pkg.version)
})

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

getPackage(name[, version || opts], callback)

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

  • version: either a dist tag (latest), version (1.2.3) or range (~1.2.3).

Other options are passed to packument.

getPackage = getPackage.factory(packument, opts)

Preconfigure the function. Useful for setting defaults or adding a cache:

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

getPackage('levelup', '~2.0.2', (err, pkg) => {
  // It will make only one request
})

getPackage('levelup', '^1.3.0', (err, pkg) => {
  // Subsequent calls for the same package are cached
})

install

With npm do:

npm install packument-package

license

MIT © Vincent Weevers

Package Sidebar

Install

npm i packument-package

Weekly Downloads

7

Version

2.0.0

License

MIT

Unpacked Size

5.11 kB

Total Files

4

Last publish

Collaborators

  • vweevers