Socket
Socket
Sign inDemoInstall

package-json

Package Overview
Dependencies
31
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

37

index.js

@@ -5,4 +5,20 @@ 'use strict';

function get(url, cb) {
got(url, {json: true}, function (err, data) {
if (err && err.code === 404) {
cb(new Error('Package or version doesn\'t exist'));
return;
}
if (err) {
cb(err);
return;
}
cb(null, data);
});
}
module.exports = function (name, version, cb) {
var url = registryUrl(name.split('/')[0]);
var url = registryUrl(name.split('/')[0]) + name + '/';

@@ -14,8 +30,10 @@ if (typeof version !== 'string') {

got(url + encodeURIComponent(name) + '/' + version, function (err, data) {
if (err && err.code === 404) {
cb(new Error('Package or version doesn\'t exist'));
return;
}
get(url + version, cb);
};
module.exports.field = function (name, field, cb) {
var url = registryUrl(name.split('/')[0]) +
'-/by-field/?key=%22' + name + '%22&field=' + field;
get(url, function (err, res) {
if (err) {

@@ -26,4 +44,9 @@ cb(err);

cb(null, JSON.parse(data));
if (Object.keys(res).length === 0) {
cb(new Error('Field `' + field + '` doesn\'t exist'));
return;
}
cb(null, res[name][field]);
});
};

4

package.json
{
"name": "package-json",
"version": "1.1.0",
"version": "1.2.0",
"description": "Get the package.json of a package from the npm registry",

@@ -33,3 +33,3 @@ "license": "MIT",

"dependencies": {
"got": "^2.4.0",
"got": "^3.2.0",
"registry-url": "^3.0.0"

@@ -36,0 +36,0 @@ },

@@ -28,2 +28,7 @@ # package-json [![Build Status](https://travis-ci.org/sindresorhus/package-json.svg?branch=master)](https://travis-ci.org/sindresorhus/package-json)

});
packageJson.field('pageres', 'description', function (err, field) {
console.log(field);
//=> 'Capture website screenshots'
});
```

@@ -39,6 +44,12 @@

### packageJson.field(name, field, callback)
Get a specific field in the `package.json`.
## Related
- [`npm-keyword`](https://github.com/sindresorhus/npm-keyword) - Get a list of npm packages with a certain keyword
- [npm-keyword](https://github.com/sindresorhus/npm-keyword) - Get a list of npm packages with a certain keyword
- [npm-user](https://github.com/sindresorhus/npm-user) - Get user info of a npm user
- [npm-email](https://github.com/sindresorhus/npm-email) - Get the email of a npm user

@@ -45,0 +56,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