Socket
Socket
Sign inDemoInstall

npm-api

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-api - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

CHANGELOG.md

5

index.js

@@ -17,2 +17,3 @@ 'use strict';

* ```
* @name NpmApi
* @api public

@@ -54,2 +55,3 @@ */

* @return {Object} `View` instance
* @name .view
* @api public

@@ -80,2 +82,3 @@ */

* @return {Object} `List` instance
* @name .list
* @api public

@@ -114,2 +117,3 @@ */

* @return {Object} Instance of a `Repo` model to work with.
* @name .repo
* @api public

@@ -138,2 +142,3 @@ */

* @return {Object} Instance of a `Maintainer` model to work with.
* @name .maintainer
* @api public

@@ -140,0 +145,0 @@ */

23

lib/list.js
'use strict';
const url = require('url');
const fetch = require('node-fetch');
const utils = require('./utils');

@@ -17,2 +18,3 @@ const config = require('./config');

* @returns {Object} instance of `List`
* @name List
* @api public

@@ -37,18 +39,12 @@ */

* @return {Promise} Results of the query when promise is resolved.
* @name .query
* @api public
*/
query(params = {}) {
return new Promise(async(resolve, reject) => {
utils.request(this.url(params), (err, response, body) => {
if (err) return reject(err);
var res = {};
try {
res = JSON.parse(body);
return resolve(res);
} catch (err) {
return reject(err);
}
});
});
async query(params = {}) {
const response = await fetch(this.url(params));
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json();
}

@@ -61,2 +57,3 @@

* @return {String} formatted url string
* @name .url
* @api public

@@ -63,0 +60,0 @@ */

@@ -13,2 +13,3 @@ 'use strict';

* @param {Object} `store` Cache store instance to use.
* @name BaseModel
* @api public

@@ -15,0 +16,0 @@ */

@@ -15,2 +15,3 @@ 'use strict';

* @param {String} `name` Name of the npm maintainer to get information about.
* @name Maintainer
* @api public

@@ -39,2 +40,3 @@ */

* @return {Promise} Returns array of repository names when promise resolves.
* @name .repos
* @api public

@@ -41,0 +43,0 @@ */

@@ -14,2 +14,3 @@ 'use strict';

* @param {String} `name` Name of the npm repo to get information about.
* @name Repo
* @api public

@@ -37,2 +38,3 @@ */

* @return {Promise} Returns the package.json object when promise resolves.
* @name .package
* @api public

@@ -69,2 +71,3 @@ */

* @return {Promise} Returns the package.json object for the specified version when promise resolves.
* @name .version
* @api public

@@ -97,2 +100,3 @@ */

* @return {Promise} Returns the dependencies object for the specified version when promise resolves.
* @name .dependencies
* @api public

@@ -118,2 +122,3 @@ */

* @return {Promise} Returns the devDependencies object for the specified version when promise resolves.
* @name .devDependencies
* @api public

@@ -140,2 +145,3 @@ */

* @return {Promise} Returns the property for the specified version when promise resolves.
* @name .prop
* @api public

@@ -142,0 +148,0 @@ */

'use strict';
const fetch = require('node-fetch');
const utils = require('./utils');

@@ -14,2 +15,3 @@ const config = require('./config');

* @returns {Object} instance of `Registry`
* @name Registry
* @api public

@@ -31,17 +33,12 @@ */

* @return {Promise} Results of the query when promise is resolved.
* @name .get
* @api public
*/
get(name) {
return new Promise((resolve, reject) => {
utils.request.get(this.url(name), (err, res, body) => {
if (err) return reject(err);
try {
let data = JSON.parse(body);
resolve(data);
} catch (err) {
reject(err);
}
});
});
async get(name) {
const response = await fetch(this.url(name));
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json();
}

@@ -54,2 +51,3 @@

* @return {String} formatted url string
* @name .url
* @api public

@@ -56,0 +54,0 @@ */

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

define('paged', () => require('paged-request'));
define('request', () => require('request'));
define('stats', () => require('download-stats'));
utils.arrayify = val => val ? (Array.isArray(val) ? val : [val]) : [];
'use strict';
const url = require('url');
const fetch = require('node-fetch');
const utils = require('./utils');

@@ -16,2 +17,3 @@ const config = require('./config');

* @returns {Object} instance of `View`
* @name View
* @api public

@@ -39,11 +41,15 @@ */

* @return {Promise} Results of the query when promise is resolved.
* @name .query
* @api public
*/
query(params = {}) {
async query(params = {}) {
const response = await fetch(this.url(params));
if (!response.ok) {
throw new Error(response.statusText);
}
return new Promise((resolve, reject) => {
let items = [];
let header = {};
utils.request(this.url(params))
.once('error', reject)
response.body
.pipe(utils.JSONStream.parse('rows.*'))

@@ -81,2 +87,3 @@ .on('header', (data) => {

* @return {Stream} Streaming results of the query.
* @name .stream
* @api public

@@ -86,4 +93,10 @@ */

stream(params = {}) {
return utils.request(this.url(params))
.pipe(utils.JSONStream.parse('rows.*'));
const stream = utils.JSONStream.parse('rows.*');
fetch(this.url(params)).then(response => {
if (!response.ok) {
throw new Error(response.statusText);
}
response.body.pipe(stream)
}).catch(e => stream.emit('error', e))
return stream;
}

@@ -96,2 +109,3 @@

* @return {String} formatted url string
* @name .url
* @api public

@@ -98,0 +112,0 @@ */

{
"name": "npm-api",
"description": "Base class for retrieving data from the npm registry.",
"version": "1.0.0",
"description": "Node.js library for getting info from NPM’s API",
"version": "1.0.1",
"homepage": "https://github.com/doowb/npm-api",

@@ -70,9 +70,9 @@ "author": "Brian Woodward (https://github.com/doowb)",

"dependencies": {
"JSONStream": "^1.3.5",
"clone-deep": "^4.0.1",
"download-stats": "^0.3.4",
"JSONStream": "^1.3.5",
"moment": "^2.24.0",
"paged-request": "^2.0.1",
"request": "^2.88.0"
"node-fetch": "^2.6.0",
"paged-request": "^2.0.1"
}
}
# npm-api [![NPM version](https://img.shields.io/npm/v/npm-api.svg?style=flat)](https://www.npmjs.com/package/npm-api) [![NPM monthly downloads](https://img.shields.io/npm/dm/npm-api.svg?style=flat)](https://npmjs.org/package/npm-api) [![NPM total downloads](https://img.shields.io/npm/dt/npm-api.svg?style=flat)](https://npmjs.org/package/npm-api) [![Linux Build Status](https://img.shields.io/travis/doowb/npm-api.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/npm-api)
> Base class for retrieving data from the npm registry.
> Node.js library for getting info from NPM’s API

@@ -23,3 +23,3 @@ Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.

### [NpmApi](index.js#L27)
### [NpmApi](index.js#L21)

@@ -31,6 +31,6 @@ NpmApi constructor. Create an instance to work with maintainer and repository information.

```js
var npm = new NpmApi();
let npm = new NpmApi();
```
### [.view](index.js#L65)
### [.view](index.js#L58)

@@ -50,3 +50,3 @@ Create a new instance of `View` or get an existing instance to work with npm couchdb views.

### [.list](index.js#L88)
### [.list](index.js#L84)

@@ -67,3 +67,3 @@ Create a new instance of `List` or get an existing instance to work with npm couchdb list.

### [.repo](index.js#L119)
### [.repo](index.js#L118)

@@ -100,3 +100,3 @@ Create an instance of a `repo` to work with.

### [BaseModel](lib/models/base.js#L24)
### [BaseModel](lib/models/base.js#L17)

@@ -109,3 +109,3 @@ Base model to include common plugins.

### [Maintainer](lib/models/maintainer.js#L25)
### [Maintainer](lib/models/maintainer.js#L19)

@@ -117,3 +117,2 @@ Maintainer constructor. Create an instance of an npm maintainer by maintainer name.

* `name` **{String}**: Name of the npm maintainer to get information about.
* `store` **{Object}**: Optional cache store instance for caching results. Defaults to a memory store.

@@ -123,6 +122,6 @@ **Example**

```js
var maintainer = new Maintainer('doowb');
const maintainer = new Maintainer('doowb');
```
### [.repos](lib/models/maintainer.js#L56)
### [.repos](lib/models/maintainer.js#L43)

@@ -144,3 +143,3 @@ Get the repositories owned by this maintainer.

### [Repo](lib/models/repo.js#L26)
### [Repo](lib/models/repo.js#L18)

@@ -152,3 +151,2 @@ Repo constructor. Create an instance of an npm repo by repo name.

* `name` **{String}**: Name of the npm repo to get information about.
* `store` **{Object}**: Optional cache store instance for caching results. Defaults to a memory store.

@@ -158,6 +156,6 @@ **Example**

```js
var repo = new Repo('micromatch');
const repo = new Repo('micromatch');
```
### [.package](lib/models/repo.js#L57)
### [.package](lib/models/repo.js#L41)

@@ -179,3 +177,3 @@ Get the repo's published package.json.

### [.version](lib/models/repo.js#L89)
### [.version](lib/models/repo.js#L73)

@@ -200,3 +198,3 @@ Get the repo's published package.json value for the specified version.

### [.dependencies](lib/models/repo.js#L118)
### [.dependencies](lib/models/repo.js#L101)

@@ -221,3 +219,3 @@ Get the repo's dependencies for the specified version.

### [.devDependencies](lib/models/repo.js#L138)
### [.devDependencies](lib/models/repo.js#L122)

@@ -242,3 +240,3 @@ Get the repo's devDependencies for the specified version.

### [.prop](lib/models/repo.js#L159)
### [.prop](lib/models/repo.js#L144)

@@ -266,3 +264,3 @@ Get the specified property from the repo's package.json for the specified version.

### [View](lib/view.js#L26)
### [View](lib/view.js#L21)

@@ -279,6 +277,6 @@ View constructor. Create an instance of a view associated with a couchdb view in the npm registry.

```js
var view = new View('dependedUpon');
const view = new View('dependedUpon');
```
### [.query](lib/view.js#L51)
### [.query](lib/view.js#L44)

@@ -295,11 +293,10 @@ Query the couchdb view with the provided parameters.

```js
view.query({ group_level: 2, startkey: JSON.stringify(['micromatch']), endkey: JSON.stringify(['micromatch', {}])})
.then(function(results) {
console.log(results);
}, function(err) {
console.log(err);
});
let results = await view.query({
group_level: 2,
startkey: JSON.stringify(['micromatch']),
endkey: JSON.stringify(['micromatch', {}])
});
```
### [.stream](lib/view.js#L91)
### [.stream](lib/view.js#L89)

@@ -316,9 +313,13 @@ Query the couchdb view with the provided parameters and return a stream of results.

```js
view.stream({ group_level: 2, startkey: JSON.stringify(['micromatch']), endkey: JSON.stringify(['micromatch', {}])})
.on('data', function(data) {
console.log(data);
});
view.stream({
group_level: 2,
startkey: JSON.stringify(['micromatch']),
endkey: JSON.stringify(['micromatch', {}])
})
.on('data', (data) => {
console.log(data);
});
```
### [.url](lib/view.js#L105)
### [.url](lib/view.js#L109)

@@ -329,6 +330,6 @@ Build a formatted url with the provided parameters.

* `params` **{Object}**: URL query parameters.
* `query` **{Object}**: URL query parameters.
* `returns` **{String}**: formatted url string
### [List](lib/list.js#L27)
### [List](lib/list.js#L22)

@@ -346,6 +347,6 @@ List constructor. Create an instance of a list associated with a couchdb list in the npm registry.

```js
var list = new List('dependedUpon', view);
let list = new List('dependedUpon', view);
```
### [.query](lib/list.js#L53)
### [.query](lib/list.js#L42)

@@ -362,11 +363,6 @@ Query the couchdb list with the provided parameters.

```js
list.query({ key: JSON.stringify(['micromatch']) })
.then(function(results) {
console.log(results);
}, function(err) {
console.log(err);
});
let results = await list.query({ key: JSON.stringify(['micromatch']) })
```
### [.url](lib/list.js#L80)
### [.url](lib/list.js#L59)

@@ -377,3 +373,3 @@ Build a formatted url with the provided parameters.

* `params` **{Object}**: URL query parameters.
* `query` **{Object}**: URL query parameters.
* `returns` **{String}**: formatted url string

@@ -388,2 +384,4 @@

Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
</details>

@@ -426,4 +424,5 @@

| --- | --- |
| 106 | [doowb](https://github.com/doowb) |
| 115 | [doowb](https://github.com/doowb) |
| 1 | [0xflotus](https://github.com/0xflotus) |
| 1 | [Hypnosphi](https://github.com/Hypnosphi) |
| 1 | [NachmanBerkowitz](https://github.com/NachmanBerkowitz) |

@@ -441,3 +440,3 @@

Copyright © 2019, [Brian Woodward](https://github.com/doowb).
Copyright © 2021, [Brian Woodward](https://github.com/doowb).
Released under the [MIT License](LICENSE).

@@ -447,2 +446,2 @@

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on June 17, 2019._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on January 20, 2021._
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc