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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhengke0110/github

v3.1.3

Published

GitHub 集成包,提供 GitHub API 客户端、模板搜索和模板下载功能。

Readme

@zhengke0110/github

GitHub 集成包,提供 GitHub API 客户端、模板搜索和模板下载功能。

核心功能

| 功能 | 描述 | | ----------------- | ------------------------------- | | GitHub 客户端 | 基于 Octokit 的 GitHub API 封装 | | 模板搜索 | 智能搜索 GitHub 模板仓库 | | 模板下载 | 快速下载 GitHub 仓库模板 | | Token 验证 | GitHub Token 有效性验证 |

主要类

GitHubClient

GitHub API 客户端,基于 Octokit 封装。

import { GitHubClient } from '@zhengke0110/github';

const client = new GitHubClient('your-github-token');

// 获取当前用户
const username = await client.getAuthenticatedUser();

// 验证 Token
const isValid = await client.validateToken();

// 获取原生 Octokit 实例
const octokit = client.getOctokit();

TemplateSearcher

GitHub 模板仓库搜索器。

import { GitHubClient, TemplateSearcher } from '@zhengke0110/github';

const client = new GitHubClient('your-token');
const searcher = new TemplateSearcher(client);

// 搜索模板
const templates = await searcher.searchTemplates({
  keyword: 'react',
  language: 'typescript',
  userOnly: true, // 只搜索当前用户的仓库
  templateOnly: true, // 只搜索模板仓库
  maxResults: 10,
});

// 获取用户所有仓库
const userRepos = await searcher.getUserRepositories();

搜索选项:

interface SearchOptions {
  keyword?: string; // 搜索关键字
  language?: string; // 编程语言过滤
  userOnly?: boolean; // 只搜索当前用户
  templateOnly?: boolean; // 只搜索模板仓库
  maxResults?: number; // 最大结果数量
}

TemplateDownloader

GitHub 模板下载器,支持多种仓库标识符格式。

import { TemplateDownloader } from '@zhengke0110/github';

const downloader = new TemplateDownloader();

// 下载仓库模板
await downloader.download('owner/repo', {
  targetDir: './my-project',
  force: true, // 强制覆盖
  verbose: true, // 显示详细信息
});

// 从 GitHubTemplate 对象下载
await downloader.downloadFromTemplate(template, {
  targetDir: './my-project',
});

支持的仓库格式:

类型定义

GitHubTemplate

interface GitHubTemplate {
  fullName: string; // 仓库全名 (owner/repo)
  name: string; // 仓库名称
  owner: string; // 所有者
  description: string | null; // 描述
  language: string | null; // 主要语言
  stars: number; // Star 数量
  isTemplate: boolean; // 是否是模板仓库
  updatedAt: string; // 更新时间
  url: string; // 仓库 URL
}

DownloadOptions

interface DownloadOptions {
  targetDir: string; // 目标目录
  force?: boolean; // 强制覆盖
  cache?: boolean; // 是否缓存
  verbose?: boolean; // 详细模式
}

使用示例

完整的模板搜索和下载流程

import {
  GitHubClient,
  TemplateSearcher,
  TemplateDownloader,
} from '@zhengke0110/github';

// 1. 创建客户端
const client = new GitHubClient('your-token');

// 2. 验证 Token
if (!(await client.validateToken())) {
  throw new Error('Invalid GitHub token');
}

// 3. 搜索模板
const searcher = new TemplateSearcher(client);
const templates = await searcher.searchTemplates({
  keyword: 'vue',
  language: 'typescript',
  templateOnly: true,
});

// 4. 选择模板并下载
const template = templates[0];
const downloader = new TemplateDownloader();
await downloader.downloadFromTemplate(template, {
  targetDir: './my-vue-app',
  force: true,
  verbose: true,
});

系统要求

  • Node.js: >= 16.0.0
  • Git: >= 2.0.0(下载功能需要)

开发

# 构建
nx build github

# 测试
nx test github