Home Reference Source Repository
import EgoJS from 'egojs/src/egojs.js'
public class | source

EgoJS

The actual 'core' for EgoJS. This class saves the packages into the local db, manages the cache, makes the requests and returns the package stats.

Constructor Summary

Public Constructor
public

Class constructor

Member Summary

Public Members
public set

Set the module settings object.

public get

Get the module settings object.

Method Summary

Public Methods
public

addPackage(name: String, repository: String, npmPackage: String): Promise<Object, Error>

Add a new package to the database.

public

Delete all the cached requests for all the packages or for an specific one.

public

editPackage(id: Number, name: String, repository: String, npmPackage: String): Promise<Object, Error>

Edit the information of an existing package.

public

Get a package from the database.

public

Get the stats for all the packages saved on the database.

public

Remove a package from the database.

public

Shortcut method to set the GitHub token on the settings.

Public Constructors

public constructor source

Class constructor

Public Members

public set settings: Object source

Set the module settings object. It uses an special setter because it merges it with any existing settings and saves them on the database.

public get settings: Object source

Get the module settings object.

Public Methods

public addPackage(name: String, repository: String, npmPackage: String): Promise<Object, Error> source

Add a new package to the database.

Params:

NameTypeAttributeDescription
name String

The package name.

repository String

The package repository URL (username/repository).

npmPackage String

The NPM name for the package.

Return:

Promise<Object, Error>

If success, it will return the saved package.

public deleteCache(id: Number) source

Delete all the cached requests for all the packages or for an specific one.

Params:

NameTypeAttributeDescription
id Number
  • optional
  • default: null

If specified, the cache will be only removed for that package.

public editPackage(id: Number, name: String, repository: String, npmPackage: String): Promise<Object, Error> source

Edit the information of an existing package.

Params:

NameTypeAttributeDescription
id Number

The package unique ID.

name String

The package name.

repository String

The package repository URL (username/repository).

npmPackage String

The NPM name for the package.

Return:

Promise<Object, Error>

If success, it will return the saved package.

public getPackage(id: String | Number, property: String): Promise<Object, Error> source

Get a package from the database.

Params:

NameTypeAttributeDescription
id String | Number

By default, this is the package unique id, but if you change the value of the second argument, this can be the value you are looking for.

property String
  • optional
  • default: 'id'

The name of the filter property that will be used to make the search.

Return:

Promise<Object, Error>

Example:

instance.getPackage(12)
.then((pckg) => doSomethig(pckg))
.catch((err) => console.log(err));

// ...or...

instance.getPackage('The Pckg', 'name')
.then((pckg) => doSomethig(pckg))
.catch((err) => console.log(err));

public getStats(): Promise<Array, Error> source

Get the stats for all the packages saved on the database.

Return:

Promise<Array, Error>

A list of the packages stats.

Example:

instance.getStats()
.then((list) => {
    for (let i = 0; i < list.length; i++) {
        console.log('Package ', list[i].name);
    }
});

public removePackage(id: String | Number, property: String): Promise<Object, Error> source

Remove a package from the database.

Params:

NameTypeAttributeDescription
id String | Number

By default, this is the package unique id, but if you change the value of the second argument, this can be the value that the property has to have.

property String
  • optional
  • default: 'id'

The name of the filter property that will be used to make the search.

Return:

Promise<Object, Error>

Example:

instance.removePackage(12)
.then((pckg) => confirmRemove(pckg))
.catch((err) => console.log(err));

// ...or...

instance.removePackage('The Pckg', 'name')
.then((pckg) => confirmRemove(pckg))
.catch((err) => console.log(err));

public setGitHubToken(token: String) source

Shortcut method to set the GitHub token on the settings.

Params:

NameTypeAttributeDescription
token String

The GitHub access token required to access the API.