Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 0.4.1 to 0.4.2

26

index.js

@@ -19,6 +19,6 @@ /*!

/**
* NpmInfo constructor. Create an instance to work with maintainer and repository information.
* NpmApi constructor. Create an instance to work with maintainer and repository information.
*
* ```js
* var npm = new NpmInfo();
* var npm = new NpmApi();
* ```

@@ -28,8 +28,8 @@ * @api public

function NpmInfo(options) {
if (!(this instanceof NpmInfo)) {
return new NpmInfo(options);
function NpmApi(options) {
if (!(this instanceof NpmApi)) {
return new NpmApi(options);
}
Base.call(this, null, options);
this.is('npminfo');
this.is('npmapi');

@@ -52,3 +52,3 @@ this.use(utils.plugin());

Base.extend(NpmInfo);
Base.extend(NpmApi);

@@ -68,3 +68,3 @@ /**

NpmInfo.prototype.view = function(name) {
NpmApi.prototype.view = function(name) {
if (this.has(['views', name])) {

@@ -92,3 +92,3 @@ return this.get(['views', name]);

NpmInfo.prototype.list = function(name, view) {
NpmApi.prototype.list = function(name, view) {
var viewName = view;

@@ -124,3 +124,3 @@ if (typeof view === 'object') {

NpmInfo.prototype.repo = function(name) {
NpmApi.prototype.repo = function(name) {
if (this.has(['repos', name])) {

@@ -147,3 +147,3 @@ return this.get(['repos', name]);

NpmInfo.prototype.maintainer = function(name) {
NpmApi.prototype.maintainer = function(name) {
if (this.has(['maintainers', name])) {

@@ -159,5 +159,5 @@ return this.get(['maintainers', name]);

/**
* Exposes `NpmInfo`
* Exposes `NpmApi`
*/
module.exports = NpmInfo;
module.exports = NpmApi;

@@ -14,2 +14,15 @@ /*!

/**
* List constructor. Create an instance of a list associated with a couchdb list in the npm registry.
*
* ```js
* var list = new List('dependedUpon', view);
* ```
*
* @param {String} `name` Name of couchdb list to use.
* @param {Object} `view` Instance of a View to use with the list.
* @returns {Object} instance of `List`
* @api public
*/
function List (name, view) {

@@ -25,2 +38,18 @@ if (!(this instanceof List)) {

/**
* 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);
* });
* ```
* @param {Object} `params` URL query parameters to pass along to the couchdb list.
* @return {Promise} Results of the query when promise is resolved.
* @api public
*/
List.prototype.query = function(params) {

@@ -45,2 +74,10 @@ params = params || {};

/**
* Build a formatted url with the provided parameters.
*
* @param {Object} `params` URL query parameters.
* @return {String} formatted url string
* @api public
*/
List.prototype.url = function(params) {

@@ -50,2 +87,6 @@ return url.format(utils.merge({}, this.config, {query: params || {}}));

/**
* Exposes `List`
*/
module.exports = List;

@@ -14,3 +14,11 @@ /*!

var View = require('../view');
var Memory = require('../stores/memory');
/**
* Base model to include common plugins.
*
* @param {Object} `store` Cache store intance to use.
* @api public
*/
function BaseModel(store) {

@@ -28,7 +36,15 @@ if (!(this instanceof BaseModel)) {

this.define('View', View);
this.define('store', store);
this.define('store', store || new Memory());
}
/**
* Extend `Base`
*/
Base.extend(BaseModel);
/**
* Exposes `BaseModel`
*/
module.exports = BaseModel;

@@ -13,2 +13,14 @@ /*!

/**
* Maintainer constructor. Create an instance of an npm maintainer by maintainer name.
*
* ```js
* var maintainer = new Maintainer('doowb');
* ```
*
* @param {String} `name` Name of the npm maintainer to get information about.
* @param {Object} `store` Optional cache store instance for caching results. Defaults to a memory store.
* @api public
*/
function Maintainer (name, store) {

@@ -23,4 +35,24 @@ if (!(this instanceof Maintainer)) {

/**
* Extend `Base`
*/
Base.extend(Maintainer);
/**
* Get the repositories owned by this maintainer.
*
* ```js
* maintainer.repos()
* .then(function(repos) {
* console.log(repos);
* }, function(err) {
* console.error(err);
* });
* ```
*
* @return {Promise} Returns array of repository names when promise resolves.
* @api public
*/
Maintainer.prototype.repos = function() {

@@ -39,2 +71,6 @@ return utils.co(function* (self) {

/**
* Exposes `Maintainer`
*/
module.exports = Maintainer;

@@ -14,2 +14,14 @@ /*!

/**
* Repo constructor. Create an instance of an npm repo by repo name.
*
* ```js
* var repo = new Repo('micromatch');
* ```
*
* @param {String} `name` Name of the npm repo to get information about.
* @param {Object} `store` Optional cache store instance for caching results. Defaults to a memory store.
* @api public
*/
function Repo (name, store) {

@@ -25,4 +37,23 @@ if (!(this instanceof Repo)) {

/**
* Extend `Base`
*/
Base.extend(Repo);
/**
* Get the repo's published package.json.
*
* ```js
* repo.package()
* .then(function(pkg) {
* console.log(pkg);
* }, function(err) {
* console.error(err);
* });
* ```
* @return {Promise} Returns the package.json object when promise resolves.
* @api public
*/
Repo.prototype.package = function() {

@@ -42,2 +73,18 @@ return utils.co(function* (self) {

/**
* Get the repo's published package.json value for the specified version.
*
* ```js
* repo.version('0.2.0')
* .then(function(pkg) {
* console.log(pkg);
* }, function(err) {
* console.error(err);
* });
* ```
* @param {String} `version` Specific version to retrieve.
* @return {Promise} Returns the package.json object for the specified version when promise resolves.
* @api public
*/
Repo.prototype.version = function(version) {

@@ -56,2 +103,18 @@ return utils.co(function* (self) {

/**
* Get the repo's dependencies for the specified version.
*
* ```js
* repo.dependencies()
* .then(function(dependencies) {
* console.log(dependencies);
* }, function(err) {
* console.error(err);
* });
* ```
* @param {String} `version` Specific version to retrieve. Defaults to `latest`.
* @return {Promise} Returns the dependencies object for the specified version when promise resolves.
* @api public
*/
Repo.prototype.dependencies = function(version) {

@@ -61,2 +124,18 @@ return this.prop('dependencies', version);

/**
* Get the repo's devDependencies for the specified version.
*
* ```js
* repo.devDependencies()
* .then(function(devDependencies) {
* console.log(devDependencies);
* }, function(err) {
* console.error(err);
* });
* ```
* @param {String} `version` Specific version to retrieve. Defaults to `latest`.
* @return {Promise} Returns the devDependencies object for the specified version when promise resolves.
* @api public
*/
Repo.prototype.devDependencies = function(version) {

@@ -66,2 +145,19 @@ return this.prop('devDependencies', version);

/**
* Get the specified property from the repo's package.json for the specified version.
*
* ```js
* repo.prop('author')
* .then(function(author) {
* console.log(author);
* }, function(err) {
* console.error(err);
* });
* ```
* @param {String} `prop` Name of the property to get.
* @param {String} `version` Specific version to retrieve. Defaults to `latest`.
* @return {Promise} Returns the property for the specified version when promise resolves.
* @api public
*/
Repo.prototype.prop = function(prop, version) {

@@ -75,2 +171,6 @@ version = version || 'latest';

/**
* Exposes `Repo`
*/
module.exports = Repo;

@@ -14,2 +14,14 @@ /*!

/**
* View constructor. Create an instance of a view associated with a couchdb view in the npm registry.
*
* ```js
* var view = new View('dependedUpon');
* ```
*
* @param {String} `name` Name of couchdb view to use.
* @returns {Object} instance of `View`
* @api public
*/
function View (name) {

@@ -24,2 +36,18 @@ if (!(this instanceof View)) {

/**
* 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);
* });
* ```
* @param {Object} `params` URL query parameters to pass along to the couchdb view.
* @return {Promise} Results of the query when promise is resolved.
* @api public
*/
View.prototype.query = function(params) {

@@ -43,2 +71,10 @@ return utils.co(function* (self) {

/**
* Build a formatted url with the provided parameters.
*
* @param {Object} `params` URL query parameters.
* @return {String} formatted url string
* @api public
*/
View.prototype.url = function(params) {

@@ -48,2 +84,6 @@ return url.format(utils.merge({}, this.config, {query: params || {}}));

/**
* Exposes `View`
*/
module.exports = View;
{
"name": "npm-api",
"description": "Base class for retrieving data from the npm registry.",
"version": "0.4.1",
"version": "0.4.2",
"homepage": "https://github.com/doowb/npm-api",

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

@@ -16,3 +16,3 @@ # npm-api [![NPM version](https://img.shields.io/npm/v/npm-api.svg)](https://www.npmjs.com/package/npm-api) [![Build Status](https://img.shields.io/travis/doowb/npm-api.svg)](https://travis-ci.org/doowb/npm-api)

```js
var NpmInfo = require('npm-api');
var NpmApi = require('npm-api');
```

@@ -22,5 +22,5 @@

### [NpmInfo](index.js#L27)
### [NpmApi](index.js#L27)
NpmInfo constructor. Create an instance to work with maintainer and repository information.
NpmApi constructor. Create an instance to work with maintainer and repository information.

@@ -30,3 +30,3 @@ **Example**

```js
var npm = new NpmInfo();
var npm = new NpmApi();
```

@@ -95,2 +95,248 @@

## Models
### [BaseModel](lib/models/base.js#L22)
Base model to include common plugins.
**Params**
* `store` **{Object}**: Cache store intance to use.
### [Maintainer](lib/models/maintainer.js#L25)
Maintainer constructor. Create an instance of an npm maintainer by maintainer name.
**Params**
* `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.
**Example**
```js
var maintainer = new Maintainer('doowb');
```
### [.repos](lib/models/maintainer.js#L56)
Get the repositories owned by this maintainer.
* `returns` **{Promise}**: Returns array of repository names when promise resolves.
**Example**
```js
maintainer.repos()
.then(function(repos) {
console.log(repos);
}, function(err) {
console.error(err);
});
```
### [Repo](lib/models/repo.js#L26)
Repo constructor. Create an instance of an npm repo by repo name.
**Params**
* `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.
**Example**
```js
var repo = new Repo('micromatch');
```
### [.package](lib/models/repo.js#L57)
Get the repo's published package.json.
* `returns` **{Promise}**: Returns the package.json object when promise resolves.
**Example**
```js
repo.package()
.then(function(pkg) {
console.log(pkg);
}, function(err) {
console.error(err);
});
```
### [.version](lib/models/repo.js#L87)
Get the repo's published package.json value for the specified version.
**Params**
* `version` **{String}**: Specific version to retrieve.
* `returns` **{Promise}**: Returns the package.json object for the specified version when promise resolves.
**Example**
```js
repo.version('0.2.0')
.then(function(pkg) {
console.log(pkg);
}, function(err) {
console.error(err);
});
```
### [.dependencies](lib/models/repo.js#L116)
Get the repo's dependencies for the specified version.
**Params**
* `version` **{String}**: Specific version to retrieve. Defaults to `latest`.
* `returns` **{Promise}**: Returns the dependencies object for the specified version when promise resolves.
**Example**
```js
repo.dependencies()
.then(function(dependencies) {
console.log(dependencies);
}, function(err) {
console.error(err);
});
```
### [.devDependencies](lib/models/repo.js#L136)
Get the repo's devDependencies for the specified version.
**Params**
* `version` **{String}**: Specific version to retrieve. Defaults to `latest`.
* `returns` **{Promise}**: Returns the devDependencies object for the specified version when promise resolves.
**Example**
```js
repo.devDependencies()
.then(function(devDependencies) {
console.log(devDependencies);
}, function(err) {
console.error(err);
});
```
### [.prop](lib/models/repo.js#L157)
Get the specified property from the repo's package.json for the specified version.
**Params**
* `prop` **{String}**: Name of the property to get.
* `version` **{String}**: Specific version to retrieve. Defaults to `latest`.
* `returns` **{Promise}**: Returns the property for the specified version when promise resolves.
**Example**
```js
repo.prop('author')
.then(function(author) {
console.log(author);
}, function(err) {
console.error(err);
});
```
## Registry queries
### [View](lib/view.js#L26)
View constructor. Create an instance of a view associated with a couchdb view in the npm registry.
**Params**
* `name` **{String}**: Name of couchdb view to use.
* `returns` **{Object}**: instance of `View`
**Example**
```js
var view = new View('dependedUpon');
```
### [.query](lib/view.js#L51)
Query the couchdb view with the provided parameters.
**Params**
* `params` **{Object}**: URL query parameters to pass along to the couchdb view.
* `returns` **{Promise}**: Results of the query when promise is resolved.
**Example**
```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);
});
```
### [.url](lib/view.js#L77)
Build a formatted url with the provided parameters.
**Params**
* `params` **{Object}**: URL query parameters.
* `returns` **{String}**: formatted url string
### [List](lib/list.js#L27)
List constructor. Create an instance of a list associated with a couchdb list in the npm registry.
**Params**
* `name` **{String}**: Name of couchdb list to use.
* `view` **{Object}**: Instance of a View to use with the list.
* `returns` **{Object}**: instance of `List`
**Example**
```js
var list = new List('dependedUpon', view);
```
### [.query](lib/list.js#L53)
Query the couchdb list with the provided parameters.
**Params**
* `params` **{Object}**: URL query parameters to pass along to the couchdb list.
* `returns` **{Promise}**: Results of the query when promise is resolved.
**Example**
```js
list.query({ key: JSON.stringify(['micromatch']) })
.then(function(results) {
console.log(results);
}, function(err) {
console.log(err);
});
```
### [.url](lib/list.js#L80)
Build a formatted url with the provided parameters.
**Params**
* `params` **{Object}**: URL query parameters.
* `returns` **{String}**: formatted url string
## Related projects

@@ -97,0 +343,0 @@

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