New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

packument

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

packument

Fetch package metadata from the npm registry

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
4.5K
-25.82%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

npm

FAQs

Package last updated on 29 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts