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-api-get

v0.4.4

Published

use github api

Downloads

25

Readme

github-api-get

  • use githubApiGetProject to get the github project info - reduce with pathExpression constants - only root GET request

  • i.e. its project topics

  • use githubApiGetLogin to get the github login info - reduce with pathExpression constants - only root GET request

  • i.e. its user avatar

  • use getGithubTopics to get the github project topics - deprecated - use githubApiGetProject with GITHUB_PROJECT_TOPICS

Install

npm install github-api-get

Usage

---
// in a module
export {};

// import the function from the library
import { getGithubTopics } from "github-api-get";
import { GITHUB_PROJECT_TOPICS } from './consts.js';

// define a example usage function
export async function realdataTopicsWithPathExpression() {
  const loginName = "roebi";
  const projectName = "01-01-vanilla-HTML5-starter-page";
  const infoLog = true;
  const isProd = true;

  const githubTopics = githubApiGetProject(loginName, projectName, GITHUB_PROJECT_TOPICS, infoLog, isProd); // as Promise<string[]>

  const realGithubTopics = await githubTopics;
  console.group("realGithubTopics, call of githubApiGetProject with constant GITHUB_PROJECT_TOPICS");
  console.info("realGithubTopics");
  console.info(realGithubTopics);
  console.groupEnd();
}

// run the example
await realdataTopicsWithPathExpression();

---

real demo see

https://github.com/roebi/github-api-get-nodejs-example

or direct on

https://stackblitz.com/edit/github-api-get-nodejs

Usage of other APIs

look in the tests: test.ts

github API has a hourly based rate limit

if this limit is reached in a hour, then

the response is in this case a 'Status is 403' Forbidden

and return this Message Object / Json:

{
  message: "API rate limit exceeded for nnn.nnn.nnn.nnn. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
  documentation_url: 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting'
}

see github - rest - resources-in-the-rest-api - rate-limiting

API - new implemented

githubApiGetProject(loginName, projectName, pathExpression, infoLog, isProd)

get github project info - reduce with pathExpression constants

Returns a Promise<any> with the project info

loginName

Type: String

The github login name

projectName

Type: String

The github project name of the project of a user login

pathExpression

Type: String

filter the project name of the project of a user login

infoLog

Type: boolean

true Logs group and info into the console

isProd

Type: boolean

true Calls fetch to github api, false returns mock data with same structure

return

Returns a Promise<any>

with a Json / Object of a project reduced with pathExpression

see Example answer Json / Object of a project

githubApiGetLogin(loginName, pathExpression, infoLog, isProd)

get github user info - reduce with pathExpression constants

Returns a Promise<any> with the project info or user info

loginName

Type: String

The github login name

pathExpression

Type: String

filter the project namen of the project of a user login

infoLog

Type: boolean

true Logs group and info into the console

isProd

Type: boolean

true Calls fetch to github api, false returns mock data with same structure

return

Returns a Promise<any>

with a Json / Object of a user login reduced with pathExpression

see Example answer Json / Object of a login of a user

Example answer Json / Object of a project

Github Meta Data of project 'roebi/01-01-vanilla-HTML5-starter-page'

{
  "name": "01-01-vanilla-HTML5-starter-page",
  ...
  "owner": {
     "login": "roebi",
     ...
  },
  "html_url": "https://github.com/roebi/01-01-vanilla-HTML5-starter-page",
  "description": "vanilla HTML 5 starter page - Have you ever heard of this HTML 5 tags ?",
  ...
  "url": "https://api.github.com/repos/roebi/01-01-vanilla-HTML5-starter-page",
  ...
  "homepage": "https://roebi.github.io/01-01-vanilla-HTML5-starter-page/",
  ...
  "license": {
    "key": "unlicense",
  },
  ...
  "topics": [
    "html5",
    "html5-template",
    "roebi",
    "starter"
  ],
  ...
}

Example answer Json / Object of a login of a user

Github Meta Data of user login 'roebi'

{
  "login": "roebi",
  ...
  "avatar_url": "...",
  ...
  "url": "https://api.github.com/users/roebi",
  "html_url": "https://github.com/roebi",
  ...
  "location": "Switzerland",
  ...
  "bio": "..."
}

tip on the behavior of the function

look in the tests: test.ts

API - implemented - deprecated

getGithubTopics(loginName, projectName, infoLog, isProd)

get github project topics as a Array

deprecated: use githubApiGetProject() with pathExpression constant GITHUB_PROJECT_TOPICS

loginName

Type: String

The github login name

projectName

Type: String

The github project name of the project of a user login

infoLog

Type: boolean

true Logs group and info into the console

isProd

Type: boolean

true Calls fetch to github api, false returns mock data with same structure

return

Returns a Promise<String[]> with the list of the project topics

i.e.

"topics": [
  "html5",
  "html5-template",
  "roebi",
  "starter"
]

tip on the behavior of the function

look in the tests: test.ts