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

@yankeeinlondon/repo-info

v0.3.2

Published

Provides an API surface for querying repos across Github and other Git hosts

Downloads

4

Readme

Repo Info

Installation

From the shell:

# choose your favorite package manager
pnpm install @yankeeinlondon/repo-info

Usage

Get The API surface

First you want to get a repo based API:

import RepoInfo from "repo-info";

// defaults to assuming a github repo
const repo = await RepoInfo("org/repo");
// you can use the full URL if you prefer
const alt = await RepoInfo("https://github.com/org/repo");

Note: currently we only support Github but the intent is to be appropriately abstracted to support other providers like Gitlab and Bitbucket

Partial Application

A lot of time, it's useful to lazy load what you want to do but not start the doing until later. This is in fact the default behavior of this library:

//  RepoConfig<"org/repo", "default-branch", "github", "none">
const repo = RepoApi("org/repo");

This synchronous operation simply configures what you'll want to do later with returned configuration object's load() method:

// RepoApi<"org/repo", "default-branch", "github", "none">
const info = await repo.load();

Now the info hash provides a combination of useful information about the repo and it's branches but also an API surface which let's you explore further. It's all strongly typed with comments for the types in most cases so just use the surface as your documentation.

Note: if you thing lazy-loading is just lazy then you can skip it by setting the option { loadNow: true }.

Preloading More Meta

When a RepoInfo type is created it pre-loads some information about the repo. By default this is just the following:

  • Repo Meta
  • Branch Info

Beyond that it provides an API surface for things like:

  • getReposInOrg()
  • getReadme()
  • getContentInRepo()
  • getCommits()
  • buildSitemap()

While that let's you extend beyond the base information you'll always get, you may know that you always want certain information loaded along with the repo meta and branch info. This is possible via the initial options hash provided:

// RepoInfo<"org/repo", "default-branch", "github", "readme">
const api = await RepoInfo("org/repo", { withReadme: true, loadNow: true })

In this case, stating that you know you'll want info on the repo's README.md file changes the surface of the API. You'll no longer have a getReadme() method but instead a readme property which is populated with the ReadmeMarkdown type.

Not all endpoints are yet supported in this manner but you'll see in your editor which ones are just by exploring the options hash of RepoInfo.

Branches

Up to now all examples have shown us not expressing an explicit branch we want to default to but by doing so we've ended seeing that our "type" includes reference to default-branch. Since we always get the repo's meta data and it knows which branch is the the "default branch" we can automatically set this for you but you can set it explicitly too if you prefer:

// RepoConfig<"org/repo", "develop", "github", "none">
const api = await RepoInfo("org/repo", { branch: "develop" });

It will trust your knowledge of the actual branches when lazy loading the config but if when you load to an active API surface if we find that the branch doesn't exist then an error will be thrown.

Contributing

Happy for people to contribute with PRs. This repo's API approach should be maintained but there is definitely plans to to additively add other endpoints to the API surface when time permits and most self-evidently this library is intended to abstract the git vendor but currently is only implemented for github though it is structured for this abstraction I am VERY happy if someone takes on Bitbucket and/or Gitlab which I am not currently working that much.

One thing to bear in mind if you're considering contributing, I expect the following things:

  • unit tests in a similar level of granularity as what are already here to show your feature's contribution working along with any edge cases you're aware of
  • strong typing which preserves type literals where possible