npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-js-api

v0.3.1

Published

A simple JavaScript GitHub API wrapper.

Downloads

7

Readme

GitHub.JS-API

NPM

Overview

Github.JS-API is a simple JavaScript GitHub API wrapper.

Getting Started

Prerequisites

  • Node

Installation

To install Github.JS-API simply run:

npm install github-js-api

in your project folder.

Running the Tests

To run the test a few changes need to be done.

  1. Open the config.json in the tests folder
  2. Set the owner name and the repo name of one of your private repositories
  3. The GitHub AuthToken can also be set in config.json or later as a parameter in the test command.

The tests can then be run via:

  npm test

or

  npm test -- --authToken=<Your GitHub Auth Token>

in case the auth token was not already set in the config.json;

Usage

JavaScript

const GitHubApi = require('github-js-api').GitHubApi;

const gitHub = new GitHubApi();

async function printPullRequestData() {
  const pullRequestData = await gitHub
                                  .getUser('octocat')
                                  .getRepo('Hello-World')
                                  .getPullRequest(493)
                                  .asJson();

  console.log(pullRequestData);
}

printPullRequestData();

TypeScript

import {GitHubApi} from 'github-js-api';

class GitHubApiSample {
  public gitHub: GitHubApi = new GitHubApi();

  public async printPullRequestData() {
    const pullRequestData: JSON = await this.gitHub
                                              .getUser('octocat')
                                              .getRepo('Hello-World')
                                              .getPullRequest(493)
                                              .asJson();

   console.log(pullRequestData);
  }
}

const gitHubApi: GitHubApi = new GitHubApiSample();

gitHubApi.printPullRequestData();

Documentation

GitHub

Variables

  • endpoint

    • The GitHub api endpoint
    • Type: string
    • Get & Set
    • Default: https://api.github.com/
  • authToken

  • configService

    • The service where all configs are stored
    • Type: ConfigService
    • Get & Set

Constructor

  • GitHubApi(authToken?: string)

Functions

  • getOrga(orgaName: string, configService?: ConfigService): IOrga

    • Parameters

      • orgaName
        • The name of the organization
        • Type: string
      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • The created organization
        • Type: IOrga
  • getUser(userName: string, configService?: ConfigService): IUser

    • Parameters

      • userName
        • The name of the user
        • Type: string
      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • The created user
        • Type: IUser
  • getLoggedInUser(): Promise

    • Parameters

    • Returns

      • A Promise containing logged in user
        • Type: IUser

Owner [abstract]

Constructor

  • Owner(name: string, configService?: ConfigService)
    • Parameters
      • name
        • The name of the owner
        • Type: string
      • configService [optional]
        • A custom configService
        • Type: ConfigService

Variables

  • name
    • The name of the owner
    • Type: string
    • Get

Functions

  • asJson(): Promise

    • Parameters

      • None
    • Returns

      • A promise containing the data of the owner
        • Type: JSON
  • getRepo(repoName: string, configService?: ConfigService): IRepo

    • Parameters

      • repoName
        • The name of the repository
        • Type: string
      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • The created repository
        • Type: IRepo
  • getAllPublicRepos(configService?: configService): Promise<Array>

    • Parameters

      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • A promise containing all created public repositories
        • Type: Promise<Array>

Orga [extends Owner]

A GitHub Organization.

Constructor

  • Orga(name: string, configService?: ConfigService)
    • Parameters
      • name
        • The name of the orga
        • Type: string
      • configService [optional]
        • A custom configService
        • Type: ConfigService

Functions

  • asOrgaData(): Promise
    • Parameters

      • None
    • Returns

      • A promise containing the data of the organization
        • Type: IOrganizationData

User [extends Owner]

A GitHub User.

Constructor

  • User(name: string, configService?: ConfigService)
    • Parameters
      • name
        • The name of the user
        • Type: string
      • configService [optional]
        • A custom configService
        • Type: ConfigService

Functions

  • asUserData(): Promise
    • Parameters

      • None
    • Returns

      • A promise containing the data of the user
        • Type: IUserData

Repo

A GitHub Repository.

Constructor

  • Repo(owner: IOwner, name: string, configService?: ConfigService)
    • Parameters
      • owner
        • The owner of the repository
        • Type: IOwner
      • name
        • The name of the repository
        • Type: string
      • configService [optional]
        • A custom configService
        • Type: ConfigService

Variables

  • name

    • The name of the repository
    • Type: string
    • Get
  • owner

    • The owner of the repository
    • Type: IOwner
    • Get

Functions

  • asJson(): Promise

    • Parameters

      • None
    • Returns

      • A promise containing the data of the repository
        • Type: JSON
  • asRepositoryData(): Promise

    • Parameters

      • None
    • Returns

      • A promise containing the data of the repository
        • Type: IRepositoryData
  • [static] fromData(owner: IOwner, data: JSON, configService?: ConfigService): IRepo

    • Parameters

      • owner
        • The owner of the repository
          • Type: IOwner
      • data
        • The data of the repository
          • Type: JSON
      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • The created repository
        • Type: IRepo
  • getPullRequest(pullRequestNumber: number, configService?: ConfigService): IPullRequest

    • Parameters

      • pullRequestNumber: The number of the pull request
        • Type: number
      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • The created pull request
        • Type: IPullRequest
  • getOpenPullRequests(configService?: ConfigService): Promise<Array>

    • Parameters

      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • A promise containing all created public repositories
        • Type: Promise<Array>

Pull Request

A GitHub Pull Request.

Constructor

  • PullRequest(owner: IOwner, repo: IRepo, pullRequestNumber: number, configService?: ConfigService)
    • Parameters
      • owner
        • The owner of the repository that contains the pull request
        • Type: IOwner
      • repo
        • The repository that contains the pull request
        • Type: IRepo
      • pullRequestNumber
        • The number of the pull request
        • Type: number
      • configService [optional]
        • A custom configService
        • Type: ConfigService

Variables

  • number

    • The number of the pull request
    • Type: number
    • Get
  • repo

    • The repository containing the pull request
    • Type: IRepo
    • Get
  • owner

    • The owner of the repository containing the pull request
    • Type: IOwner
    • Get

Functions

  • asJson(): Promise

    • Parameters

      • None
    • Returns

      • A promise containing the data of the pull request
        • Type: JSON
  • asPullRequestData(): Promise

    • Parameters

      • None
    • Returns

      • A promise containing the data of the pull request
        • Type: IPullRequestData
  • [static] fromData(owner: IOwner, repo: IRepo, data: JSON, configService?: ConfigService): Pull Request

    • Parameters

      • owner
        • The owner of the repository containing the pull request
        • Type: IOwner
      • repo
        • The repository containing the pull request
        • Type: IRepo
      • data
        • The data of the pull request
        • Type: JSON
      • configService [optional]
        • A custom configService
        • Type: ConfigService
    • Returns

      • The created pull request
        • Type: IPullRequest

Changelog

v0.3.1

  • 🐛 Add Missing Functions to Interfaces

v0.3.0

  • Add getLoggedInUser
  • 🐛 Fix Bug That Changed The Authtoken When Using withAuthtoken
  • Add Interfaces
  • Add Tests for getLoggedInUser
  • ✅ ♻️ Use Interfaces in Tests

v0.2.1

  • 🐛 Fix Using ConfigService for User
  • 🐛 Fix Using ConfigService for Orga

v0.2.0

  • Add Declarations
  • Add Registry
  • ♻️ Refactor ConfigService & HttpClient

v0.1.0

  • Add Basic Support for Users
  • Add Basic Support for Orgas
  • Add Basic Support for Repos
  • Add Basic Support for Pull Requests
  • Add ConfigService
  • Add HttpClient
  • Add Tests
  • 🏷 Add Types