Socket
Socket
Sign inDemoInstall

package-json

Package Overview
Dependencies
22
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 4.0.0

20

index.js

@@ -8,3 +8,3 @@ 'use strict';

module.exports = (name, version) => {
module.exports = (name, opts) => {
const scope = name.split('/')[0];

@@ -14,4 +14,15 @@ const regUrl = registryUrl(scope);

const authInfo = registryAuthToken(regUrl);
const headers = {};
opts = Object.assign({
version: 'latest'
}, opts);
const headers = {
accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
};
if (opts.fullMetadata) {
delete headers.accept;
}
if (authInfo) {

@@ -24,3 +35,8 @@ headers.authorization = `${authInfo.type} ${authInfo.token}`;

let data = res.body;
let version = opts.version;
if (opts.allVersions) {
return data;
}
if (data['dist-tags'][version]) {

@@ -27,0 +43,0 @@ data = data.versions[data['dist-tags'][version]];

4

package.json
{
"name": "package-json",
"version": "3.1.0",
"description": "Get the package.json of a package from the npm registry",
"version": "4.0.0",
"description": "Get metadata of a package from the npm registry",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": "sindresorhus/package-json",

# package-json [![Build Status](https://travis-ci.org/sindresorhus/package-json.svg?branch=master)](https://travis-ci.org/sindresorhus/package-json)
> Get the package.json of a package from the npm registry
> Get metadata of a package from the npm registry

@@ -18,11 +18,11 @@

packageJson('pageres', 'latest').then(json => {
packageJson('ava').then(json => {
console.log(json);
//=> {name: 'pageres', ...}
//=> {name: 'ava', ...}
});
// Also works with scoped packages
packageJson('@company/package', 'latest').then(json => {
packageJson('@sindresorhus/df').then(json => {
console.log(json);
//=> {name: 'package', ...}
//=> {name: '@sindresorhus/df', ...}
});

@@ -34,8 +34,23 @@ ```

### packageJson(name, [version])
### packageJson(name, [options])
You can optionally specify a version (e.g. `1.0.0`) or a [dist tag](https://docs.npmjs.com/cli/dist-tag) such as `latest`. If you don't specify a version you'll get the [main entry](http://registry.npmjs.org/pageres/) containing all versions.
#### name
The version can also be in any format supported by the [semver](https://www.npmjs.com/package/semver) module. For example:
Type: `string`
Name of the package.
#### options
Type: `Object`
##### version
Type: `string`<br>
Default: `latest`
Package version such as `1.0.0` or a [dist tag](https://docs.npmjs.com/cli/dist-tag) such as `latest`.
The version can also be in any format supported by the [semver](https://github.com/npm/node-semver) module. For example:
- `1` - get the latest `1.x.x`

@@ -46,3 +61,17 @@ - `1.2` - get the latest `1.2.x`

##### fullMetadata
Type: `boolean`<br>
Default: `false`
By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
##### allVersions
Type: `boolean`<br>
Default: `false`
Return the [main entry](https://registry.npmjs.org/ava) containing all versions.
## Authentication

@@ -49,0 +78,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc