Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

get-pkg

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-pkg - npm Package Compare versions

Comparing version
0.3.0
to
1.0.0
+25
-22
index.js
/*!
* get-pkgs <https://github.com/jonschlinkert/get-pkgs>
* get-pkg <https://github.com/jonschlinkert/get-pkg>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
* Copyright (c) 2014-present, Jon Schlinkert.
* Released under the MIT License.
*/

@@ -10,3 +10,3 @@

var request = require('min-request');
const request = require('axios');

@@ -18,2 +18,3 @@ module.exports = function getPkg(name, version, cb) {

}
if (isScoped(name)) {

@@ -26,21 +27,23 @@ name = '@' + encodeURIComponent(name.slice(1));

var url = 'https://registry.npmjs.org/' + name + '/';
const promise = request.get(`https://registry.npmjs.org/${name}/${version}`)
.then(res => res.data)
.catch(err => {
if (err.response.status === 500) {
return Promise.reject(new Error(err.response.status));
}
if (err.response.status === 404) {
const error = new Error('document not found');
error.code = err.response.status;
error.pkgName = name;
return Promise.reject(error);
}
return Promise.reject(err);
});
request(url + version, {}, function(err, res) {
if (err) return cb(err);
if (res.statusCode === 500) {
return cb(new Error(res.statusMessage));
}
if (res.statusCode === 404) {
var error = new Error('document not found');
error.code = res.statusCode;
error.pkgName = name;
return cb(error);
}
var pkg = JSON.parse(res.body);
if (pkg.error && pkg.reason) {
return cb(new Error(pkg.reason));
}
cb(null, pkg);
});
if (typeof cb === 'function') {
promise.then(res => cb(null, res)).catch(cb);
return;
}
return promise;
};

@@ -47,0 +50,0 @@

The MIT License (MIT)
Copyright (c) 2014-2016, Jon Schlinkert.
Copyright (c) 2014-present, Jon Schlinkert.

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "get-pkg",
"description": "Get the package.json for a project from npm.",
"version": "0.3.0",
"version": "1.0.0",
"homepage": "https://github.com/jonschlinkert/get-pkg",

@@ -16,5 +16,2 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"main": "index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {

@@ -24,7 +21,7 @@ "test": "mocha"

"dependencies": {
"min-request": "^1.4.1"
"axios": "^0.18.0"
},
"devDependencies": {
"gulp-format-md": "^0.1.7",
"mocha": "^2.4.5"
"gulp-format-md": "^1.0.0",
"mocha": "^5.2.0"
},

@@ -59,4 +56,3 @@ "keywords": [

"reflinks": [
"get-pkgs",
"verb"
"get-pkgs"
],

@@ -63,0 +59,0 @@ "lint": {

+52
-28

@@ -1,5 +0,7 @@

# get-pkg [![NPM version](https://img.shields.io/npm/v/get-pkg.svg?style=flat)](https://www.npmjs.com/package/get-pkg) [![NPM downloads](https://img.shields.io/npm/dm/get-pkg.svg?style=flat)](https://npmjs.org/package/get-pkg) [![Build Status](https://img.shields.io/travis/jonschlinkert/get-pkg.svg?style=flat)](https://travis-ci.org/jonschlinkert/get-pkg)
# get-pkg [![NPM version](https://img.shields.io/npm/v/get-pkg.svg?style=flat)](https://www.npmjs.com/package/get-pkg) [![NPM monthly downloads](https://img.shields.io/npm/dm/get-pkg.svg?style=flat)](https://npmjs.org/package/get-pkg) [![NPM total downloads](https://img.shields.io/npm/dt/get-pkg.svg?style=flat)](https://npmjs.org/package/get-pkg) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/get-pkg.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/get-pkg)
> Get the package.json for a project from npm.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install

@@ -10,6 +12,6 @@

```sh
$ npm install get-pkg --save
$ npm install --save get-pkg
```
This code was pulled out of [get-pkgs](https://github.com/jonschlinkert/get-pkgs).
Also see [get-pkgs](https://github.com/jonschlinkert/get-pkgs), if you need to get more than one `package.json`.

@@ -19,56 +21,78 @@ ## Usage

```js
var getPkg = require('get-pkg');
const getPkg = require('get-pkg');
// takes a callback
getPkg('generate', function(err, pkg) {
console.log(pkg);
});
// or returns a promise
getPkg('generate')
.then(pkg => console.log(pkg))
.catch(console.error);
```
## Related projects
## About
You might also be interested in these projects:
<details>
<summary><strong>Contributing</strong></summary>
* [get-pkgs](https://www.npmjs.com/package/get-pkgs): Get the package.json for an array of repos from the npm registry, optionally filtering properties… [more](https://www.npmjs.com/package/get-pkgs) | [homepage](https://github.com/jonschlinkert/get-pkgs)
* [github-base](https://www.npmjs.com/package/github-base): Base methods for creating node.js apps that work with the GitHub API. | [homepage](https://github.com/jonschlinkert/github-base)
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
## Contributing
</details>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/get-pkg/issues/new).
<details>
<summary><strong>Running Tests</strong></summary>
## Building docs
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
Generate readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install verb && npm run docs
$ npm install && npm test
```
Or, if [verb](https://github.com/verbose/verb) is installed globally:
</details>
```sh
$ verb
```
<details>
<summary><strong>Building docs</strong></summary>
## Running tests
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
Install dev dependencies:
To generate the readme, run the following command:
```sh
$ npm install -d && npm test
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
## Author
</details>
### Related projects
You might also be interested in these projects:
* [get-pkgs](https://www.npmjs.com/package/get-pkgs): Get the package.json for an array of repos from the npm registry, optionally filtering properties… [more](https://github.com/jonschlinkert/get-pkgs) | [homepage](https://github.com/jonschlinkert/get-pkgs "Get the package.json for an array of repos from the npm registry, optionally filtering properties using glob patterns.")
* [github-base](https://www.npmjs.com/package/github-base): JavaScript wrapper that greatly simplifies working with GitHub's API. | [homepage](https://github.com/jonschlinkert/github-base "JavaScript wrapper that greatly simplifies working with GitHub's API.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 9 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [doowb](https://github.com/doowb) |
| 1 | [joakimbeng](https://github.com/joakimbeng) |
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
## License
### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/get-pkg/blob/master/LICENSE).
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 11, 2016._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 28, 2018._