https://github.com/vweevers/packument-package
Fetch package metadata of a version from the npm registry.
https://github.com/vweevers/packument-package
npm npm-registry package packument
Last synced: 5 months ago
JSON representation
Fetch package metadata of a version from the npm registry.
- Host: GitHub
- URL: https://github.com/vweevers/packument-package
- Owner: vweevers
- License: mit
- Created: 2018-04-28T14:14:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-01T20:14:18.000Z (over 2 years ago)
- Last Synced: 2025-10-27T04:39:07.232Z (8 months ago)
- Topics: npm, npm-registry, package, packument
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# packument-package
**Fetch package metadata of a version from the npm registry. If you need metadata of all versions, use [`packument`](https://www.npmjs.org/package/packument).**
[](https://www.npmjs.com/package/packument-package)
[](https://www.npmjs.com/package/packument-package)
[](https://github.com/vweevers/packument-package/actions/workflows/test.yml)
[](https://standardjs.com)
## example
```js
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`](https://www.npmjs.org/package/packument).
## `getPackage = getPackage.factory(packument, opts)`
Preconfigure the function. Useful for setting defaults or adding a cache:
```js
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](https://npmjs.org) do:
```
npm install packument-package
```
## license
[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers